/
run.sh
executable file
·219 lines (188 loc) · 5.31 KB
/
run.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#!/bin/bash
# OSC-Midi-Live
# Copyright (C) 2015 Michele Laurenti
# email: asmeikal [at] me [dot] com
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You can find a copy of the GNU General Public License at
# http://www.gnu.org/licenses/gpl.html
# ./run.sh starts the main binary.
# It can be easily configured running ./run.sh configure
# and then, to start the main binary, just run ./run.sh.
./copyright_notice.sh "OSC-Midi-Live" "2015" "Michele Laurenti"
if (( $? != 0 ))
then
exit 1
fi
YLW='\033[0;33m'
NC='\033[0m'
IP_MATCH="(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[0-9]{1,2})"
quit()
{
echo; echo; exit $1
}
yellow_print()
{
printf "${YLW}$@${NC}\n"
}
run_cmd()
{
yellow_print "${1}"
eval $1
}
# Here we go...
echo; echo
if [[ $1 =~ "configure" ]]
then
# Configure
cat <<END
Please provide the IP address of the computer currently
running OSCulator, the Arduino's serial Baud Rate, and
the Arduinos' device names, in the form [path]:[n_vars],
where [path] is the full path to the Arduino serial device
(e.g. '/dev/cu.usbmodem1411', '/dev/ttyACM0'), and [n_vars]
is the number of variables each one of them is sending
(e.g., 4, 6, 12).
END
echo
if [[ -f .config ]]
then
echo "Loading previous configuration."
read -d '\n' <.config old_param_ip old_param_baud old_param_devices
echo "Previous configuration was:"
echo " [ip address]: ${old_param_ip}"
echo " [baud rate]: ${old_param_baud}"
echo " [dev names]: ${old_param_devices}"
echo "Press enter to skip input and keep a previous value."
echo
fi
echo -n "[ip address]: "; read param_ip
if [[ -z $param_ip ]]
then
if [[ -z $old_param_ip ]]
then
echo "Please provide an input."
quit 1
fi
param_ip=$old_param_ip
elif [[ ! $param_ip =~ ^(${IP_MATCH}\.){3}(${IP_MATCH})$ ]]
then
echo "Illegal ip address."
quit 1
fi
echo -n "[baud rate]: "; read param_baud
if [[ -z $param_baud ]]
then
if [[ -z $old_param_baud ]]
then
echo "Please provide an input."
quit 1
fi
param_baud=$old_param_baud
elif [[ ! $param_baud =~ ^[0-9]{1,}$ ]]
then
echo "Illegal baud rate."
quit 1
fi
echo -n "[dev names]: "; read param_devices
if [[ -z $param_devices ]]
then
if [[ -z $old_param_devices ]]
then
echo "Please provide an input."
quit 1
fi
param_devices=$old_param_devices
elif [[ ! $param_devices =~ ^(/dev/[^:]+:[0-9]{1,2} ?){1,}$ ]]
then
echo "Illegal device(s) name(s)."
quit 1
fi
echo $param_ip > .config
echo $param_baud >> .config
echo $param_devices >> .config
echo
echo "Configuration file created."
elif [[ $1 =~ "build" ]]
then
# Build executables
if [[ $2 =~ "tests" ]]
then
echo "Compiling test executables."
cmd="make clean tests"
run_cmd "${cmd}"
else
echo "Compiling executable for live concert."
cmd="make clean prod"
run_cmd "${cmd}"
fi
elif (( $# == 0 ))
then
# Run main app
if [[ ! -f .config ]]
then
echo "Configuration file not found."
./run.sh configure
fi
echo "Reading configuration file."
read -d '\n' <.config param_ip param_baud param_devices
cmd="bin/oscLiveMain $param_ip $param_baud $param_devices"
echo
for l in $param_devices
do
devname=`echo $l | cut -f1 -d':'`
echo "Checking device '$devname' availability."
if [[ ! -c $devname ]]
then
echo "Device '$devname' not connected."
quit 1
fi
inputs=`echo $l | cut -f2 -d':'`
cmd_nest="python3 check_device.py $devname $param_baud $inputs"
trials=0
yellow_print $cmd_nest
while (( $trials < 10 ))
do
eval "$cmd_nest"
retval=$?
if (( $retval == 0 ))
then
echo "Device '${devname}' ready."
break
else
trials=$(( $trials + 1 ))
yellow_print "Attempt ${trials} failed."
if (( $trials >= 10 ))
then
echo "Device '${devname}' not available."
echo "Maybe baud rate is not ${param_baud}?"
echo "Maybe '${devname}' is not sending ${inputs} variables?"
quit 1
fi
fi
done
done
echo
echo "All devices ready."
if [[ ! -f bin/oscLiveMain ]]
then
echo
echo "No executable found. Building."
./run.sh build
fi
echo "Starting Arduino-osculator bridge..."
run_cmd "$cmd"
else
echo "usage: ./run.sh [configure|build tests]"
quit 1
fi
echo; echo