-
Notifications
You must be signed in to change notification settings - Fork 8
/
mmbtools-get
381 lines (324 loc) · 8.68 KB
/
mmbtools-get
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
#!/bin/bash
# mmbtools-get - Build, install, uninstall, remove the software stack
# Copyright (C) 20222 Robin ALEXANDER
#
# 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 should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
print_usage () {
cat <<- EOF
Usage:
$(basename ${0}) [option] action
Option:
-h, --help Print this help
-b, --branch <name> Specify the odr-mmbTools branch to use
--odr-user Opendigitalradio user
Action:
install Install the programs and the configuration sample
remove Remove the programs and the configuration sample
EOF
}
install_base () {
# Create odr-user if necessary
if ! test $(id --user "${odr_user}"); then
useradd --create-home "${odr_user}"
fi
## Add the current user to the dialout and audio groups
usermod --append --groups audio,dialout "${odr_user}"
# Install the essential tools and create the tools root directory
apt-get update
apt-get install --yes \
automake \
build-essential \
libtool \
pkg-config \
supervisor
if [ ! -d "${DIR_MMB}" ]; then
mkdir "${DIR_MMB}"
fi
if [ ! $(grep inet_http_server /etc/supervisor/supervisord.conf) ]; then
cat << EOF | tee -a /etc/supervisor/supervisord.conf > /dev/null
[inet_http_server]
port = 8001
username = odr ; Auth username
password = odr ; Auth password
EOF
fi
}
install_audioenc () {
# Install mmb-tools: audio encoder
apt-get install --yes \
libasound2-dev \
libcurl4-openssl-dev \
libjack-jackd2-dev \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libvlc-dev \
libzmq3-dev
if [ ! -d "${DIR_AUDIO}" ]; then
pushd "${DIR_MMB}" || return
git clone https://github.com/Opendigitalradio/ODR-AudioEnc.git --branch "${1}"
popd || return
fi
pushd "${DIR_AUDIO}" || return
./bootstrap
./configure --enable-alsa --enable-jack --enable-vlc --enable-gst
make
make install
make clean
popd || return
apt-get purge --yes \
libasound2-dev \
libcurl4-openssl-dev \
libjack-jackd2-dev \
libgstreamer1.0-dev \
libgstreamer-plugins-base1.0-dev \
libvlc-dev \
libzmq3-dev
apt-get install --yes \
gstreamer1.0-plugins-good \
libasound2 \
libcurl4 \
libgstreamer1.0 \
libgstreamer-plugins-base1.0 \
libjack0 \
libvlc5 \
libzmq5 \
vlc-plugin-base
}
install_padenc () {
# Install mmb-tools: PAD encoder
apt-get install --yes libmagickwand-dev
if [ ! -d "${DIR_PAD}" ]; then
pushd "${DIR_MMB}" || return
git clone https://github.com/Opendigitalradio/ODR-PadEnc.git --branch "${1}"
popd || return
fi
pushd "${DIR_PAD}" || return
./bootstrap
./configure
make
make install
make clean
popd || return
}
install_dabmux () {
# Install mmb-tools: dab multiplexer
apt-get install --yes \
libboost-system-dev \
libcurl4-openssl-dev \
libzmq3-dev \
python3-zmq
if [ ! -d "${DIR_MUX}" ]; then
pushd "${DIR_MMB}" || return
git clone https://github.com/Opendigitalradio/ODR-DabMux.git --branch "${1}"
popd || return
fi
pushd "${DIR_MUX}" || return
./bootstrap.sh
./configure
make
make install
make clean
popd || return
apt-get purge --yes \
libboost-system-dev \
libcurl4-openssl-dev
apt-get install --yes \
libboost-system1.74.0 \
libcurl4
}
install_dabmod () {
# Install mmb-tools: modulator
apt-get install --yes \
libbladerf-dev \
libcurl4-openssl-dev \
libfftw3-dev \
liblimesuite-dev \
libsoapysdr-dev \
libuhd-dev \
libzmq3-dev
if [ ! -d "${DIR_MOD}" ]; then
pushd "${DIR_MMB}" || return
git clone https://github.com/Opendigitalradio/ODR-DabMod.git --branch "${1}"
popd || return
fi
pushd "${DIR_MOD}" || return
./bootstrap.sh
./configure CFLAGS="-O3 -DNDEBUG" CXXFLAGS="-O3 -DNDEBUG" --enable-fast-math --enable-limesdr --enable-bladerf
make
make install
make clean
popd || return
apt-get purge --yes \
libbladerf-dev \
libcurl4-openssl-dev \
libfftw3-dev \
liblimesuite-dev \
libsoapysdr-dev \
libuhd-dev \
libzmq3-dev
apt-get install --yes \
libbladerf2 \
libcurl4 \
libfftw3-3 \
liblimesuite20.10-1 \
libsoapysdr0.7 \
libuhd3.15.0 \
libzmq5
}
install_fdkaac () {
# Install mmb-tools: fdk-aac
if [ ! -d "${DIR_FDKAAC}" ]; then
pushd "${DIR_MMB}" || return
git clone https://github.com/Opendigitalradio/fdk-aac.git
popd || return
fi
pushd "${DIR_FDKAAC}" || return
./bootstrap
./configure
make
make install
make clean
popd || return
}
install_srccmp () {
# Install mmb-tools: source companion
apt-get install --yes \
libzmq3-dev
if [ ! -d "${DIR_SRCCMP}" ]; then
pushd "${DIR_MMB}" || return
git clone https://github.com/Opendigitalradio/ODR-SourceCompanion.git --branch "${1}"
popd || return
fi
pushd "${DIR_SRCCMP}" || return
./bootstrap
./configure
make
make install
make clean
popd || return
apt-get purge --yes \
libzmq3-dev
apt-get install --yes \
libzmq5
}
install_encmgr () {
# Install mmb-tools: encoder manager
apt-get install --yes \
python3-cherrypy3 \
python3-jinja2 \
python3-pysnmp4 \
python3-serial \
python3-yaml \
supervisor
if [ ! -d "${DIR_ENCMGR}" ]; then
pushd "${DIR_MMB}" || return
git clone https://github.com/Opendigitalradio/ODR-EncoderManager.git --branch "${1}"
popd || return
fi
}
install_config () {
# Copy the configuration files
if [ -d "${DIR_CONFIG}" ]; then
rm -r "${DIR_CONFIG}"
fi
cp -r $(realpath $(dirname $0))/../${CONFIG_NAME} "${DIR_CONFIG}"
ln -s "${DIR_CONFIG}"/supervisor/*.conf /etc/supervisor/conf.d/
## Adapt the supervisor configuration files
for file in "${DIR_CONFIG}"/supervisor/*.conf; do
[[ -e ${file} ]] || break
sed \
-e "s;user=pi;user=$(id --user --name ${odr_user});g" \
-e "s;group=pi;group=$(id --group --name ${odr_user});g" \
-e "s;/home/pi;/home/${odr_user};g" \
-i "${file}"
done
## Adapt the ODR-EncoderManager configuration file
sed \
-e "s;/home/pi;/home/${odr_user};g" \
-e "s;\"user\": \"pi\";\"user\": \"$(id --user --name ${odr_user})\";g" \
-e "s;\"group\": \"pi\";\"group\": \"$(id --group --name ${odr_user})\";g" \
-i "${DIR_CONFIG}/encodermanager.json"
## Adapt the odr-misc.conf
sed \
-e "s;--host=raspberrypi.local;--host=$(hostname -I | awk '{print $1}');" \
-i "${DIR_CONFIG}/supervisor/ODR-misc.conf"
## Restart supervisor
supervisorctl reread
supervisorctl reload
echo "Sample configuration files installed"
}
install () {
# Clone the sources, build and install programs, clean-up
install_base "${1}"
install_fdkaac "${1}"
install_audioenc "${1}"
install_padenc "${1}"
install_dabmux "${1}"
install_dabmod "${1}"
install_srccmp "${1}"
install_encmgr "${1}"
install_config
ldconfig
chown --recursive ${odr_user}:${odr_user} /home/${odr_user}
apt-get autoremove --yes
rm -rf /var/lib/apt/lists/*
echo "ODR-mmbTools suite and configuration files installed"
}
remove () {
# Update supervisor
rm /etc/supervisor/conf.d/ODR-*
supervisorctl reread
supervisorctl reload
# Uninstall programs
for makefile in $(ls ${DIR_MMB}/**/Makefile); do
pushd $(dirname ${makefile}) || return
make uninstall
popd || return
done
# Delete sources
rm -rf "${DIR_MMB}"
# Delete configuration files
rm -rf "${DIR_CONFIG}"
echo "ODR-mmbTools suite and configuration files removed"
}
# MAIN PROGRAM
if test "$(id --user)" != "0"; then
echo "You must be root to run $(basename ${0})" >&2
exit 2
fi
branch="master"
action=""
odr_user="$(logname)"
while [ "$#" -gt 0 ] ; do
case "${1}" in
(-h|--help) print_usage; exit 0 ;;
(-b|--branch) branch="${2}" ; shift ;;
(--odr-user) odr_user="${2}" ; shift ;;
install) action="install" ;;
remove) action="remove" ;;
*) print_usage; exit 1 ;;
esac
shift
done
if test -z "${odr_user}"; then
echo "You must use the argument --odr-user" >&2
exit 3
fi
source $(realpath $(dirname $0))/mmbtools-get.conf
case "${action}" in
install) install "${branch}" ;;
remove) remove ;;
*) print_usage; exit 3 ;;
esac