-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinstall.sh
executable file
·1354 lines (1163 loc) · 31 KB
/
install.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
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
##############################################################################################################
# Configuration
#set -o errexit # Exit on error
#set -o errtrace # Exit on error inside functions
#set -o xtrace # Turn on traces, disabled by default
APP_NAME="ConfigInterfaceTool"
APP_FILE="configinterfacetool"
APP_DESCRIPTION="Easy, minimalistic and simple interface for device/application administration and configuration."
APP_VERSION="0.0.1"
APP_COPYRIGHT="(c) 2022 Sebastian Obele / obele.eu"
DOWNLOAD_URL_SERVER="https://raw.githubusercontent.com/SebastianObi/ConfigInterfaceTool/main/releases/"
DOWNLOAD_URL_FILE_RELEASE="release_full.tar.gz"
DOWNLOAD_URL_FILE_DEV="dev_full.tar.gz"
DOWNLOAD_URL=""
DOWNLOAD_CMD="install.sh"
DOWNLOAD_CMD_ARGS="-s"
DOWNLOAD_CMD_ARGS_USER=""
DEFAULT_SSL="/C=DE/ST=NRW/L=Duesseldorf/O=IT/CN=configinterfacetool.local"
DEFAULT_USER="admin"
DEFAULT_PASSWORD="password"
##############################################################################################################
# Setup/Start
_run() {
_header
_start_prompt
_root_check
_pipe_check
_linux_check
_download_prompt
_file_delete
_file_copy
_file_permission_owner
_file_permission_rights
_addon_prompt
_deps_system_update
_deps_system_check
_python_check
_deps_python_check
_deps_file_check
_config_prompt
_webserver_prompt
_webproxy_prompt
_password_prompt
_user_prompt
_service_prompt
_footer
_footer_next_steps
}
_run_unattended() {
_header
#_start_prompt
_start_unattended_prompt
_root_check
_pipe_check
_linux_check
#_download_prompt
_download_check
_file_delete
_file_copy
_file_permission_owner
_file_permission_rights
#_addon_prompt
_deps_system_update
_deps_system_check
_python_check
_deps_python_check
_deps_file_check
#_config_prompt
_config_install
#_webserver_prompt
_webserver_gunicorn
#_webproxy_prompt
_webproxy_nginx_install
_webproxy_nginx_config_ssl
#_webproxy_nginx_config_dh
_webproxy_nginx_config
_webserver_config
#_password_prompt
_password_default
#_user_prompt
#_service_prompt
_service_install
_service_addon_install
_service_start
_service_addon_start
_footer
_footer_next_steps
}
##############################################################################################################
# Variables
PATH_CURRENT=$(dirname $(realpath $0))
LOG_FILE="/tmp/${0##*/}-$(date +%Y%m%d-%H%M%S).log"
DEPS_SYSTEM=("python3-pip")
DEPS_PYTHON=("psutil")
DEPS_FILE=("$PATH_CURRENT/bin/main.py")
PERMISSION_OWNER=("$PATH_CURRENT/*")
PERMISSION_RIGHTS=("$PATH_CURRENT/bin/main*.py" "$PATH_CURRENT/*.sh" "$PATH_CURRENT/service_templates/*.sh" "$PATH_CURRENT/software_templates/*.sh" "$PATH_CURRENT/wizard_templates/*.sh")
FILE_DELETE=()
FILE_COPY_SOURCE=()
FILE_COPY_DEST=()
ADDON=0
ADDON_WEBPROXY=0
ADDON_START=0
##############################################################################################################
# Colors
RED='\033[0;31m'
LIGHT_RED='\033[1;31m'
GREEN='\033[0;32m'
LIGHT_GREEN='\033[1;32m'
YELLOW='\033[0;33m'
LIGHT_YELLOW='\033[1;33m'
BLUE='\033[0;34m'
LIGHT_BLUE='\033[1;34m'
PURPLE='\033[0;35m'
LIGHT_PURPLE='\033[1;35m'
WHITE='\033[0;37m'
BG_BLACK='\033[40m'
RESET='\033[0m'
NC='\033[0m'
##############################################################################################################
# Texts
OK="${GREEN}${BG_BLACK} ok.${RESET}"
FAIL="${RED}${BG_BLACK} failed!${RESET}"
NOK="${YELLOW}${BG_BLACK} nok.${RESET}"
##############################################################################################################
# Functions
_help() {
local help
read -r -d '' help << EOM
Usage: $0 [-hvud]
-h Displays this help
-s Download nothing/skip
-r Download release version
-d Download development version
-u Unattended installation
-v Outputs release info and exits
EOM
echo "$help"
exit 1
}
_version() {
echo -e "${APP_NAME} v${APP_VERSION} - ${APP_DESCRIPTION}"
exit 1
}
_divider() {
echo -e "..............................................................................."
}
_header() {
_divider
echo -e " Name: ${APP_NAME}"
echo -e " ${APP_DESCRIPTION}"
echo -e "Program File: ${0##*/}"
echo -e " Log File: ${LOG_FILE}"
echo -e " Version: ${APP_VERSION}"
echo -e " Copyright: ${APP_COPYRIGHT}"
_divider
}
_footer() {
_divider
echo -e "Finished!"
echo -e "You have successfully installed ${APP_NAME}."
_divider
}
_footer_next_steps() {
_divider
if [ $ADDON_START -eq 1 ]; then
echo -e "To proceed with further installation and configuration, please open a web browser with the following address (depending on your network ip address):"
else
echo -e "To proceed with further installation and configuration, please start the program first."
echo -e "Then open a web browser with the following address (depending on your network ip address):"
fi
if [ $ADDON_WEBPROXY -eq 1 ]; then
IP_PROTO="https://"
IP_PORT=""
else
IP_PROTO="http://"
IP_PORT=":8080"
fi
IPLIST=$(ip -4 -o addr show scope global | awk '{gsub(/\/.*/,"",$4); print $4}')
for s in $IPLIST; do
echo -e "${IP_PROTO}${s}${IP_PORT}"
done
echo -e ""
echo -e "Use the following login data:"
echo -e "Username: ${DEFAULT_USER}"
echo -e "Password: ${DEFAULT_PASSWORD}"
echo -e ""
echo -e "If a certificate warning is displayed, it can be ignored and confirmed. This is because the certificate was self-signed."
echo -e ""
echo -e "If the connection does not work then clear the browser cache and reopen the browser."
_divider
}
_panic() {
echo -e ""
echo -e "Aborted!"
echo -e "For more information check the logs in ${LOG_FILE}"
echo -e ""
echo -e "You can try to run the script again, this maybe solve the error."
exit 1
}
_start_prompt() {
echo -e ""
echo -e "This script installs and creates the basic configuration for ${APP_NAME}."
echo -e "The Quick Installer will guide you through a few easy steps."
echo -e ""
echo -e "The software is installed in the following folder: ${PATH_CURRENT}"
echo -e "It is recommended to create a new custom folder manually. "
echo -e ""
while true; do
read -p "Do you want to proceed? [y/n]" YN
case $YN in
[Yy]*)
echo -e ""
echo -e "Ok, proceeding..."
break;;
[Nn]*)
echo -e ""
echo -e "No, exiting now."
exit 1;;
*)
echo -e ""
echo -e "Please answer yes or no.";;
esac
done
}
_start_unattended_prompt() {
echo -e ""
echo -e "This script installs and creates the basic configuration for ${APP_NAME}."
echo -e ""
echo -e "Unattended mode without any user interaction! Using recommended default settings!"
}
_root_check() {
echo -ne "Checking root..."
if [[ $EUID -ne 0 ]]; then
echo -e "${FAIL}"
echo -e "You need to run this script as root (UID=0)"
echo -e "To change the user to root enter the command: sudo su"
exit 1
fi
echo -e "${OK}"
}
_pipe_check() {
echo -ne "Checking script execution..."
if [ -p /dev/stdin ]; then
echo -e "${FAIL}"
echo -e "This script can't be piped!"
exit 1
fi
echo -e "${OK}"
}
_linux_check() {
echo -ne "Checking Linux..."
if type lsb_release >/dev/null 2>&1; then # linuxbase.org
OS=$(lsb_release -si)
RELEASE=$(lsb_release -sr)
CODENAME=$(lsb_release -sc)
DESC=$(lsb_release -sd)
MODEL=""
if [ -f /proc/device-tree/model ]; then
MODEL=$(tr -d '\0' < /proc/device-tree/model)
fi
elif [ -f /etc/os-release ]; then # freedesktop.org
. /etc/os-release
OS=$ID
RELEASE=$VERSION_ID
CODENAME=$VERSION_CODENAME
DESC=$PRETTY_NAME
MODEL=""
if [ -f /proc/device-tree/model ]; then
MODEL=$(tr -d '\0' < /proc/device-tree/model)
fi
else
echo -e "${FAIL}"
echo -e "Unsupported Linux distribution"
exit 1
fi
echo -e "${OK}"
}
_download_prompt() {
if [ "$DOWNLOAD_SKIP" = true ]; then
return
fi
if [ -n "${DOWNLOAD_URL}" ]; then
_download
return
fi
echo -e ""
echo -e "This installer can download the latest version from the internet and install it."
while true; do
read -p "Do you want to start download? [y/n]" YN
case $YN in
[Yy]*)
LOOP=1
while [ $LOOP -eq 1 ]; do
echo -e ""
echo -e "Which version do you want to use?"
options=("Release (Recommended for production use)" "Development")
select opt in "${options[@]}"; do
case $opt in
"Release"*)
echo -e ""
echo -e "Ok, downloading the latest release version."
DOWNLOAD_URL="${DOWNLOAD_URL_SERVER}${DOWNLOAD_URL_FILE_RELEASE}"
_download
LOOP=0
break;;
"Development"*)
echo -e ""
echo -e "Ok, downloading the latest development version."
DOWNLOAD_URL="${DOWNLOAD_URL_SERVER}${DOWNLOAD_URL_FILE_DEV}"
_download
LOOP=0
break;;
*)
echo -e ""
echo -e "Invalid choice!";;
esac
done
done
break;;
[Nn]*)
echo -e ""
echo -e "No, using existing version."
break;;
*)
echo -e ""
echo -e "Please answer yes or no.";;
esac
done
}
_download_check() {
if [ "$DOWNLOAD_SKIP" = true ]; then
return
fi
echo -ne "Checking Download URL..."
if [ -n "${DOWNLOAD_URL}" ]; then
echo -e "${OK}"
_download
else
echo -e "${NOK}"
fi
}
_download() {
echo -ne "Downloading..."
if [ -n "${DOWNLOAD_URL}" ]; then
if wget --no-check-certificate -q -O - "${DOWNLOAD_URL}" | tar -xz >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
file="${PATH_CURRENT}/${DOWNLOAD_CMD}"
echo -ne "Checking installer..."
if [ -n "${DOWNLOAD_CMD}" ] && [ -e "${file}" ]; then
echo -e "${OK}"
echo -ne "Changing installer permissions/right..."
if chmod +x "${file}" >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
echo -e "Starting installer..."
$file $DOWNLOAD_CMD_ARGS $DOWNLOAD_CMD_ARGS_USER
exit 0
else
echo -e "${NOK}"
_panic
fi
else
echo -e "${NOK}"
_panic
fi
else
echo -e "${NOK}"
_panic
fi
else
echo -e "${NOK}"
_panic
fi
}
_file_delete() {
echo -ne "Deleting files..."
for i in ${!FILE_DELETE[@]}; do
if ! rm -R -f "${FILE_DELETE[$i]}" >> "${LOG_FILE}" 2>&1; then
echo -e "${NOK}"
_panic
fi
done
echo -e "${OK}"
}
_file_copy() {
echo -ne "Copying files..."
for i in ${!FILE_COPY_SOURCE[@]}; do
if [ -d "${FILE_COPY_DEST[$i]}" ]; then
if ! cp -a "${FILE_COPY_SOURCE[$i]}" "${FILE_COPY_DEST[$i]}" >> "${LOG_FILE}" 2>&1; then
echo -e "${NOK}"
_panic
fi
fi
done
echo -e "${OK}"
}
_file_permission_owner() {
echo -ne "Changing file permissions/owner to '$(whoami)'..."
for file in ${PERMISSION_OWNER[@]}; do
if [ -e "${file}" ]; then
if ! chown -cR "$(whoami)" "${file}" >> "${LOG_FILE}" 2>&1; then
echo -e "${NOK}"
_panic
fi
fi
done
echo -e "${OK}"
}
_file_permission_rights() {
echo -ne "Changing file permissions/right..."
for file in ${PERMISSION_RIGHTS[@]}; do
if [ -e "${file}" ]; then
if ! chmod +x "${file}" >> "${LOG_FILE}" 2>&1; then
echo -e "${NOK}"
_panic
fi
fi
done
echo -e "${OK}"
}
_return_check() {
if [ "$1" -ne 0 ]; then
echo -e "${FAIL}"
_panic
fi
}
_deps_system_update() {
echo -ne "Updating sources..."
if grep -q "debian" /etc/os-release; then
if ! apt -y -q update >> "${LOG_FILE}" 2>&1; then
echo -e "${FAIL}"
_panic
fi
else
echo -e "${FAIL}"
echo -e "Cannot detect your distribution package manager."
_panic
fi
echo -e "${OK}"
}
_deps_system_check() {
echo -ne "Checking and installing dependencies system..."
for dep in ${DEPS_SYSTEM[@]}; do
if ! command -v "${dep}" >> "${LOG_FILE}" 2>&1; then
_deps_system_install "${dep}"
_return_check $?
fi
done
echo -e "${OK}"
}
_deps_system_install() {
if grep -q "debian" /etc/os-release; then
apt -y -q install "$1" >> "${LOG_FILE}" 2>&1
elif grep -q "fedora" /etc/os-release || grep -q "centos" /etc/os-release; then
dnf -y -q install "$1" >> "${LOG_FILE}" 2>&1
else
echo -e "${FAIL}"
echo -e "Cannot detect your distribution package manager."
_panic
fi
}
_deps_python_check() {
echo -ne "Checking and installing dependencies python..."
for dep in ${DEPS_PYTHON[@]}; do
pip3 install "${dep}" >> "${LOG_FILE}" 2>&1
_return_check $?
done
echo -e "${OK}"
}
_deps_file_check() {
echo -ne "Checking files..."
for dep in ${DEPS_FILE[@]}; do
if [ ! -e "${dep}" ]; then
echo "File '${dep}' missing." >> "${LOG_FILE}"
echo -e "${FAIL}"
echo -e "Needed files missing."
_panic
fi
done
echo -e "${OK}"
}
_python_check() {
echo -ne "Checking python..."
if pip3 --version >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
else
echo -e "${NOK}"
echo -e "Please install pip3 first"
_panic
fi
}
_addon_prompt() {
LOOP=1
options=("Terminal (Web-Terminal)" "Skip")
while [ $LOOP -eq 1 ] && [ "${#options[@]}" -ne "1" ]; do
echo -e ""
echo -e "Select addons which should be used:"
select opt in "${options[@]}"; do
case $opt in
"Terminal"*)
unset -v 'options[0]'
ADDON=1
echo -e ""
echo -e "Adding Terminal (Web-Terminal)...${OK}"
break;;
"Skip"*)
LOOP=0
echo -e ""
break;;
*)
echo -e ""
echo -e "Invalid choice!";;
esac
done
done
}
_config_prompt() {
if [ ! -f "$PATH_CURRENT/config.cfg" ] || [ ! -f "$PATH_CURRENT/config_auth.cfg" ]; then
_config_install
else
while true; do
echo -e ""
echo -e "There is already an existing configuration."
read -p "Do you want to overwrite this configuration? [y/n]" YN
case $YN in
[Yy]*)
echo -e ""
_config_install
break;;
[Nn]*)
echo -e ""
break;;
*)
echo -e ""
echo -e "Please answer yes or no.";;
esac
done
fi
}
_config_install() {
echo -ne "Installing config..."
if python3 bin/main.py --defaultconfig >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
else
echo -e "${NOK}"
_panic
fi
}
_webserver_prompt() {
LOOP=1
while [ $LOOP -eq 1 ]; do
echo -e ""
echo -e "Select a webserver to be used:"
options=("Gunicorn (Recommended)" "Flask" "aiohttp")
select opt in "${options[@]}"; do
case $opt in
"Gunicorn"*)
echo -e ""
_webserver_gunicorn
LOOP=0
break;;
"Flask"*)
echo -e ""
_webserver_flask
LOOP=0
break;;
"aiohttp"*)
echo -e ""
_webserver_aiohttp
LOOP=0
break;;
*)
echo -e ""
echo -e "Invalid choice!";;
esac
done
done
}
_webserver_config() {
ADDON_WEBPROXY=1
echo -ne "Configuring webserver for use with webproxy..."
sed -i '/^\[/h;G;/connection_webserver_aiohttp/s/\(host = \).*/\1127.0.0.1/m;P;d' config.cfg
sed -i '/^\[/h;G;/connection_webserver_aiohttp/s/\(port = \).*/\18080/m;P;d' config.cfg
sed -i '/^\[/h;G;/connection_webserver_flask/s/\(host = \).*/\1127.0.0.1/m;P;d' config.cfg
sed -i '/^\[/h;G;/connection_webserver_flask/s/\(port = \).*/\18080/m;P;d' config.cfg
sed -i '/^\[/h;G;/connection_webserver_gunicorn/s/\(host = \).*/\1127.0.0.1/m;P;d' config.cfg
sed -i '/^\[/h;G;/connection_webserver_gunicorn/s/\(port = \).*/\18080/m;P;d' config.cfg
echo -e "${OK}"
}
_webserver_gunicorn() {
echo -ne "Installing Gunicorn..."
if pip3 install gunicorn flask flask_httpauth >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
else
echo -e "${NOK}"
_panic
fi
echo -ne "Configuring Gunicorn..."
sed -i '/^\[/h;G;/connection_webserver_aiohttp/s/\(enabled = \).*/\1False/m;P;d' config.cfg
sed -i '/^\[/h;G;/connection_webserver_flask/s/\(enabled = \).*/\1False/m;P;d' config.cfg
sed -i '/^\[/h;G;/connection_webserver_gunicorn/s/\(enabled = \).*/\1True/m;P;d' config.cfg
echo -e "${OK}"
if [ $ADDON -eq 1 ]; then
echo -ne "Installing Addons..."
if pip3 install flask_socketio >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
else
echo -e "${NOK}"
_panic
fi
fi
}
_webserver_flask() {
echo -ne "Installing Flask..."
if pip3 install flask flask_httpauth >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
else
echo -e "${NOK}"
_panic
fi
echo -ne "Configuring Flask..."
sed -i '/^\[/h;G;/connection_webserver_aiohttp/s/\(enabled = \).*/\1False/m;P;d' config.cfg >> "${LOG_FILE}"
sed -i '/^\[/h;G;/connection_webserver_flask/s/\(enabled = \).*/\1True/m;P;d' config.cfg >> "${LOG_FILE}"
sed -i '/^\[/h;G;/connection_webserver_gunicorn/s/\(enabled = \).*/\1False/m;P;d' config.cfg >> "${LOG_FILE}"
echo -e "${OK}"
if [ $ADDON -eq 1 ]; then
echo -ne "Installing Addons..."
if pip3 install flask_socketio >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
else
echo -e "${NOK}"
_panic
fi
fi
}
_webserver_aiohttp() {
echo -ne "Installing aiohttp..."
if pip3 install aiohttp aiohttp_basicauth >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
else
echo -e "${NOK}"
_panic
fi
echo -ne "Configuring aiohttp..."
sed -i '/^\[/h;G;/connection_webserver_aiohttp/s/\(enabled = \).*/\1False/m;P;d' config.cfg >> "${LOG_FILE}"
sed -i '/^\[/h;G;/connection_webserver_flask/s/\(enabled = \).*/\1False/m;P;d' config.cfg >> "${LOG_FILE}"
sed -i '/^\[/h;G;/connection_webserver_gunicorn/s/\(enabled = \).*/\1True/m;P;d' config.cfg >> "${LOG_FILE}"
echo -e "${OK}"
}
_webproxy_prompt() {
LOOP=1
while [ $LOOP -eq 1 ]; do
echo -e ""
echo -e "Select a webproxy to be used:"
options=("Nginx (Recommended for production use)" "None")
select opt in "${options[@]}"; do
case $opt in
"Nginx"*)
echo -e ""
_webproxy_nginx_prompt
LOOP=0
break;;
"None"*)
echo -e ""
LOOP=0
break;;
*)
echo -e ""
echo -e "Invalid choice!";;
esac
done
done
}
_webproxy_nginx_prompt() {
echo -ne "Checking Nginx..."
if ! command -v "nginx" >> "${LOG_FILE}" 2>&1; then
echo -e "${OK}"
_webproxy_nginx_install
_webproxy_nginx_config_ssl_prompt
_webproxy_nginx_config_dh_prompt
_webproxy_nginx_config
_webserver_config
else
echo -e "${OK}"
echo -e ""
echo -e "Nginx is already installed."
echo -e "This wizard will create a new web page with HTTP & HTTPS."
echo -e "You will need to check the configuration later to make sure there are no conflicts with the existing configuration."
read -p "Do you want to proceed? [y/n]" YN
while true; do
case $YN in
[Yy]*)
echo -e ""
_webproxy_nginx_config_ssl_prompt
_webproxy_nginx_config_dh_prompt
_webproxy_nginx_config
_webserver_config
break;;
[Nn]*)
echo -e ""
echo -e "Continue without configuring the webproxy."
echo -e "This is not recommended for a productive environment!"
echo -e "You have to do the configuration manually later!"
break;;
*)
echo -e ""
echo -e "Please answer yes or no.";;
esac
done
fi
}
_webproxy_nginx_install() {
if ! command -v "nginx" >> "${LOG_FILE}" 2>&1; then
echo -ne "Installing Nginx..."
_deps_system_install "nginx"
_return_check $?
fi
}
_webproxy_nginx_config_ssl_prompt() {
echo -e "Configuring Nginx..."
if [ ! -f "/etc/ssl/private/${APP_FILE}.key" ] && [ ! -f "/etc/ssl/certs/${APP_FILE}.crt" ]; then
echo -e "Configuring SSL..."
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout "/etc/ssl/private/${APP_FILE}.key" -out "/etc/ssl/certs/${APP_FILE}.crt"
echo -e "${OK}"
else
while true; do
echo -e ""
echo -e "There is already an existing SSL certificate."
read -p "Do you want to generate a new one? [y/n]" YN
case $YN in
[Yy]*)
echo -e ""
echo -e "Configuring SSL..."
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout "/etc/ssl/private/${APP_FILE}.key" -out "/etc/ssl/certs/${APP_FILE}.crt"
echo -e "${OK}"
break;;
[Nn]*)
echo -e ""
break;;
*)
echo -e ""
echo -e "Please answer yes or no.";;
esac
done
fi
}
_webproxy_nginx_config_ssl() {
echo -e "Configuring Nginx..."
echo -e "Configuring SSL..."
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 -keyout "/etc/ssl/private/${APP_FILE}.key" -out "/etc/ssl/certs/${APP_FILE}.crt" -subj "${DEFAULT_SSL}"
echo -e "${OK}"
}
_webproxy_nginx_config_dh_prompt() {
echo -e "Configuring Nginx..."
if [ ! -f "/etc/nginx/${APP_FILE}.pem" ]; then
while true; do
echo -e ""
echo -e "Do you want to create a Diffie–Hellman Key for a higher level of security?"
read -p "This is going to take a long time. (~20 minutes) [y/n]" YN
case $YN in
[Yy]*)
echo -e ""
echo -e "Configuring Diffie–Hellman Key..."
openssl dhparam -out "/etc/nginx/${APP_FILE}.pem" 4096
echo -e "${OK}"
break;;
[Nn]*)
echo -e ""
break;;
*)
echo -e ""
echo -e "Please answer yes or no.";;
esac
done
else
while true; do
echo -e ""
echo -e "There is already an existing Diffie–Hellman Key."
echo -e "Do you want to generate a new one?"
read -p "This is going to take a long time. (~20 minutes) [y/n]" YN
case $YN in
[Yy]*)
echo -e ""
echo -e "Configuring Diffie–Hellman Key..."
openssl dhparam -out "/etc/nginx/${APP_FILE}.pem" 4096
echo -e "${OK}"
break;;
[Nn]*)
echo -e ""
break;;
*)
echo -e ""
echo -e "Please answer yes or no.";;
esac
done
fi
}
_webproxy_nginx_config_dh() {
echo -e "Configuring Nginx..."
echo -ne "Configuring Diffie–Hellman Key..."
openssl dhparam -out "/etc/nginx/${APP_FILE}.pem" 4096
echo -e "${OK}"
}
_webproxy_nginx_config() {
echo -e "Configuring Nginx..."
echo -ne "Creating web site config..."
if [ $ADDON -eq 1 ]; then
COMMENT_ADDON=""
else
COMMENT_ADDON="#"
fi
if [ -f "/etc/nginx/${APP_FILE}.pem" ]; then
COMMENT_DHPARAM=""
else
COMMENT_DHPARAM="#"
fi
FILE_DEFAULT="/etc/nginx/sites-enabled/default"
FILE_AVAILABLE="/etc/nginx/sites-available/${APP_FILE}.conf"
FILE_ENABLED="/etc/nginx/sites-enabled/${APP_FILE}.conf"
cat <<EOF > ${FILE_AVAILABLE}
server {
listen 80;
server_name _;
return 301 https://$host$request_uri;
}
server {
listen 443 ssl;
listen [::]:443 ssl;
ssl_certificate /etc/ssl/certs/${APP_FILE}.crt;
ssl_certificate_key /etc/ssl/private/${APP_FILE}.key;
${COMMENT_DHPARAM}ssl_dhparam /etc/nginx/${APP_FILE}.pem;
server_name _;
auth_basic "${APP_NAME}";
auth_basic_user_file /var/www/${APP_FILE}.htpasswd;
location ~ ^/index?.*[^.css|.html|.js]$ {
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header HOST \$http_host;
proxy_set_header X-Forwarded-Host \$http_host;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_pass http://127.0.0.1:8080;
proxy_redirect off;
}
${COMMENT_ADDON}location /socket.io {
${COMMENT_ADDON} proxy_set_header X-Real-IP \$remote_addr;
${COMMENT_ADDON} proxy_set_header HOST \$http_host;
${COMMENT_ADDON} proxy_set_header X-Forwarded-Host \$http_host;
${COMMENT_ADDON} proxy_set_header X-Forwarded-Proto \$scheme;
${COMMENT_ADDON} proxy_pass http://127.0.0.1:8181;
${COMMENT_ADDON} proxy_redirect off;
${COMMENT_ADDON}}
location / {
root /var/www/${APP_FILE};
}
}
EOF
if [ -f "$FILE_AVAILABLE" ]; then
echo -e "${OK}"