-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathosp-config.sh
More file actions
1297 lines (1182 loc) · 53.5 KB
/
osp-config.sh
File metadata and controls
1297 lines (1182 loc) · 53.5 KB
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
# OSP Control Script
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
OSPLOG="/var/log/osp/installer.log"
VERSION=$(<version)
NGINX_BUILD_VERSION="1.22.1"
NGINX_RTMP_VERSION="1.2.11"
NGINX_ZLIB_VERSION="1.3.1"
EJABBERD_VERSION="23.04"
DIALOG_CANCEL=1
DIALOG_ESC=255
HEIGHT=0
WIDTH=0
updateRunCount=0
archu=$( uname -r | grep -i "arch")
if [[ "$archu" = *"arch"* ]]
then
arch=true
web_root='/srv/http'
http_user='http'
else
arch=false
web_root='/var/www'
http_user='www-data'
fi
#######################################################
# Check Requirements
#######################################################
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
exit 1
fi
command -v dialog >/dev/null 2>&1 || { echo >&2 "Dialog is required but it's not installed. (apt-get dialog/packman -S dialog) Aborting."; exit 1; }
command -v sudo >/dev/null 2>&1 || { echo >&2 "Sudo is required but it's not installed. (apt-get sudo/packman -S sudo) Aborting."; exit 1; }
#######################################################
# Script Functions
#######################################################
display_result() {
dialog --title "$1" \
--no-collapse \
--msgbox "$result" 20 70
}
update_and_install_safely(){
attemptCount=0
maxAttemptCount=10
packages="$@"
if [ $updateRunCount -le 0 ]; then
echo "INFO: apt-get update has not run yet for this instance of the install script. Running now..."
sudo apt-get update
echo "INFO: unattended-upgrades has not yet run for this instance of the install script. Running now..."
sudo unattended-upgrade --debug
updateRunCount=1
fi
echo "Checking to see if dpkg files are currently in use..."
while [ $attemptCount -le $maxAttemptCount ]; do
if ! sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; then
echo "Dpkg is available."
if [ -n "$packages" ]; then
echo "Continuing with install of the following packages: $packages"
sudo apt-get install -y $packages
else
echo "Continuing with install process..."
fi
break
fi
echo "Dpkg is currently locked by another process. Waiting..."
sleep 5
attemptCount=$((attemptCount +1 ))
done
if sudo fuser /var/lib/dpkg/lock-frontend >/dev/null 2>&1; then
echo "ERROR: Dpkg locked for extended duration."
echo "ERROR: Results from sudo lsof /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend"
sudo lsof /var/lib/dpkg/lock /var/lib/dpkg/lock-frontend
if [ -n "$packages" ]; then
echo "ERROR: You may need to reinstall the following packages: $packages"
else
echo "ERROR: This error was generated without any packages to install."
fi
fi
}
confirm_service_is_running(){
serviceToCheck=$1
attemptCount=0
maxAttemptCount=10
if [ -z "$serviceToCheck" ]; then
echo "ERROR: confirm_service_is_running() was called without any parameters! Install will continue.."
return 1
fi
while [ $attemptCount -le $maxAttemptCount ]; do
if systemctl is-active --quiet "$serviceToCheck"; then
echo "$serviceToCheck is ready! Continuing with install..."
break
else
echo "$serviceToCheck is currently unavailable..."
sleep 5
attemptCount=$((attemptCount +1 ))
fi
done
if ! systemctl is-active --quiet "$serviceToCheck"; then
echo "ERROR: $serviceToCheck failed to start after $maxAttemptCount attempts. This might cause errors with future commands."
return 1
fi
}
config_smtp() {
smtpSendAs=""
smtpServerAddress=""
smtpServerPort=""
smtpUsername=""
smtpPassword=""
smtpEncryption=""
exec 3>&1
# Store data to $VALUES variable
VALUES=$(dialog --separate-widget $'\n' --ok-label "Save" \
--title "Configure SMTP Settings" \
--form "Please Configure your SMTP Settings (Required)" \
20 70 0 \
"Send Email As: (*)" 1 1 "$smtpSendAs" 1 25 40 0 \
"SMTP Server Address: (*)" 2 1 "$smtpServerAddress" 2 25 40 0 \
"SMTP Server Port: (*)" 3 1 "$smtpServerPort" 3 25 5 0 \
"Username:" 4 1 "$smtpUsername" 4 25 40 0 \
"Password:" 5 1 "$smtpPassword" 5 25 40 0 \
2>&1 1>&3)
echo "$VALUES" > /tmp/o.txt
smtpSendAs=$(cat /tmp/o.txt | head -1)
smtpServerAddress=$(cat /tmp/o.txt | head -2 | tail -1)
smtpServerPort=$(cat /tmp/o.txt | head -3 | tail -1)
smtpUsername=$(cat /tmp/o.txt | head -4 | tail -1)
smtpPassword=$(cat /tmp/o.txt | head -5 | tail -1)
rm /tmp/o.txt
cmd=(dialog --title "Configure SMTP Settings" --radiolist "Select SMTP Server Encryption": 20 70 0 1 "None" on 2 "TLS" off 3 "SSL" off
)
choice=$("${cmd[@]}" "${options[@]}" 2>&1 > /dev/tty )
smtpEncryption=""
case $choice in
1)
smtpEncryption="none"
;;
2)
smtpEncryption="tls"
;;
3)
smtpEncryption="ssl"
;;
*)
smtpEncryption="none"
;;
esac
sudo sed -i "s/sendAs@email.com/$smtpSendAs/" /opt/osp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i "s/smtp.email.com/$smtpServerAddress/" /opt/osp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i "s/smtpServerPort=25/smtpServerPort=$smtpServerPort/" /opt/osp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i "s/smtpUsername=\"\"/smtpUsername=\"$smtpUsername\"/" /opt/osp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i "s/smtpPassword=\"\"/smtpPassword=\"$smtpPassword\"/" /opt/osp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i "s/smtpEncryption=\"none\"/smtpEncryption=\"$smtpEncryption\"/" /opt/osp/conf/config.py >> $OSPLOG 2>&1
exec 3>&-
}
reset_nginx() {
if cd /usr/local/nginx/conf
then
echo 5 | dialog --title "Reset Nginx Configuration" --gauge "Stopping Nginx-OSP" 10 70 0
sudo systemctl stop nginx-osp
sudo systemctl disable nginx-osp
echo 20 | dialog --title "Reset Nginx Configuration" --gauge "Backing up Existing Conf" 10 70 0
sudo mkdir /tmp/nginxbak >> $OSPLOG 2>&1
sudo cp -R /usr/local/nginx/conf /tmp/nginxbak >> $OSPLOG 2>&1
cd /
echo 30 | dialog --title "Reset Nginx Configuration" --gauge "Removing Previous Nginx Instance" 10 70 0
sudo rm -rf /usr/local/nginx >> $OSPLOG 2>&1
echo 50 | dialog --title "Reset Nginx Configuration" --gauge "Rebuilding Nginx from Source" 10 70 0
install_nginx_core
echo 75 | dialog --title "Reset Nginx Configuration" --gauge "Restoring Nginx Conf" 10 70 0
sudo cp -R /tmp/nginxbak/conf/* /usr/local/nginx/conf/ >> $OSPLOG 2>&1
echo 90 | dialog --title "Reset Nginx Configuration" --gauge "Restarting Nginx-OSP" 10 70 0
sudo systemctl enable nginx-osp
sudo systemctl start nginx-osp
fi
}
reset_ejabberd() {
#delete old settings in config.py
sudo sed -i '/^ejabberdPass/d' /opt/osp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i '/^ejabberdHost/d' /opt/osp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i '/^ejabberdAdmin/d' /opt/osp/conf/config.py >> $OSPLOG 2>&1
#add new settings lines to conifg.py
sudo echo 'ejabberdAdmin = "admin"' >> /opt/osp/conf/config.py
sudo echo 'ejabberdHost = "localhost"' >> /opt/osp/conf/config.py
sudo echo 'ejabberdPass = "CHANGE_EJABBERD_PASS"' >> /opt/osp/conf/config.py
install_ejabberd
generate_ejabberd_admin
}
upgrade_db() {
UPGRADELOG="/opt/osp/logs/upgrade.log"
echo 0 | dialog --title "Upgrading Database" --gauge "Stopping OSP" 10 70 0
sudo systemctl stop osp.target >> $OSPLOG 2>&1
cd /opt/osp
echo 50 | dialog --title "Upgrading Database" --gauge "Upgrading Database" 10 70 0
source venv/bin/activate >> $OSPLOG 2>&1
flask db upgrade >> $OSPLOG 2>&1
deactivate >> $OSPLOG 2>&1
echo 75 | dialog --title "Upgrading Database" --gauge "Starting OSP" 10 70 0
sudo systemctl start osp.target >> $OSPLOG 2>&1
echo 100 | dialog --title "Upgrading Database" --gauge "Complete" 10 70 0
cd $DIR
}
install_prereq() {
echo 10 | dialog --title "Installing Prereqs" --gauge "Installing Preqs - Debian Based" 10 70 0
# Get Deb Dependencies
update_and_install_safely wget build-essential libpcre3 libpcre3-dev libssl-dev unzip libpq-dev curl git >> $OSPLOG 2>&1
# Setup Python
echo 50 | dialog --title "Installing Prereqs" --gauge "Installing Python3 Requirements - Debian Based" 10 70 0
update_and_install_safely python3 python3-pip python3-venv uwsgi-plugin-python3 python3-dev python3-setuptools >> $OSPLOG 2>&1
}
install_ffmpeg() {
#Setup FFMPEG for recordings and Thumbnails
echo 10 | dialog --title "Installing FFMPEG" --gauge "Installing FFMPEG" 10 70 0
echo 45 | dialog --title "Installing FFMPEG" --gauge "Installing FFMPEG" 10 70 0
#sudo add-apt-repository ppa:jonathonf/ffmpeg-4 -y >> $OSPLOG 2>&1
#echo 75 | dialog --title "Installing FFMPEG" --gauge "Installing FFMPEG" 10 70 0
echo 90 | dialog --title "Installing FFMPEG" --gauge "Installing FFMPEG" 10 70 0
update_and_install_safely ffmpeg >> $OSPLOG 2>&1
}
install_mysql(){
echo 10 | dialog --title "Installing MySQL" --gauge "Installing MySQL Server" 10 70 0
update_and_install_safely mariadb-server >> $OSPLOG 2>&1
echo 25 | dialog --title "Installing MySQL" --gauge "Copying MySQL Configuration" 10 70 0
sudo cp $DIR/setup/mysql/mysqld.cnf /etc/mysql/my.cnf >> $OSPLOG 2>&1
echo 50 | dialog --title "Installing MySQL" --gauge "Restarting MySQL Server" 10 70 0
sudo systemctl restart mysql >> $OSPLOG 2>&1
confirm_service_is_running mysql >> $OSPLOG 2>&1
echo 75 | dialog --title "Installing MySQL" --gauge "Building Database" 10 70 0
sudo mysql -e "create database osp" >> $OSPLOG 2>&1
#Check if admin account already exists. This can happen if you are reinstalling over an existing install.
SQLPASS=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 )
USER_EXISTS=$(sudo mysql -e "SELECT EXISTS(SELECT 1 FROM mysql.user WHERE user = 'osp' AND host = 'localhost');" -s -N)
if [ "$USER_EXISTS" -eq 1 ]; then
echo "OSP admin account for mysql (osp@localhost) already exists. Resetting password and updating config..." >> $OSPLOG 2>&1
sudo mysql -e "ALTER USER 'osp'@'localhost' IDENTIFIED BY '$SQLPASS';"
sudo mysql -e "GRANT ALL PRIVILEGES ON osp.* TO 'osp'@'localhost'" >> $OSPLOG 2>&1
sudo mysql -e "flush privileges" >> $OSPLOG 2>&1
echo 100 | dialog --title "Installing MySQL" --gauge "Updating OSP Configuration File" 10 70 0
sudo sed -i "s/sqlpass/$SQLPASS/g" /opt/osp-rtmp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i "s/sqlpass/$SQLPASS/g" /opt/osp/conf/config.py >> $OSPLOG 2>&1
else
echo "No OSP admin account detected for mysql. Generating admin account..." >> $OSPLOG 2>&1
sudo mysql -e "CREATE USER 'osp'@'localhost' IDENTIFIED BY '$SQLPASS'" >> $OSPLOG 2>&1
sudo mysql -e "GRANT ALL PRIVILEGES ON osp.* TO 'osp'@'localhost'" >> $OSPLOG 2>&1
sudo mysql -e "flush privileges" >> $OSPLOG 2>&1
echo 100 | dialog --title "Installing MySQL" --gauge "Updating OSP Configuration File" 10 70 0
sudo sed -i "s/sqlpass/$SQLPASS/g" /opt/osp-rtmp/conf/config.py >> $OSPLOG 2>&1
sudo sed -i "s/sqlpass/$SQLPASS/g" /opt/osp/conf/config.py >> $OSPLOG 2>&1
fi
}
install_nginx_core() {
install_prereq
# Build Nginx with RTMP module
echo 10 | dialog --title "Installing Nginx-Core" --gauge "Downloading Nginx Source" 10 70 0
if cd /tmp
then
echo 5 | dialog --title "Installing Nginx-Core" --gauge "Downloading Nginx Source" 10 70 0
sudo wget -q "http://nginx.org/download/nginx-$NGINX_BUILD_VERSION.tar.gz" >> $OSPLOG 2>&1
echo 15 | dialog --title "Installing Nginx-Core" --gauge "Downloading Required Modules" 10 70 0
#sudo wget -q "https://github.com/arut/nginx-rtmp-module/archive/v$NGINX_RTMP_VERSION.zip" >> $OSPLOG 2>&1
sudo wget -q "https://github.com/winshining/nginx-http-flv-module/archive/refs/tags/v$NGINX_RTMP_VERSION.tar.gz" >> $OSPLOG 2>&1
echo 20 | dialog --title "Installing Nginx-Core" --gauge "Downloading Required Modules" 10 70 0
sudo wget -q "http://www.zlib.net/zlib-$NGINX_ZLIB_VERSION.tar.gz" >> $OSPLOG 2>&1
echo 25 | dialog --title "Installing Nginx-Core" --gauge "Downloading Required Modules" 10 70 0
sudo wget -q "https://bitbucket.org/nginx-goodies/nginx-sticky-module-ng/get/master.tar.gz" >> $OSPLOG 2>&1
echo 30 | dialog --title "Installing Nginx-Core" --gauge "Decompressing Nginx Source and Modules" 10 70 0
sudo tar xfz nginx-$NGINX_BUILD_VERSION.tar.gz >> $OSPLOG 2>&1
#sudo unzip -qq -o v$NGINX_RTMP_VERSION.zip >> $OSPLOG 2>&1
sudo tar xfz v$NGINX_RTMP_VERSION.tar.gz >> $OSPLOG 2>&1
sudo tar xfz zlib-$NGINX_ZLIB_VERSION.tar.gz >> $OSPLOG 2>&1
sudo tar xfz master.tar.gz >> $OSPLOG 2>&1
# Apply Any Precompile Nginx-RTMP Patches
echo 31 | dialog --title "Installing Nginx-Core" --gauge "Applying Precompile Patches" 10 70 0
if cd nginx-http-flv-module-$NGINX_RTMP_VERSION
then
# sudo cp $DIR/installs/nginx-core/patches/mr-1158/1158.patch /tmp/nginx-http-flv-module-$NGINX_RTMP_VERSION/1158.patch >> $OSPLOG 2>&1
# sudo patch -s -p 1 < 1158.patch
cd ..
else
echo "Unable to Access Nginx-RTMP Module Source"
exit 1
fi
echo 35 | dialog --title "Installing Nginx-Core" --gauge "Building Nginx from Source" 10 70 0
if cd nginx-$NGINX_BUILD_VERSION
then
./configure --with-http_ssl_module --with-http_v2_module --with-http_auth_request_module --with-http_stub_status_module --add-module=../nginx-http-flv-module-$NGINX_RTMP_VERSION --add-module=../nginx-goodies-nginx-sticky-module-ng-08a395c66e42 --with-zlib=../zlib-$NGINX_ZLIB_VERSION --with-cc-opt="-Wimplicit-fallthrough=0" >> $OSPLOG 2>&1
echo 50 | dialog --title "Installing Nginx-Core" --gauge "Installing Nginx" 10 70 0
sudo make install >> $OSPLOG 2>&1
else
echo "Unable to Build Nginx! Aborting."
exit 1
fi
else
echo "Unable to Download Nginx due to missing /tmp! Aborting."
exit 1
fi
# Grab Configuration
echo 65 | dialog --title "Installing Nginx-Core" --gauge "Copying Nginx Config Files" 10 70 0
sudo cp $DIR/installs/nginx-core/nginx.conf /usr/local/nginx/conf/ >> $OSPLOG 2>&1
sudo cp $DIR/installs/nginx-core/mime.types /usr/local/nginx/conf/ >> $OSPLOG 2>&1
sudo mkdir /usr/local/nginx/conf/locations >> $OSPLOG 2>&1
sudo mkdir /usr/local/nginx/conf/upstream >> $OSPLOG 2>&1
sudo mkdir /usr/local/nginx/conf/servers >> $OSPLOG 2>&1
sudo mkdir /usr/local/nginx/conf/services >> $OSPLOG 2>&1
sudo mkdir /usr/local/nginx/conf/custom >> $OSPLOG 2>&1
sudo cp $DIR/installs/nginx-core/osp-custom-servers.conf /usr/local/nginx/conf/custom/ >> $OSPLOG 2>&1
sudo cp $DIR/installs/nginx-core/osp-custom-serversredirect.conf /usr/local/nginx/conf/custom/ >> $OSPLOG 2>&1
# Enable SystemD
echo 75 | dialog --title "Installing Nginx-Core" --gauge "Setting up Nginx SystemD" 10 70 0
sudo cp $DIR/installs/nginx-core/nginx-osp.service /etc/systemd/system/nginx-osp.service >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable nginx-osp.service >> $OSPLOG 2>&1
install_ffmpeg
# Create HLS directory
echo 80 | dialog --title "Installing Nginx-Core" --gauge "Creating OSP Video Directories" 10 70 0
sudo mkdir -p "$web_root" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/live" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/videos" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/live-adapt" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/stream-thumb" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/keys" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/keys-adapt" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/pending" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/ingest" >> $OSPLOG 2>&1
s3DriveMount=$(mount | grep -iE "/var/www/videos" | grep s3fs | wc -l)
if test $s3DriveMount -eq 0
then
echo 90 | dialog --title "Installing Nginx-Core" --gauge "Setting Ownership of OSP Video Directories" 10 70 0
sudo chown -R "$http_user:$http_user" "$web_root" >> $OSPLOG 2>&1
fi
# Start Nginx
echo 100 | dialog --title "Installing Nginx-Core" --gauge "Starting Nginx" 10 70 0
sudo systemctl start nginx-osp.service >> $OSPLOG 2>&1
}
install_osp_rtmp_venv() {
cd /opt/osp-rtmp
sudo python3 -m venv venv >> $OSPLOG 2>&1
source venv/bin/activate >> $OSPLOG 2>&1
pip3 uninstall -r $DIR/installs/osp-rtmp/setup/remove_requirements.txt -y >> $OSPLOG 2>&1
pip3 install -r $DIR/installs/osp-rtmp/setup/requirements.txt >> $OSPLOG 2>&1
deactivate
}
install_osp_rtmp() {
echo 10 | dialog --title "Installing OSP-RTMP" --gauge "Intalling Prereqs" 10 70 0
install_prereq
echo 20 | dialog --title "Installing OSP-RTMP" --gauge "Setting Up Nginx Configs" 10 70 0
sudo cp $DIR/installs/osp-rtmp/setup/nginx/servers/*.conf /usr/local/nginx/conf/servers >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-rtmp/setup/nginx/services/*.conf /usr/local/nginx/conf/services >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-rtmp/setup/nginx/custom/osp-rtmp-* /usr/local/nginx/conf/custom >> $OSPLOG 2>&1
# Create OSP-RTMP Folder
echo 30 | dialog --title "Installing OSP-RTMP" --gauge "Create OSP-RTMP Folder" 10 70 0
sudo mkdir /opt/osp-rtmp >> $OSPLOG 2>&1
echo 40 | dialog --title "Installing OSP-RTMP" --gauge "Installing Requirements.txt" 10 70 0
install_osp_rtmp_venv
# Copy OSP-RTMP Data
echo 50 | dialog --title "Installing OSP-RTMP" --gauge "Installing OSP-RTMP Application" 10 70 0
sudo cp -R $DIR/installs/osp-rtmp/* /opt/osp-rtmp >> $OSPLOG 2>&1
sudo mkdir /opt/osp-rtmp/rtmpsocket >> $OSPLOG 2>&1
sudo chown -R www-data:www-data /opt/osp-rtmp/rtmpsocket >> $OSPLOG 2>&1
# Log Files Access Fix
sudo touch /opt/osp-rtmp/logs/access.log
sudo touch /opt/osp-rtmp/logs/error.log
sudo chown -R $http_user:$http_user /opt/osp-rtmp/logs
echo 75 | dialog --title "Installing OSP-RTMP" --gauge "Installing SystemD File" 10 70 0
sudo cp $DIR/installs/osp-rtmp/setup/gunicorn/osp-rtmp.service /etc/systemd/system/osp-rtmp.service >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp-rtmp.service >> $OSPLOG 2>&1
}
install_redis() {
# Install Redis
echo 50 | dialog --title "Installing Redis" --gauge "Installing Redis Server" 10 70 0
update_and_install_safely redis >> $OSPLOG 2>&1
echo 25 | dialog --title "Installing Redis" --gauge "Configuring Redis" 10 70 0
sudo sed -i 's/appendfsync everysec/appendfsync no/' /etc/redis/redis.conf >> $OSPLOG 2>&1
}
install_osp_proxy_venv() {
cd /opt/osp-proxy
sudo python3 -m venv venv >> $OSPLOG 2>&1
source venv/bin/activate >> $OSPLOG 2>&1
pip3 install -r $DIR/installs/osp-proxy/setup/requirements.txt >> $OSPLOG 2>&1
deactivate
}
install_osp_proxy() {
user_input=$(\
dialog --nocancel --title "Setting up OSP-Proxy" \
--inputbox "Enter your OSP-Core Protocol and FQDN (ex:https://osp.example.com):" 8 80 \
3>&1 1>&2 2>&3 3>&-)
# Grab Configuration
echo 10 | dialog --title "Installing OSP-Proxy" --gauge "Installing Configuration Files" 10 70 0
sudo cp $DIR/installs/osp-proxy/setup/nginx/locations/osp-proxy-locations.conf /usr/local/nginx/conf/locations >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-proxy/setup/nginx/servers/osp-proxy-servers.conf /usr/local/nginx/conf/servers >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-proxy/setup/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-proxy/setup/nginx/cors.conf /usr/local/nginx/conf/cors.conf >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-proxy/setup/nginx/custom/osp-proxy-custom* /usr/local/nginx/conf/custom/ >> $OSPLOG 2>&1
# Install OSP Proxy
echo 25 | dialog --title "Installing OSP-Proxy" --gauge "Installing OSP-Proxy Application Prereqs" 10 70 0
sudo mkdir /opt/osp-proxy >> $OSPLOG 2>&1
sudo cp -R $DIR/installs/osp-proxy/* /opt/osp-proxy >> $OSPLOG 2>&1
sudo cp /opt/osp-proxy/conf/config.py.dist /opt/osp-proxy/conf/config.py >> $OSPLOG 2>&1
sudo chmod +x /opt/osp-proxy/updateUpstream.sh >> $OSPLOG 2>&1
sudo mkdir -p /var/cache/nginx/osp_cache_temp >> $OSPLOG 2>&1
# Setup OSP Proxy Directory
echo 50 | dialog --title "Installing OSP-Proxy" --gauge "Installing OSP-Proxy Application Prereqs" 10 70 0
install_osp_proxy_venv
# Setup Configuration with IP
echo 75 | dialog --title "Installing OSP-Proxy" --gauge "Installing Configuration Files" 10 70 0
sed -i "s|#CHANGEMETOOSPCORE|$user_input|g" /opt/osp-proxy/conf/config.py >> $OSPLOG 2>&1
# Setup Install OSP-Proxy Service
echo 85 | dialog --title "Installing OSP-Proxy" --gauge "Installing Configuration Files" 10 70 0
sudo cp $DIR/installs/osp-proxy/setup/gunicorn/osp-proxy.service /etc/systemd/system/osp-proxy.service >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp-proxy.service >> $OSPLOG 2>&1
sudo systemctl start osp-proxy.service >> $OSPLOG 2>&1
# Enable OSP Upstream Updater
echo 90 | dialog --title "Installing OSP-Proxy" --gauge "Installing OSP-Proxy Upstream Updater" 10 70 0
cronjob="*/5 * * * * /opt/osp-proxy/updateUpstream.sh"
(sudo crontab -u root -l;sudo echo "$cronjob" ) | sudo crontab -u root -
sudo systemctl restart cron >> $OSPLOG 2>&1
}
install_osp_edge () {
user_input=$(\
dialog --nocancel --title "Setting up OSP-Edge" \
--inputbox "Enter your OSP-RTMP IP Address. Use Commas to Separate Multiple Values (ex: 192.168.0.4,192.168.8.5):" 8 80 \
3>&1 1>&2 2>&3 3>&-)
IFS="," read -a rtmpArray <<< $user_input
rtmpString=""
for i in "${rtmpArray[@]}"
do
rtmpString+="allow publish $i;\n"
done
core_input=$(\
dialog --nocancel --title "Setting up OSP-Edge" \
--inputbox "Enter your OSP-Core IP Address. Use Commas to Separate Multiple Values (ex: 192.168.0.4,192.168.8.5):" 8 80 \
3>&1 1>&2 2>&3 3>&-)
IFS="," read -a coreArray <<< $core_input
coreString=""
for i in "${coreArray[@]}"
do
coreString+="allow $i;\n"
done
# Grab Configuration
echo 10 | dialog --title "Installing OSP-Edge" --gauge "Installing Configuration Files" 10 70 0
sudo cp $DIR/installs/osp-edge/setup/nginx/locations/osp-edge-redirects.conf /usr/local/nginx/conf/locations >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-edge/setup/nginx/servers/osp-edge-servers.conf /usr/local/nginx/conf/servers >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-edge/setup/nginx/services/osp-edge-rtmp.conf /usr/local/nginx/conf/services >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-edge/setup/nginx/custom/osp-edge-custom* /usr/local/nginx/conf/custom >> $OSPLOG 2>&1
# Setup Configuration with IP
echo 40 | dialog --title "Installing OSP-Edge" --gauge "Installing Configuration Files" 10 70 0
sed -i "s/#ALLOWRTMP/$rtmpString/g" /usr/local/nginx/conf/custom/osp-edge-custom-allowedpub.conf >> $OSPLOG 2>&1
sed -i "s/#ALLOWCORE/$coreString/g" /usr/local/nginx/conf/custom/osp-edge-custom-nginxstat.conf >> $OSPLOG 2>&1
# Make OSP-Edge Directory for RTMP sockets
echo 60 | dialog --title "Installing OSP-Edge" --gauge "Creating OSP-Edge Directories" 10 70 0
sudo mkdir /opt/osp-edge >> $OSPLOG 2>&1
sudo mkdir /opt/osp-edge/rtmpsocket >> $OSPLOG 2>&1
sudo chown -R www-data:www-data /opt/osp-edge/rtmpsocket >> $OSPLOG 2>&1
# Create HLS directory
sudo mkdir -p /var/www >> $OSPLOG 2>&1
sudo mkdir -p /var/www/live >> $OSPLOG 2>&1
sudo mkdir -p /var/www/live-adapt >> $OSPLOG 2>&1
sudo chown -R www-data:www-data /var/www >> $OSPLOG 2>&1
echo 75 | dialog --title "Installing OSP-Edge" --gauge "Setting up FFMPEG" 10 70 0
# Start Nginx
echo 90 | dialog --title "Installing OSP-Edge" --gauge "Restarting Nginx Core" 10 70 0
sudo systemctl restart nginx-osp.service >> $OSPLOG 2>&1
}
install_ejabberd_venv() {
sudo python3 -m venv /opt/ejabberd/venv >> $OSPLOG 2>&1
/opt/ejabberd/venv/bin/pip3 install requests >> $OSPLOG 2>&1
}
install_ejabberd() {
echo 5 | dialog --title "Installing ejabberd" --gauge "Installing Prereqs" 10 70 0
sudo mkdir -p /opt/ejabberd
install_ejabberd_venv
# Install ejabberd
echo 10 | dialog --title "Installing ejabberd" --gauge "Downloading ejabberd" 10 70 0
sudo wget -O "/tmp/ejabberd-$EJABBERD_VERSION-linux-x64.run" "https://github.com/processone/ejabberd/releases/download/$EJABBERD_VERSION/ejabberd-$EJABBERD_VERSION-1-linux-x64.run" >> $OSPLOG 2>&1
echo 20 | dialog --title "Installing ejabberd" --gauge "Installing ejabberd" 10 70 0
sudo chmod +x /tmp/ejabberd-$EJABBERD_VERSION-linux-x64.run >> $OSPLOG 2>&1
sudo yes | /tmp/ejabberd-$EJABBERD_VERSION-linux-x64.run --quiet >> $OSPLOG 2>&1
sudo ln -s /opt/ejabberd /usr/local/ejabberd >> $OSPLOG 2>&1
echo 35 | dialog --title "Installing ejabberd" --gauge "Installing Configuration Files" 10 70 0
mkdir /opt/ejabberd/conf >> $OSPLOG 2>&1
sudo cp $DIR/installs/ejabberd/setup/ejabberd.yml /opt/ejabberd/conf/ejabberd.yml >> $OSPLOG 2>&1
sudo cp $DIR/installs/ejabberd/setup/inetrc /opt/ejabberd/conf/inetrc >> $OSPLOG 2>&1
sudo cp /opt/ejabberd-$EJABBERD_VERSION/bin/ejabberd.service /etc/systemd/system/ejabberd.service >> $OSPLOG 2>&1
# If we don't have the site address, prompt the user
#if [ -z "$OSP_EJABBERD_SITE_ADDRESS" ]; then
# user_input=$(\
# dialog --nocancel --title "Setting up eJabberd" \
# --inputbox "Enter your Site Address (Must match FQDN without http):" 8 80 \
# 3>&1 1>&2 2>&3 3>&-)
#else
# user_input="$OSP_EJABBERD_SITE_ADDRESS"
#fi
# Hardcoding to osp.internal domain to eliminate osp ejabberd domain issues
user_input="osp.internal"
echo 65 | dialog --title "Installing ejabberd" --gauge "Setting Up ejabberd Configuration" 10 70 0
sudo sed -i "s/CHANGEME/$user_input/g" /opt/ejabberd/conf/ejabberd.yml >> $OSPLOG 2>&1
echo 85 | dialog --title "Installing ejabberd" --gauge "Starting ejabberd" 10 70 0
sudo cp $DIR/installs/ejabberd/setup/auth_osp.py /opt/ejabberd/conf/auth_osp.py >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable ejabberd >> $OSPLOG 2>&1
sudo systemctl start ejabberd >> $OSPLOG 2>&1
echo 95 | dialog --title "Installing ejabberd" --gauge "Installing Nginx File" 10 70 0
sudo cp $DIR/installs/ejabberd/setup/nginx/locations/ejabberd.conf /usr/local/nginx/conf/locations/ >> $OSPLOG 2>&1
sudo chown -R ejabberd:ejabberd /opt/ejabberd
}
generate_ejabberd_admin() {
confirm_service_is_running ejabberd >> $OSPLOG 2>&1
sudo /opt/ejabberd-23.04/bin/ejabberdctl unregister admin localhost
ADMINPASS=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 32 | head -n 1 )
sudo sed -i "s/CHANGE_EJABBERD_PASS/$ADMINPASS/" /opt/osp/conf/config.py >> $OSPLOG 2>&1
user_input="osp.internal"
sudo sed -i "s/CHANGEME/$user_input/g" /opt/ejabberd/conf/ejabberd.yml >> $OSPLOG 2>&1
sudo /opt/ejabberd-$EJABBERD_VERSION/bin/ejabberdctl register admin localhost $ADMINPASS >> $OSPLOG 2>&1
sudo /opt/ejabberd-$EJABBERD_VERSION/bin/ejabberdctl change_password admin localhost $ADMINPASS >> $OSPLOG 2>&1
sudo systemctl restart ejabberd
}
install_osp_venv() {
cd /opt/osp
sudo python3 -m venv venv >> $OSPLOG 2>&1
source venv/bin/activate >> $OSPLOG 2>&1
pip3 uninstall -r $DIR/setup/remove_requirements.txt -y >> $OSPLOG 2>&1
pip3 install -r $DIR/setup/requirements.txt >> $OSPLOG 2>&1
deactivate
}
install_osp() {
cwd=$PWD
echo "Starting OSP Install" >> $OSPLOG 2>&1
echo 0 | dialog --title "Installing OSP" --gauge "Installing Linux Dependencies" 10 70 0
install_prereq
# Setup OSP Directory
echo 20 | dialog --title "Installing OSP" --gauge "Setting up OSP Directory" 10 70 0
mkdir -p /opt/osp >> $OSPLOG 2>&1
sudo cp -rf -R $DIR/* /opt/osp >> $OSPLOG 2>&1
sudo cp -rf -R $DIR/.git /opt/osp >> $OSPLOG 2>&1
echo 35 | dialog --title "Installing OSP" --gauge "Setting up OSP Virtual Environment" 10 70 0
install_osp_venv
echo 50 | dialog --title "Installing OSP" --gauge "Setting up Gunicorn Systemd" 10 70 0
if cd $DIR/setup/gunicorn
then
sudo cp $DIR/setup/gunicorn/osp.target /etc/systemd/system/ >> $OSPLOG 2>&1
sudo cp $DIR/setup/gunicorn/osp-worker@.service /etc/systemd/system/ >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp.target >> $OSPLOG 2>&1
else
echo "Unable to find downloaded Gunicorn config directory. Aborting." >> $OSPLOG 2>&1
exit 1
fi
sudo cp $DIR/setup/nginx/locations/* /usr/local/nginx/conf/locations >> $OSPLOG 2>&1
sudo cp $DIR/setup/nginx/upstream/osp.conf /usr/local/nginx/conf/upstream >> $OSPLOG 2>&1
sudo cp $DIR/setup/nginx/upstream/osp-edge.conf /usr/local/nginx/conf/upstream >> $OSPLOG 2>&1
# Create HLS directory
echo 60 | dialog --title "Installing OSP" --gauge "Creating OSP Video Directories" 10 70 0
sudo mkdir -p "$web_root" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/live" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/videos" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/images" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/images/stickers" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/live-adapt" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/stream-thumb" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/keys" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/keys-adapt" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/pending" >> $OSPLOG 2>&1
sudo mkdir -p "$web_root/ingest" >> $OSPLOG 2>&1
s3DriveMount=$(mount | grep -iE "/var/www/videos" | grep s3fs | wc -l)
if test $s3DriveMount -eq 0
then
echo 70 | dialog --title "Installing OSP" --gauge "Setting Ownership of OSP Video Directories" 10 70 0
sudo chown -R "$http_user:$http_user" "$web_root" >> $OSPLOG 2>&1
fi
sudo chown -R "$http_user:$http_user" /opt/osp >> $OSPLOG 2>&1
sudo chown -R "$http_user:$http_user" /opt/osp/.git >> $OSPLOG 2>&1
# Copy Initial Favicons
sudo cp $DIR/static/android-chrome-192x192.png $web_root/images/ >> $OSPLOG 2>&1
sudo cp $DIR/static/android-chrome-512x512.png $web_root/images/ >> $OSPLOG 2>&1
sudo cp $DIR/static/apple-touch-icon.png $web_root/images/ >> $OSPLOG 2>&1
sudo cp $DIR/static/favicon.ico $web_root/images/ >> $OSPLOG 2>&1
sudo cp $DIR/static/favicon-16x16.png $web_root/images/ >> $OSPLOG 2>&1
sudo cp $DIR/static/favicon-32x32.png $web_root/images/ >> $OSPLOG 2>&1
install_celery
# Setup Logrotate
echo 90 | dialog --title "Installing OSP" --gauge "Setting Up Log Rotation" 10 70 0
if cd /etc/logrotate.d
then
sudo cp /opt/osp/setup/logrotate/* /etc/logrotate.d/ >> $OSPLOG 2>&1
else
update_and_install_safely logrorate >> $OSPLOG 2>&1
if cd /etc/logrotate.d
then
sudo cp /opt/osp/setup/logrotate/* /etc/logrotate.d/ >> $OSPLOG 2>&1
else
echo "Unable to setup logrotate" >> $OSPLOG 2>&1
fi
fi
}
install_celery() {
# Setup Celery
echo 50 | dialog --title "Installing OSP" --gauge "Setting Up Celery" 10 70 0
sudo mkdir /var/log/celery >> $OSPLOG 2>&1
sudo chown -R www-data:www-data /var/log/celery >> $OSPLOG 2>&1
sudo cp -rf $DIR/setup/celery/osp-celery.service /etc/systemd/system >> $OSPLOG 2>&1
sudo cp -rf $DIR/setup/celery/celery /etc/default/celery >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp-celery >> $OSPLOG 2>&1
}
install_celery_beat() {
echo 50 | dialog --title "Installing OSP" --gauge "Setting Up Celery Beat" 10 70 0
sudo cp -rf $DIR/setup/celery/osp-celery-beat.service /etc/systemd/system >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp-celery-beat >> $OSPLOG 2>&1
}
install_celery_flower() {
echo 50 | dialog --title "Installing OSP" --gauge "Setting Up Celery Flower" 10 70 0
sudo pip3 install flower >> $OSPLOG 2>&1
sudo cp -rf $DIR/setup/celery/osp-celery-flower.service /etc/systemd/system >> $OSPLOG 2>&1
sudo cp -rf $DIR/setup/celery/celery-flower /etc/default/celery-flower >> $OSPLOG 2>&1
ADMINPASS=$( cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 16 | head -n 1 )
sed -i "s/CHANGEME/$ADMINPASS/" /etc/default/celery-flower >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp-celery-flower >> $OSPLOG 2>&1
result=$(echo "OSP-Celery-Flower Install Completed! \n\nVisit http://FQDN:5572 to configure\n\nUsername: Admin \nPassword: $ADMINPASS \n\nYou can change the password by editing the /etc/default/celery-flower file")
display_result "Install OSP-Celery-Flower"
}
upgrade_celery() {
install_prereq
install_celery
sudo systemctl restart osp-celery >> $OSPLOG 2>&1
}
upgrade_celery_beat() {
install_prereq
install_celery_beat
sudo systemctl restart osp-celery-beat >> $OSPLOG 2>&1
}
upgrade_osp() {
UPGRADELOG="/opt/osp/logs/upgrade.log"
install_prereq
if cd /opt/osp
then
echo 0 | dialog --title "Upgrading OSP" --gauge "Pulling Git Repo" 10 70 0
echo 10 | dialog --title "Upgrading OSP" --gauge "Setting /opt/osp Ownership" 10 70 0
sudo chown -R $http_user:$http_user /opt/osp >> $UPGRADELOG 2>&1
echo 25 | dialog --title "Upgrading OSP" --gauge "Stopping OSP" 10 70 0
sudo systemctl stop osp.target >> $UPGRADELOG 2>&1
echo 30 | dialog --title "Upgrading OSP" --gauge "Stopping Nginx" 10 70 0
sudo systemctl stop nginx-osp >> $UPGRADELOG 2>&1
echo 35 | dialog --title "Upgrading OSP" --gauge "Installing Python Dependencies" 10 70 0
install_osp_venv
echo 45 | dialog --title "Upgrading OSP" --gauge "Upgrading Nginx-RTMP Configurations" 10 70 0
sudo cp -rf /opt/osp/setup/nginx/locations/* /usr/local/nginx/conf/locations >> $OSPLOG 2>&1
sudo cp -rf /opt/osp/setup/nginx/upstream/osp.conf /usr/local/nginx/conf/upstream >> $OSPLOG 2>&1
sudo cp -rf /opt/osp/setup/nginx/upstream/osp-edge.conf /usr/local/nginx/conf/upstream >> $OSPLOG 2>&1
sudo cp $DIR/setup/gunicorn/osp.target /etc/systemd/system/ >> $OSPLOG 2>&1
sudo cp $DIR/setup/gunicorn/osp-worker@.service /etc/systemd/system/ >> $OSPLOG 2>&1
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp.target >> $OSPLOG 2>&1
echo 50 | dialog --title "Upgrading OSP" --gauge "Upgrading Database" 10 70 0
echo 65 | dialog --title "Upgrading OSP" --gauge "Upgrading Database" 10 70 0
source venv/bin/activate >> $OSPLOG 2>&1
flask db upgrade >> $OSPLOG 2>&1
deactivate >> $OSPLOG 2>&1
echo 75 | dialog --title "Upgrading OSP" --gauge "Starting OSP" 10 70 0
sudo systemctl start osp.target >> $UPGRADELOG 2>&1
echo 90 | dialog --title "Upgrading OSP" --gauge "Starting Nginx" 10 70 0
sudo systemctl start nginx-osp >> $UPGRADELOG 2>&1
echo 100 | dialog --title "Upgrading OSP" --gauge "Complete" 10 70 0
else
echo "Error: /opt/osp Does not Exist" >> $OSPLOG 2>&1
fi
}
upgrade_proxy() {
install_prereq
sudo cp $DIR/installs/osp-proxy/setup/nginx/locations/*.conf /usr/local/nginx/conf/locations >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-proxy/setup/nginx/servers/*.conf /usr/local/nginx/conf/servers >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-proxy/setup/nginx/nginx.conf /usr/local/nginx/conf/nginx.conf >> $OSPLOG 2>&1
sudo cp -R $DIR/installs/osp-proxy/* /opt/osp-proxy >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-proxy/setup/gunicorn/osp-proxy.service /etc/systemd/system/osp-proxy.service >> $OSPLOG 2>&1
install_osp_proxy_venv
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp-proxy.service >> $OSPLOG 2>&1
}
upgrade_rtmp() {
install_prereq
sudo cp -rf $DIR/installs/osp-rtmp/setup/nginx/servers/*.conf /usr/local/nginx/conf/servers >> $OSPLOG 2>&1
sudo cp -rf $DIR/installs/osp-rtmp/setup/nginx/services/*.conf /usr/local/nginx/conf/services >> $OSPLOG 2>&1
sudo cp -R $DIR/installs/osp-rtmp/* /opt/osp-rtmp >> $OSPLOG 2>&1
sudo cp $DIR/installs/osp-rtmp/setup/gunicorn/osp-rtmp.service /etc/systemd/system/osp-rtmp.service >> $OSPLOG 2>&1
install_osp_rtmp_venv
sudo systemctl daemon-reload >> $OSPLOG 2>&1
sudo systemctl enable osp-rtmp.service >> $OSPLOG 2>&1
}
upgrade_ejabberd() {
sudo cp -rf $DIR/installs/ejabberd/setup/auth_osp.py /opt/ejabberd/conf/auth_osp.py >> $OSPLOG 2>&1
sudo cp -rf $DIR/installs/ejabberd/setup/nginx/locations/ejabberd.conf /usr/local/nginx/conf/locations/ >> $OSPLOG 2>&1
if [[ ! -d /opt/ejabberd/venv ]]; then
install_ejabberd_venv
fi
sed -i 's/^extauth_program:.*$/extauth_program: "\/opt\/ejabberd\/venv\/bin\/python3 \/opt\/ejabberd\/conf\/auth_osp.py"/' /opt/ejabberd/conf/ejabberd.yml
}
upgrade_edge() {
install_prereq
sudo cp -rf $DIR/installs/osp-edge/setup/nginx/services/osp-edge-rtmp.conf /usr/local/nginx/conf/services/ >> $OSPLOG 2>&1
sudo cp -rf $DIR/installs/osp-edge/setup/nginx/locations/osp-edge-redirects.conf /usr/local/nginx/conf/locations/ >> $OSPLOG 2>&1
sudo cp -rf $DIR/installs/osp-edge/setup/nginx/servers/osp-edge-servers.conf /usr/local/nginx/conf/servers/ >> $OSPLOG 2>&1
}
upgrade_nginxcore() {
sudo cp -rf $DIR/installs/nginx-core/nginx.conf /usr/local/nginx/conf >> $OSPLOG 2>&1
}
config_overwrite_warning_dialog() {
while true; do
exec 3>&1
dialog \
--backtitle "Open Streaming Platform" \
--title "SINGLE-SERVER INSTALL WARNING" \
--clear \
--yesno "If you have existing local installations of Nginx and MariaDB, they will be replaced/modified during the OSP single-server installation.\n\nDo you want to proceed?" $HEIGHT $WIDTH \
2>&1 1>&3
local exit_status=$?
exec 3>&-
case $exit_status in
$DIALOG_CANCEL)
clear
echo "Program terminated."
exit
;;
$DIALOG_ESC)
clear
echo "Program aborted." >&2
exit 1
;;
esac
return $exit_status
done
}
config_overwrite_warning_cli() {
local read_input=""
echo "If you have existing local installations of Nginx and MariaDB,"
echo "they will be replaced/modified during the OSP single-server installation."
echo ""
read -rp "Do you want to proceed? (Enter 'YES' to proceed, or anything else to abort) " read_input
if [[ "$read_input" != "YES" ]]; then
echo "Program terminated."
exit
fi
return
}
##########################################################
# Menu Options
##########################################################
install_menu() {
while true; do
exec 3>&1
selection=$(dialog \
--backtitle "Open Streaming Platform - $VERSION" \
--title "Menu" \
--clear \
--cancel-label "Exit" \
--menu "Please select:" $HEIGHT $WIDTH 7 \
"1" "Install OSP - Single Server" \
"2" "Install OSP-Core" \
"3" "Install OSP-RTMP" \
"4" "Install OSP-Edge" \
"5" "Install OSP-Proxy" \
"6" "Install eJabberd" \
"7" "Install Celery Beat" \
"8" "Install Celery Flower" \
2>&1 1>&3)
exit_status=$?
exec 3>&-
case $exit_status in
$DIALOG_CANCEL)
clear
echo "Program terminated."
exit
;;
$DIALOG_ESC)
clear
echo "Program aborted." >&2
exit 1
;;
esac
case $selection in
0 )
clear
echo "Program terminated."
;;
1 )
config_overwrite_warning_dialog
echo 10 | dialog --title "Installing OSP" --gauge "Installing Nginx Core" 10 70 0
install_nginx_core
echo 20 | dialog --title "Installing OSP" --gauge "Installing Redis" 10 70 0
install_redis
echo 30 | dialog --title "Installing OSP" --gauge "Installing ejabberd" 10 70 0
install_ejabberd
echo 40 | dialog --title "Installing OSP" --gauge "Installing OSP-RTMP" 10 70 0
install_osp_rtmp
echo 60 | dialog --title "Installing OSP" --gauge "Installing OSP Core" 10 70 0
install_osp
echo 65 | dialog --title "Installing OSP" --gauge "Setting Up Configuration Files" 10 70 0
sudo cp /opt/osp-rtmp/conf/config.py.dist /opt/osp-rtmp/conf/config.py >> $OSPLOG 2>&1
sudo cp /opt/osp/conf/config.py.dist /opt/osp/conf/config.py >> $OSPLOG 2>&1
config_smtp
echo 70 | dialog --title "Installing OSP" --gauge "Setting up Celery" 10 70 0
install_celery
install_celery_beat
echo 75 | dialog --title "Installing OSP" --gauge "Setting up ejabberd" 10 70 0
generate_ejabberd_admin
echo 80 | dialog --title "Installing OSP" --gauge "Installing MySQL" 10 70 0
install_mysql
echo 85 | dialog --title "Installing OSP" --gauge "Restarting Nginx Core" 10 70 0
sudo systemctl restart nginx-osp >> $OSPLOG 2>&1
echo 90 | dialog --title "Installing OSP" --gauge "Starting OSP Core" 10 70 0
sudo systemctl start osp.target >> $OSPLOG 2>&1
upgrade_db
echo 95 | dialog --title "Installing OSP" --gauge "Starting OSP-RTMP" 10 70 0
sudo systemctl start osp-rtmp >> $OSPLOG 2>&1
echo 95 | dialog --title "Installing OSP" --gauge "Starting Celery" 10 70 0
sudo systemctl start osp-celery >> $OSPLOG 2>&1
sudo systemctl start osp-celery-beat >> $OSPLOG 2>&1
result=$(echo "OSP Install Completed! \n\nVisit http://FQDN to configure\n\nInstall Log can be found at ${OSPLOG}")
display_result "Install OSP"
;;
2 )
echo 30 | dialog --title "Installing OSP" --gauge "Installing Nginx Core" 10 70 0
install_nginx_core
echo 60 | dialog --title "Installing OSP" --gauge "Installing OSP Core" 10 70 0
install_osp
echo 70 | dialog --title "Installing OSP" --gauge "Setting Celery" 10 70 0
install_celery
echo 90 | dialog --title "Installing OSP" --gauge "Restarting Nginx Core" 10 70 0
sudo systemctl restart nginx-osp >> $OSPLOG 2>&1
;;
3 )
echo 30 | dialog --title "Installing OSP" --gauge "Installing Nginx Core" 10 70 0
install_nginx_core
echo 60 | dialog --title "Installing OSP" --gauge "Installing OSP-RTMP" 10 70 0
install_osp_rtmp
echo 90 | dialog --title "Installing OSP" --gauge "Restarting Nginx Core" 10 70 0
sudo systemctl restart nginx-osp >> $OSPLOG 2>&1
;;
4 )
echo 30 | dialog --title "Installing OSP" --gauge "Installing Nginx Core" 10 70 0
install_nginx_core
echo 60 | dialog --title "Installing OSP" --gauge "Installing OSP-EDGE" 10 70 0
install_osp_edge
echo 90 | dialog --title "Installing OSP" --gauge "Restarting Nginx Core" 10 70 0
sudo systemctl restart nginx-osp >> $OSPLOG 2>&1
;;
5 )
echo 30 | dialog --title "Installing OSP" --gauge "Installing Nginx Core" 10 70 0
install_nginx_core
echo 45 | dialog --title "Installing OSP" --gauge "Installing Redis" 10 70 0
install_redis
echo 60 | dialog --title "Installing OSP" --gauge "Installing OSP-Proxy" 10 70 0
install_osp_proxy
echo 90 | dialog --title "Installing OSP" --gauge "Restarting Nginx Core" 10 70 0
sudo systemctl restart nginx-osp >> $OSPLOG 2>&1
;;
6 )
echo 30 | dialog --title "Installing OSP" --gauge "Installing Nginx Core" 10 70 0
install_nginx_core
echo 60 | dialog --title "Installing OSP" --gauge "Installing ejabberd" 10 70 0
install_ejabberd
echo 90 | dialog --title "Installing OSP" --gauge "Restarting Nginx Core" 10 70 0
sudo systemctl restart nginx-osp >> $OSPLOG 2>&1
;;
7 )
echo 50 | dialog --title "Installing OSP" --gauge "Setting up Celery Beat"
install_celery_beat
echo 75 | dialog --title "Installing OSP" --gauge "Starting Celery Beat" 10 70 0
sudo systemctl start osp-celery
sudo systemctl start osp-celery-beat
;;
8 )
echo 50 | dialog --title "Installing OSP" --gauge "Setting up Celery Flower"
install_celery_flower
echo 75 | dialog --title "Installing OSP" --gauge "Starting Celery Flower" 10 70 0
sudo systemctl start osp-celery
sudo systemctl start osp-celery-beat
esac
done
}
upgrade_menu() {
while true; do
exec 3>&1
selection=$(dialog \
--backtitle "Open Streaming Platform - $VERSION" \
--title "Menu" \