-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
install
executable file
·1227 lines (1142 loc) · 45 KB
/
install
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
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash -e
#-e Causes bash script to exit if any of the installers
#return with a non-zero return value.
if [[ $EUID -ne 0 ]]; then
echo "Please run as root user."
exit 1
fi
SCRIPT_DIR="$( cd "$( dirname "$0" )" && pwd )"
AIRTIMEROOT=${SCRIPT_DIR}
showhelp () {
echo "Usage: sudo bash install [options]
-h, --help, -?
Display usage information
-V, --version
Display version information
-v, --verbose
More output
-q, --quiet, --silent
No output except errors
-f, --force
Turn off interactive prompts
--distribution=DISTRIBUTION
Linux distribution the installation is being run on
--release=RELEASE
Distribution release
-d, --ignore-dependencies
Don't install binary dependencies
-w, --web-user=WEB_USER
Set the apache web user. Defaults to www-data. Only change
this setting if you've changed the default apache web user
-r, --web-root=WEB_ROOT
Set the web root for Airtime files
This will copy the Airtime application files, but you will need
to give your web user access to the given directory if it is
not accessible
--web-port=WEB_PORT
Set what port the LibreTime interface should run on.
-I, --in-place
Set the current Airtime directory as the web root
Note that you will need to give your web user permission to
access this directory if it is not accessible
-p, --postgres
Create a default postgres user named 'airtime' with password
'airtime'
-a, --apache
Install apache and deploy a basic configuration for Airtime
-i, --icecast
Install Icecast 2 and deploy a basic configuration for Airtime
--selinux
Run restorecon on directories and files that need tagging to
allow the WEB_USER access
--no-postgres
Skips all postgres related install tasks (Useful if you configure
postgresql as part of another script / docker builds)
--no-rabbitmq
Skips all rabbitmq related install tasks.
"
exit 0
}
showversion () {
if [ ! -f "$SCRIPT_DIR/VERSION" ]; then
echo "Please initialize LibreTime by running ./build.sh"
exit 1
fi
version=$(cat "$SCRIPT_DIR/VERSION")
echo "LibreTime Version ${version}"
exit 0
}
web_user=""
web_root=""
web_port="80"
in_place="f"
postgres="f"
apache="f"
icecast="f"
ignore_dependencies="f"
selinux="f"
# Interactive
_i=1
# Verbose
_v=0
# Quiet
_q=0
upgrade="f"
dist=""
code=""
apache_bin=""
skip_postgres=0
skip_rabbitmq=0
default_value="Y"
function verbose() {
if [[ ${_v} -eq 1 ]]; then
echo -e "$@"
fi
}
function loud() {
if [[ ${_q} -eq 0 ]]; then
echo -e "$@"
fi
}
# Evaluate commands silently if quiet.
# If not quiet, output command if verbose.
function loudCmd() {
if [[ ${_q} -eq 0 ]]; then
verbose "$@"
eval $@
else
eval $@ > /dev/null
fi
}
function checkCommandExists() {
set +e
command=$@
eval hash ${command} 2>/dev/null
commandFound=$?
if [[ ! ${commandFound} -eq 0 ]]; then
echo -e "Error: ${command} not found. Please ensure you have the corresponding dependency installed."
exit
fi
set -e
}
# Function to determine if systemd, Upstart or System V Init is the active
# init system. All the newer supported distros use systemd out-of-the-box but
# a sysadmin could have installed an alternative init compatibility package.
# As a result, making assumptions based on the distribution and release is
# not a good idea. The detection works as follows:
# 1. Get the process name where PID=1 and follow any symlinks.
# 2. Look up that path in the appropriate package manager to get the name
# of the package that process is part of.
# See https://unix.stackexchange.com/questions/196166/how-to-find-out-if-a-system-uses-sysv-upstart-or-systemd-initsystem
has_systemd_init=false
has_upstart_init=false
has_systemv_init=false
function systemInitDetect() {
verbose "\nDetecting init system type ..."
# Get the path of the command where pid=1 following any symlinks
pid_1_path=$(readlink --canonicalize -n /proc/1/exe)
# returns '/sbin/init' (Debian Wheezy & Ubuntu Trusty)
# returns '(/usr)?/lib/systemd/systemd' (Debian Stretch, Debian Jessie, Debian Buster, Ubuntu Xenial, CentOS 7)
verbose "Detected path to PID=1 process: $pid_1_path"
# Get package of PID=1 path as it identifies the init system.
# Allow this to fail, at least then the init system can be guessed from the
# PID 1 executable alone
pid_1_package=$(dpkg -S $pid_1_path 2>/dev/null ||
rpm --qf '%{name}\n' -qf $pid_1_path 2>/dev/null ||
echo "unknown")
verbose "Detected package name for PID=1 process: $pid_1_package"
case "${pid_1_package}:${pid_1_path}" in
*systemd*) has_systemd_init=true; verbose "Detected init system type: systemd" ;;
*upstart*) has_upstart_init=true; verbose "Detected init system type: Upstart" ;;
*sysvinit*) has_systemv_init=true; verbose "Detected init system type: System V" ;;
*) echo "ERROR: Unable to detect init system using package or path of PID=1 process!" >&2
exit 1
;;
esac
return 0
}
# Function to wrap installation of services for systemd, Upstart and System V
# depending on which one was detected by the systemInitDetect() function.
# Service file is copied from a known location and installed into the system.
# In the process, filtering is performed for the userid if appropriate.
# If required, the service is enabled; then it is started.
# Usage:
# systemInitInstall service-name [user]
function systemInitInstall() {
local service_name="$1"
local user="$2"
local source_base_path=""
local source_path=""
local target_path=""
local alt_path=""
local source_config_path=""
local target_config_path=""
local python_source_path="${SCRIPT_DIR-$PWD}/python_apps"
verbose "\n * Installing service $service_name ..."
if $has_systemd_init; then
case "$service_name" in
libretime-analyzer)
source_path="${python_source_path}/airtime_analyzer/install/systemd/${service_name}.service"
target_path="/etc/systemd/system/${service_name}.service"
alt_path=$(echo $target_path | sed 's/libretime-/airtime_/')
;;
libretime-celery)
source_path="${python_source_path}/airtime-celery/install/systemd/${service_name}.service"
target_path="/etc/systemd/system/${service_name}.service"
alt_path=$(echo $target_path | sed 's/libretime-/airtime-/')
;;
libretime-liquidsoap|libretime-playout)
source_path="${python_source_path}/pypo/install/systemd/${service_name}.service"
target_path="/etc/systemd/system/${service_name}.service"
alt_path=$(echo $target_path | sed 's/libretime-/airtime-/')
;;
esac
if [[ ! -e $source_path ]]; then
echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2
exit 1
fi
# Stop and disable the service if it already exists
if [[ -e $target_path ]]; then
verbose "Service $service_name already exists - stopping and disabling."
loudCmd "systemctl disable ${service_name}.service"
loudCmd "systemctl stop ${service_name}.service"
fi
local old_style_unit_exists="f"
# Migrate old style airtime unit exist if it exists
if [[ -e $alt_path && ! -L $alt_path ]]; then
local old_service=$(echo $service_name | sed 's/libretime/airtime/' | sed 's/-analyzer/_analyzer/')
verbose "Old service $old_service already exists - migrating."
loudCmd "systemctl disable ${old_service}.service"
loudCmd "systemctl stop ${old_service}.service"
loudCmd "rm $alt_path"
old_style_unit_exists="t"
fi
# If no user defined, then just copy, otherwise filter
if [[ -z $user ]]; then
loudCmd "cp $source_path $target_path"
else
sed -e "s/User=.*/User=${user}/" \
-e "s/Group=.*/Group=${user}/" $source_path > $target_path
fi
if [[ $old_style_unit_exists == "t" ]]; then
verbose "Maintaining compatibility with old systemd unit names"
# Alias to old Airtime names
loudCmd "ln -s $source_path $alt_path"
fi
chmod 0644 $target_path
chown root:root $target_path
verbose "Service ${service_name} installed into ${target_path}"
# Enable and start the service
loudCmd "systemctl enable ${service_name}.service"
verbose "Service ${service_name} enabled and started"
elif $has_upstart_init; then
case "$service_name" in
libretime-analyzer)
source_path="${python_source_path}/airtime_analyzer/install/upstart/${service_name}.conf"
target_path="/etc/init/${service_name}.conf"
user=${user:-$web_user}
;;
libretime-celery)
source_path="${python_source_path}/airtime-celery/install/upstart/${service_name}.conf"
target_path="/etc/init/${service_name}.conf"
user=""
;;
libretime-liquidsoap|libretime-playout)
source_path="${python_source_path}/pypo/install/upstart/${service_name}.conf.template"
target_path="/etc/init/${service_name}.conf"
user=${user:-$web_user}
;;
esac
if [[ ! -e $source_path ]]; then
echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2
exit 1
fi
# Stop the service if it already exists
if [[ -e $target_path ]]; then
verbose "Service $service_name already exists - stopping."
loudCmd "service ${service_name} stop"
fi
# If no user defined, then just copy, otherwise filter
if [[ -z $user ]]; then
loudCmd "cp $source_path $target_path"
else
sed -e "s/WEB_USER/${user}/g" \
-e "/^set[gu]id/{s/www-data/${user}/}" $source_path > $target_path
fi
chmod 0644 $target_path
chown root:root $target_path
verbose "Service ${service_name} installed into ${target_path}"
loudCmd "initctl check-config $service_name"
elif $has_systemv_init; then
case "$service_name" in
libretime-analyzer)
source_path="${python_source_path}/airtime_analyzer/install/sysvinit/${service_name}"
target_path="/etc/init.d/${service_name}"
user=${user:-$web_user}
;;
libretime-celery)
source_path="${python_source_path}/airtime-celery/install/sysvinit/${service_name}"
target_path="/etc/init.d/${service_name}"
source_config_path="${python_source_path}/${service_name}/install/conf/${service_name}"
target_config_path="/etc/default/${service_name}"
user=""
;;
libretime-liquidsoap|libretime-playout)
source_path="${python_source_path}/pypo/install/sysvinit/${service_name}"
target_path="/etc/init.d/${service_name}"
user=${user:-$web_user}
;;
esac
if [[ ! -e $source_path ]]; then
echo "$0:${FUNCNAME}(): ERROR: service \"$service_name\" with source path \"$source_path\" does not exist!" >&2
exit 1
fi
# Stop the service if it already exists
if [[ -e $target_path ]]; then
verbose "Service $service_name already exists - stopping."
loudCmd "invoke-rc.d $service_name stop"
fi
# If no user defined, then just copy, otherwise filter
if [[ -z $user ]]; then
loudCmd "cp $source_path $target_path"
[[ -n $source_config_path ]] &&
loudCmd "cp $source_config_path $target_config_path"
else
sed -e "/^USERID/{s/www-data/${user}/}" \
-e "/^GROUPID/{s/www-data/${user}/}" $source_path > $target_path
fi
chmod 0644 $target_path
chown root:root $target_path
if [[ -n $target_config_path ]]; then
chmod 0644 $target_config_path
chown root:root $target_config_path
fi
verbose "Service ${service_name} installed into ${target_path}"
# Create symlinks for the appropriate runlevels
loudCmd "update-rc.d $service_name defaults"
verbose "Service ${service_name} enabled"
fi
return 0
}
# Function to wrap different systemd vs. Upstart init commands depending
# on which init system has been detected. Syntax is similar to systemctl.
# Usage:
# systemInitCommand _command_ [service-name ...]
# Where _command_ is one of: start, stop, status, reload, restart
# enable, disable and either daemon-reload or reload-configuration.
function systemInitCommand() {
local command=$1; shift
case "$command" in
start|stop|status|reload|restart)
if $has_systemd_init; then
loudCmd "systemctl $command $@"
elif $has_upstart_init; then
for svc_name in $@; do
loudCmd "service $svc_name $command"
done
elif $has_systemv_init; then
for svc_name in $@; do
loudCmd "invoke-rc.d $svc_name $command"
done
fi
;;
enable|disable) # TODO: REMOVE
$has_systemd_init &&
loudCmd "systemctl $command $1.service"
if $has_systemv_init; then
if [[ "$command" = "enable" ]]
then loudCmd "update-rc.d $1 defaults"
else loudCmd "update-rc.d $1 enable"
fi
fi
;;
daemon-reload|reload-configuration)
$has_systemd_init &&
loudCmd "systemctl daemon-reload"
$has_upstart_init &&
loudCmd "initctl reload-configuration"
;;
*) echo -e "$0:${FUNCNAME}(): ERROR: command \"$command\" is not supported!" >&2
exit 1
;;
esac
return 0
}
while :; do
case "$1" in
--help)
showhelp
;;
--version)
showversion
;;
--verbose)
_v=1
;;
--quiet|--silent)
_q=1
;;
--force)
_i=0
;;
--distribution)
if [ "$2" ]; then
dist=$2
shift 2
continue
else
echo 'ERROR: Must specify a non-empty "--distribution DISTRIBUTION" argument.' >&2
exit 1
fi
;;
--distribution=?*)
dist=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--distribution=)
echo 'ERROR: Must specify a non-empty "--distribution DISTRIBUTION" argument.' >&2
exit 1
;;
--release)
if [ "$2" ]; then
code=$2
shift 2
continue
else
echo 'ERROR: Must specify a non-empty "--release RELEASE" argument.' >&2
exit 1
fi
;;
--release=?*)
code=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--release=)
echo 'ERROR: Must specify a non-empty "--release RELEASE" argument.' >&2
exit 1
;;
--ignore-dependencies)
ignore_dependencies="t"
;;
--apache)
apache="t"
;;
--icecast)
icecast="t"
;;
--postgres)
postgres="t"
;;
--in-place)
in_place="t"
;;
--web-user)
if [ "$2" ]; then
web_user=$2
shift 2
continue
else
echo 'ERROR: Must specify a non-empty "--web-user WEB_USER" argument.' >&2
exit 1
fi
;;
--web-user=?*)
web_user=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--web-user=)
echo 'ERROR: Must specify a non-empty "--web-user=WEB_USER" argument.' >&2
exit 1
;;
--web-root)
if [ "$2" ]; then
web_root=$(readlink -f $2)
shift 2
continue
else
echo 'ERROR: Must specify a non-empty "--web-root WEB_ROOT" argument.' >&2
exit 1
fi
;;
--web-root=?*)
web_root=${1#*=} # Delete everything up to "=" and assign the remainder.
;;
--web-root=)
echo 'ERROR: Must specify a non-empty "--web-root=WEB_ROOT" argument.' >&2
exit 1
;;
--web-port)
echo 'ERROR: Please specify a port number.' >&2
exit 1
;;
--web-port=)
echo 'ERROR: Please specify a port number.' >&2
exit 1
;;
--web-port=?*)
web_port=${1#*=}
;;
--selinux)
selinux="t"
;;
--no-postgres)
skip_postgres=1
;;
--no-rabbitmq)
skip_rabbitmq=1
;;
--)
shift
break
;;
-?*)
for ((i = 1; i < ${#1}; i++)); do
case "${1:$i:1}" in
h|\?)
showhelp
;;
V)
showversion
;;
v)
_v=1
;;
q)
_q=1
;;
f)
_i=0
;;
d)
ignore_dependencies="t"
;;
a)
apache="t"
;;
i)
icecast="t"
;;
p)
postgres="t"
;;
I)
in_place="t"
;;
w)
if [ "$2" ]; then
web_user=$2
continue
else
echo 'ERROR: Must specify a non-empty "-w WEB_USER" argument.' >&2
exit 1
fi
;;
r)
if [ "$2" ]; then
web_root=$(readlink -f $2)
continue
else
echo 'ERROR: Must specify a non-empty "-d WEB_ROOT" argument.' >&2
exit 1
fi
;;
*)
echo "$0: error - unrecognized option '${1:$i:1}'" >&2;
echo "Try 'install --help' for more information."
exit 1
esac
done
;;
*)
break
esac
shift
done
if [ -z web_root -a ! -d web_root ]; then
echo "$web_root doesn't exist!"
exit 1
fi
echo -e "\n.____ ._____. ___________.__ "
echo "| | |__\_ |_________ ___\__ ___/|__| _____ ____ "
echo "| | | || __ \_ __ \_/ __ \| | | |/ \_/ __ \ "
echo "| |___| || \_\ \ | \/\ ___/| | | | Y Y \ ___/ "
echo "|_______ \__||___ /__| \___ >____| |__|__|_| /\___ >"
echo -e " \/ \/ \/ \/ \/\n"
echo -e "Detecting distribution and release ..."
if [ -e /etc/os-release ]; then
# Access $ID, $VERSION_ID and $PRETTY_NAME
source /etc/os-release
echo "Detected distribution id: $ID"
echo "Detected distribution release id: $VERSION_ID"
echo "Detected distribution description: $PRETTY_NAME"
else
ID=unknown
VERSION_ID=unknown
PRETTY_NAME="Unknown distribution and release"
echo "WARNING: /etc/os-release configuration not found. Unable to detect distribution." >&2
if [ -z "$dist" -o -z "$code" ]; then
echo "ERROR: One or both of --distribution and --release options were not specified." >&2
echo "This is an unsupported distribution and/or version!" >&2
exit 1
fi
fi
# Validate --distribution parameter has a sane value for this OS.
if [ -n "$dist" ]; then
dist=${dist,,}
verbose "Checking --distribution \"$dist\" to ensure it has a sane value."
# If $ID detected above does not match parameter, then do some checking
if [ "$dist" != "$ID" ]; then
verbose "Detected distribution \"$ID\" does not match specified one of \"$dist\". Checking ..."
case "$dist" in
centos|rhel) pkg_installer=/usr/bin/yum; verbose "Detected yum package installer" ;;
debian|ubuntu) pkg_installer=/usr/bin/apt-get; verbose "Detected apt-get package installer" ;;
*) echo "ERROR: the value \"$dist\" specified for --distribution is unsupported." >&2
exit 1
;;
esac
if [ ! -x "$pkg_installer" ]; then
echo "ERROR: The value \"$dist\" specified for --distribution does not appear compatible!" >&2
exit 1
fi
fi
fi
# Validate the distribution and release is a supported one; set boolean flags.
is_debian_dist=false
is_debian_buster=false
is_debian_stretch=false
is_ubuntu_dist=false
is_ubuntu_bionic=false
is_ubuntu_xenial=false
is_centos_dist=false
is_centos_7=false
is_centos_8=false
# Use specified distribution and release or detected otherwise.
dist="${dist:-$ID}"
code="${code:-$VERSION_ID}"
code="${code,,}"
verbose "Validating dist-code: ${dist}-${code}"
case "${dist}-${code}" in
ubuntu-18.04)
code="bionic"
is_ubuntu_dist=true
is_ubuntu_bionic=true
;;
ubuntu-16.04|ubuntu-xenial|ubuntu-xenial_docker_minimal)
code="xenial"
is_ubuntu_dist=true
is_ubuntu_xenial=true
;;
ubuntu-14.04|ubuntu-trusty)
echo -e "ERROR: Ubuntu Trusty is archived and does not receive any security or other updates since 2019-04-17." >&2
echo -e "The LibreTime installer dropped support for installing LibreTime on Trusty in 3.0.0-alpha.8." >&2
exit 1
;;
debian-9|debian-stretch)
code="stretch"
is_debian_dist=true
is_debian_stretch=true
;;
debian-10|debian-buster)
code="buster"
is_debian_dist=true
is_debian_buster=true
;;
#Fix for Raspbian 9 (stretch)
raspbian-9|9)
code="stretch"
dist="debian"
is_debian_dist=true
is_debian_stretch=true
;;
#End of fix
#Fix for Raspbian 10 (buster)
raspbian-10|10)
code="buster"
dist="debian"
is_debian_dist=true
is_debian_buster=true
;;
#End of fix
debian-8|debian-jessie)
echo -e "ERROR: Debian Jessie is archived and does not receive any security or other updates since 2018-05-17." >&2
echo -e "The LibreTime installer dropped support for installing LibreTime on Jessie in 3.0.0-alpha.8." >&2
exit 1
;;
debian-7|debian-wheezy)
echo -e "ERROR: Debian Wheezy is archived and does not receive any security or other updates since 2018-05-31." >&2
echo -e "The LibreTime installer dropped support for installing LibreTime on Wheezy in 3.0.0-alpha.6." >&2
exit 1
;;
centos-8)
is_centos_dist=true
is_centos_8=true
;;
*)
echo -e "ERROR: Distribution \"$PRETTY_NAME\" is not supported with \"${dist}-${code}\"!" >&2
exit 1
;;
esac
verbose "Using distribution id \"$dist\", release code \"$code\""
# Detect init system type
systemInitDetect
if $is_centos_dist; then
python_bin="python3.8"
apache_bin="httpd"
apache_service="httpd"
web_user="${web_user:-apache}"
else
python_bin="python3"
apache_bin="apache2ctl"
apache_service="apache2"
web_user="${web_user:-www-data}"
fi
if [ "$ignore_dependencies" = "f" ]; then
set +e
loud "\n-----------------------------------------------------"
loud " * Installing External Dependencies * "
loud "-----------------------------------------------------"
if $is_ubuntu_dist; then
loudCmd "add-apt-repository -y ppa:libretime/libretime"
fi
if [ -x /usr/bin/apt-get ]; then
verbose "\n * Reading requirements-${dist}-${code}.apt..."
loudCmd "apt-get -q update"
package_list_file="${SCRIPT_DIR}/installer/lib/requirements-${dist}-${code}.apt"
if [ ! -f "$package_list_file" ]; then
echo "ERROR: package file does not exist: $package_list_file" >&2
exit 1
fi
# For apt-get version 1.1 or higher, --force-yes is deprecated so use new options.
apt_force_options="--allow-downgrades --allow-remove-essential --allow-change-held-packages"
# Get apt-get version by returning the 2nd parameter from the 1st line of output
apt_version=$(apt-get --version |awk 'NR == 1 { print $2 }')
# returns 1.8.0~alpha3 (Debian Buster)
# returns: 1.4.7 (Debian Stretch)
# returns: 0.9.7.9 (Debian Wheezy)
# returns: 1.0.1ubuntu2 (Ubuntu Trusty)
# returns: 1.0.9.8.4 (Debian Jessie)
# returns: 1.2.9 (Ubuntu Xenial)
verbose "Detected apt-get version as: $apt_version"
apt_version_formatted=$(awk 'BEGIN {FS = "."} {printf "%03d.%03d\n", $1,$2}' <<< $apt_version)
[[ "$apt_version_formatted" < "001.001" ]] && apt_force_options="--force-yes"
verbose "Using apt-get force options: $apt_force_options"
loudCmd "DEBIAN_FRONTEND=noninteractive apt-get -y -m ${apt_force_options} install $(grep -vE '^\s*#' $package_list_file | tr '\n' ' ')"
if [ "$in_place" = "t" ]; then
loudCmd "DEBIAN_FRONTEND=noninteractive apt-get -y -m install git"
fi
else
echo "WARNING: installing dependencies is not supported for this distribution" >&2
fi
set -e
else
checkCommandExists "${apache_bin}"
checkCommandExists "rabbitmqctl"
checkCommandExists "psql"
if [ "$in_place" = "t" ]; then
checkCommandExists "git"
fi
fi
# Check if composer exists and install if it doesn't
set +e
eval hash "composer" 2>/dev/null
commandFound=$?
set -e
if [[ ! ${commandFound} -eq 0 ]]; then
curl -sS https://getcomposer.org/installer > get-composer.php
php ./get-composer.php --install-dir=/usr/local/bin --filename=composer
rm get-composer.php
PATH="${PATH}:/usr/local/bin"
fi
# Run composer (install PHP dependencies) and create a VERSION file
loudCmd "./build.sh"
if [ -f /etc/airtime/airtime.conf ]; then
# TODO use VERSION or some other way to check for updates and handle
# media-monitor case on it's own
OLD_CONF=$(grep -F "[media-monitor]" /etc/airtime/airtime.conf || true)
if [ -n "${OLD_CONF}" ]; then
upgrade="t"
set +e
verbose "Stopping airtime services..."
systemInitCommand stop airtime_analyzer airtime-celery airtime-playout airtime-liquidsoap airtime-media-monitor
verbose "...Done"
verbose "Disabling obsolete services..."
systemInitCommand disable airtime-media-monitor
verbose "...Done"
echo "Looks like you have an old version of Airtime. Your current /etc/airtime/airtime.conf \
will be moved to /etc/airtime/airtime.conf.tmp"
# If we don't remove the existing python files in /usr/lib and the
# /etc/init.d startup scripts, services won't work properly
if [ -d /usr/lib/airtime/ ]; then
rm -rf /usr/lib/airtime/
fi
rm -f /etc/init.d/airtime*
rm -f /etc/init/airtime*
rm -f /etc/default/airtime-celery
if [ "$apache" = "t" ]; then
# If the user selects an "in-place" install or passes in a web root,
# we need to replace the old apache airtime.conf
rm /etc/apache2/sites-available/airtime.conf /etc/apache2/sites-enabled/airtime.conf
fi
if [ -d /usr/share/airtime -a web_root = /usr/share/airtime ]; then
rm -rf /usr/share/airtime
fi
mv /etc/airtime/airtime.conf /etc/airtime/airtime.conf.tmp
set -e
fi
fi
if [ "$apache" = "f" -a ${_i} -eq 1 ]; then
echo -e "Install default Airtime apache configuration? (Y/n): \c"
read IN
IN=${IN:-$default_value}
if [ "$IN" = "y" -o "$IN" = "Y" ]; then
apache="t"
fi
fi
if [ "$in_place" = "t" ]; then
verbose "\n * Setting current Airtime directory as web root..."
web_root=${AIRTIMEROOT}/airtime_mvc/public
elif [ -n "$web_root" ]; then
verbose "\n * Creating Apache web root directory..."
cp -R ${AIRTIMEROOT}/airtime_mvc ${web_root}
cp -R ${AIRTIMEROOT}/vendor ${web_root}
cp ${AIRTIMEROOT}/VERSION ${web_root}
web_root=${web_root}/airtime_mvc/public/
else
verbose "\n * Creating default Apache web root directory /usr/share/airtime/php..."
web_root="/usr/share/airtime/php"
mkdir -p ${web_root}
cp -R ${AIRTIMEROOT}/airtime_mvc ${web_root}
cp -R ${AIRTIMEROOT}/vendor ${web_root}
cp ${AIRTIMEROOT}/VERSION ${web_root}
web_root=${web_root}/airtime_mvc/public/
fi
verbose "...Done"
if [ "$apache" = "t" ]; then
loud "\n-----------------------------------------------------"
loud " * Configuring Apache * "
loud "-----------------------------------------------------"
# Detect Apache root folder, e.g. /etc/apache2 or /etc/httpd
eval $($apache_bin -V |awk '/HTTPD_ROOT|SERVER_CONFIG_FILE/ { print $2 }')
apache_conf="${HTTPD_ROOT}/${SERVER_CONFIG_FILE}"
verbose "Detected Apache root folder is: ${HTTPD_ROOT}"
if [[ ! -e $apache_conf ]]; then
echo -e "ERROR: Apache binary \"$apache_bin\" points to a non-existent file \"$apache_conf\""
exit 1
fi
verbose "Detected Apache primary .conf file is: ${apache_conf}"
if [[ -d ${HTTPD_ROOT}/sites-available ]]; then # debian & ubuntu
apache_sitedir="${HTTPD_ROOT}/sites-available/"
elif [[ -d ${HTTPD_ROOT}/conf.d ]]; then # centos
apache_sitedir="${HTTPD_ROOT}/conf.d/"
else
echo -e "ERROR: unknown location of Apache sites-available or virtual host directory!" >&2
exit 1
fi
verbose "Detected Apache sites configuration folder: ${apache_sitedir}"
set +e
# Parse: Server version: Apache/2.2.22 (Ubuntu) -> 2
apache_major_version=$($apache_bin -v |awk -F'[ /.]+' 'NR == 1 { print $4 }')
set -e
if [[ "$apache_major_version" -ge 2 ]]; then
airtimeconfigfile="airtime.conf"
oldconfigfile="airtime-vhost.conf"
else
airtimeconfigfile="airtime"
oldconfigfile="airtime-vhost"
fi
# If we're upgrading (installing over an existing Airtime install) and we've been told to
# install apache, we should overwrite any existing configuration. If we don't do this, doing
# an in-place installation over an old Airtime install (which installs to /usr/share by default)
# will fail
if [ "$upgrade" = "t" -o ! -f ${apache_sitedir}${airtimeconfigfile} ]; then
verbose "\n * Creating Apache config for Airtime..."
listen_port=""
if [ "$web_port" != "80" ]; then
listen_port="Listen ${web_port}"
fi
apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost-2.4
if [[ "$apache_major_version" -eq 1 ]]; then
# fall back to apache 1 config
apache_template_file=${SCRIPT_DIR}/installer/apache/airtime-vhost
fi
sed \
-e "s@WEB_PORT_LISTEN@${listen_port}@g" \
-e "s@WEB_PORT@${web_port}@g" \
-e "s@WEB_ROOT@${web_root}@g" \
${apache_template_file} > ${apache_sitedir}${airtimeconfigfile}
# The a2ensite/a2dissite utilities are not available on CentOS
if [[ -x /usr/sbin/a2ensite ]]; then
loudCmd "a2dissite 000-default"
# If Airtime was previously installed with apt, the vhost file name is different,
# so we need to specifically disable it.
if [ -f "/etc/apache2/sites-available/${oldconfigfile}" ]; then
loudCmd "a2dissite airtime-vhost"
fi
loudCmd "a2ensite airtime"
fi
else
verbose "\nApache config for Airtime already exists, skipping"
fi
fi
if [ "$icecast" = "f" -a ${_i} -eq 1 ]; then
echo -e "Install default Airtime Icecast configuration? (Y/n): \c"
read IN
IN=${IN:-$default_value}
if [ "$IN" = "y" -o "$IN" = "Y" ]; then
icecast="t"
fi
fi
if [ "$icecast" = "t" ]; then
loud "\n-----------------------------------------------------"
loud " * Configuring Icecast * "
loud "-----------------------------------------------------"
verbose "\n * Enabling Icecast 2..."
icecast_unit_name="icecast2"
if [ "$dist" != "centos" ]; then
sed -i 's/ENABLE=false/ENABLE=true/g' /etc/default/icecast2
icecast_config="/etc/icecast2/icecast.xml"
else
icecast_unit_name="icecast"
icecast_config="/etc/icecast.xml"
fi
systemInitCommand enable ${icecast_unit_name}
# only update icecast password if
if [ ! -e "/etc/airtime/airtime.conf" ] && [ ! -e "/etc/airtime/airtime.conf.tmp" ]; then
icecast_pass=$(< /dev/urandom tr -dc _A-Z-a-z-0-9 | head -c${1:-12};)
echo $icecast_pass > /tmp/icecast_pass
loud "\n New install detected setting icecast password to random value."
xmlstarlet ed --inplace -u /icecast/authentication/source-password -v $icecast_pass $icecast_config
xmlstarlet ed --inplace -u /icecast/authentication/relay-password -v $icecast_pass $icecast_config
xmlstarlet ed --inplace -u /icecast/authentication/admin-password -v $icecast_pass $icecast_config
fi
# restart in case icecast was already started (like is the case on debian)
systemInitCommand restart ${icecast_unit_name}
verbose "...Done"
fi
loud "\n-----------------------------------------------------"
loud " * Installing Airtime Services * "
loud "-----------------------------------------------------"
python_version=$($python_bin --version 2>&1 | awk '{ print $2 }')
verbose "Detected Python version: $python_version"
verbose "\n * Installing necessary python services..."
loudCmd "$python_bin -mpip install setuptools --upgrade"
verbose "...Done"
verbose "\n * Creating /run/airtime..."
mkdir -p /run/airtime
chmod 755 /run/airtime
chown -R ${web_user}:${web_user} /run/airtime
verbose "...Done"
if [ ! -d /var/log/airtime ]; then
loud "\n-----------------------------------------------------"
loud " * Installing Log Files * "
loud "-----------------------------------------------------"
verbose "\n * Creating /var/log/airtime"
loudCmd "mkdir -p /var/log/airtime"
verbose "\n * Copying logrotate files..."
loudCmd "cp ${AIRTIMEROOT}/airtime_mvc/build/airtime-php.logrotate /etc/logrotate.d/airtime-php"
loudCmd "cp ${AIRTIMEROOT}/python_apps/pypo/liquidsoap/airtime-liquidsoap.logrotate /etc/logrotate.d/airtime-liquidsoap"
fi
verbose "\n * Installing API client..."
loudCmd "$python_bin ${AIRTIMEROOT}/python_apps/api_clients/setup.py install --install-scripts=/usr/bin"
verbose "...Done"
verbose "\n * Installing pypo and liquidsoap..."
loudCmd "$python_bin ${AIRTIMEROOT}/python_apps/pypo/setup.py install --install-scripts=/usr/bin --no-init-script"
loudCmd "mkdir -p /var/log/airtime/{pypo,pypo-liquidsoap} /var/tmp/airtime/pypo/{cache,files,tmp} /var/tmp/airtime/show-recorder/"
loudCmd "chown -R ${web_user}:${web_user} /var/log/airtime/{pypo,pypo-liquidsoap} /var/tmp/airtime/pypo/{cache,files,tmp} /var/tmp/airtime/show-recorder/"
systemInitInstall libretime-liquidsoap $web_user
systemInitInstall libretime-playout $web_user
verbose "...Done"