forked from easy-wi/installer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
easy-wi_install.sh
3034 lines (2683 loc) · 103 KB
/
easy-wi_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
# DEBUG MODE
DEBUG="OFF"
# Author: Ulrich Block <[email protected]>,
# Alexander Doerwald <[email protected]>
#
# This file is part of Easy-WI.
#
# Easy-WI is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Easy-WI is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Easy-WI. If not, see <http://www.gnu.org/licenses/>.
#
# Diese Datei ist Teil von Easy-WI.
#
# Easy-WI ist Freie Software: Sie koennen es unter den Bedingungen
# der GNU General Public License, wie von der Free Software Foundation,
# Version 3 der Lizenz oder (nach Ihrer Wahl) jeder spaeteren
# veroeffentlichten Version, weiterverbreiten und/oder modifizieren.
#
# Easy-WI wird in der Hoffnung, dass es nuetzlich sein wird, aber
# OHNE JEDE GEWAEHELEISTUNG, bereitgestellt; sogar ohne die implizite
# Gewaehrleistung der MARKTFAEHIGKEIT oder EIGNUNG FUER EINEN BESTIMMTEN ZWECK.
# Siehe die GNU General Public License fuer weitere Details.
#
# Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
# Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
# #shellcheck SC2193 https://github.com/koalaman/shellcheck/wiki/SC2193
# [ "$1" == "--debug" ]
if [ "$DEBUG" == "ON" ] || [ "${1}" == "--debug" ]; then
set -x
fi
# #shellcheck SC2145 https://github.com/koalaman/shellcheck/wiki/SC2145
# echo -e "\\033[32;1m${@}}\033[0m"
greenMessage() {
echo -e "\\033[32;1m$*\033[0m"
}
# #shellcheck SC2145 https://github.com/koalaman/shellcheck/wiki/SC2145
# echo -e "\\033[36;1m${@}\033[0m"
cyanMessage() {
echo -e "\\033[36;1m$*\033[0m"
}
# #shellcheck SC2145 https://github.com/koalaman/shellcheck/wiki/SC2145
# echo -e "\\033[31;1m${@}\033[0m"
redMessage() {
echo -e "\\033[31;1m$*\033[0m"
}
# #shellcheck SC2145 https://github.com/koalaman/shellcheck/wiki/SC2145
# echo -e "\\033[33;1m${@}\033[0m"
yellowMessage() {
echo -e "\\033[33;1m$*\033[0m"
}
# #shellcheck SC2145 https://github.com/koalaman/shellcheck/wiki/SC2145
# echo -en "\\033[32;1m${@}\033[0m"
greenOneLineMessage() {
echo -en "\\033[32;1m$*\033[0m"
}
# #shellcheck SC2145 https://github.com/koalaman/shellcheck/wiki/SC2145
# echo -en "\\033[36;1m${@}\033[0m"
cyanOneLineMessage() {
echo -en "\\033[36;1m$*\033[0m"
}
# #shellcheck SC2145 https://github.com/koalaman/shellcheck/wiki/SC2145
# echo -en "\\033[33;1m${@}\033[0m"
yellowOneLineMessage() {
echo -en "\\033[33;1m$*\033[0m"
}
errorAndQuit() {
errorAndExit "Exit now!"
}
errorAndExit() {
cyanMessage " "
redMessage "$*"
cyanMessage " "
exit 1
}
errorAndContinue() {
redMessage "Invalid option."
}
removeIfExists() {
if [ -n "${1}" ] && [ -f "${1}" ]; then
rm -f "${1}"
fi
}
runSpinner() {
SPINNER=("-" "\\" "|" "/")
for _ in $(seq 1 "$1"); do
for I in ${SPINNER[*]}; do
echo -ne "\b${I}"
sleep 0.1
done
done
}
okAndSleep() {
greenMessage "${1}"
sleep 1
}
makeDir() {
if [ -n "${1}" ] && [ ! -d "${1}" ]; then
mkdir -p "${1}"
fi
}
backUpFile() {
if [ ! -f "${1}.easy-install.backup" ]; then
cp "${1}" "${1}.easy-install.backup"
fi
}
checkInstall() {
if [ "${OS}" == "debian" ] || [ "${OS}" == "ubuntu" ]; then
if [ -z "$(dpkg-query -s "$1" 2>/dev/null)" ]; then
cyanMessage " "
okAndSleep "Installing package ${1}"
$INSTALLER -y install "${1}"
fi
elif [ "$OS" == "centos" ]; then
if [ -z "$(rpm -qa "${1}")" ]; then
cyanMessage " "
okAndSleep "Installing package $1"
$INSTALLER -y install "$1"
fi
elif [ "$OS" == "slackware" ]; then
if [ -z "$(slackpkg search "$1" 2>/dev/null)" ]; then
cyanMessage " "
okAndSleep "Installing package $1"
$INSTALLER install "$1"
fi
fi
if [ "$?" -ne 0 ]; then
errorAndExit "\nPlease check Output!\nInstallation abort!\n"
fi
}
checkUnInstall() {
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
if [ -z "$(dpkg-query -s "$1" 2>/dev/null)" ]; then
cyanMessage " "
okAndSleep "Uninstalling package $1"
$INSTALLER -y remove "$1"
fi
elif [ "$OS" == "centos" ]; then
if [ -z "$(rpm -qa "$1")" ]; then
cyanMessage " "
okAndSleep "Uninstalling package $1"
$INSTALLER -y remove "$1"
fi
elif [ "$OS" == "slackware" ]; then
if [ -z "$(slackpkg search "$1")" ]; then
cyanMessage " "
okAndSleep "Uninstalling package $1"
$INSTALLER remove "$1"
fi
fi
}
importKey() {
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
apt-key adv --recv-keys --keyserver "$1" "$2"
elif [ "$OS" == "centos" ]; then
rpm --import "$1"
elif [ "$OS" == "slackware" ]; then
slackpkg update gpg
fi
}
checkUser() {
if [ -z "$1" ]; then
redMessage "Error: No masteruser specified"
elif [ "$1" == "root" ]; then
redMessage "Error: Using root as masteruser is a security hazard and not allowed."
elif [ -n "$(id "$1" 2>/dev/null)" ] && { [ "$INSTALL" != "EW" ] && [ "$INSTALL" != "WR" ] || [ ! -d "/home/$1/sites-enabled" ]; }; then
redMessage "Error: User \"$1\" already exists. Please name a not yet existing user"
else
echo 1
fi
}
RestartWebserver() {
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
if [ "$WEBSERVER" == "Apache" ]; then
cyanMessage " "
okAndSleep "Restarting Apache2."
apache2ctl restart 1>/dev/null
elif [ "$WEBSERVER" == "Lighttpd" ]; then
cyanMessage " "
okAndSleep "Restarting Lighttpd."
service lighttpd restart 1>/dev/null
fi
elif [ "$OS" == "centos" ]; then
if [ "$WEBSERVER" == "Apache" ]; then
cyanMessage " "
if [ -f /etc/php-fpm.conf ]; then
okAndSleep "Restarting PHP-FPM and Apache2."
systemctl restart php-fpm.service 1>/dev/null
else
okAndSleep "Restarting Apache2."
fi
systemctl restart httpd.service 1>/dev/null
elif [ "$WEBSERVER" == "Lighttpd" ]; then
cyanMessage " "
if [ -f /etc/php-fpm.conf ]; then
okAndSleep "Restarting PHP-FPM and Lighttpd."
systemctl restart php-fpm.service 1>/dev/null
else
okAndSleep "Restarting Lighttpd."
fi
systemctl restart lighttpd.service 1>/dev/null
fi
elif [ "$OS" == "slackware" ]; then
if [ "$WEBSERVER" == "Apache" ]; then
cyanMessage " "
if [ -f /etc/php-fpm.conf ]; then
okAndSleep "Restarting PHP-FPM and Apache2."
/etc/rc.d/rc.php-fpm restart 1>/dev/null
else
okAndSleep "Restarting Apache2."
fi
/etc/rc.d/rc.httpd restart 1>/dev/null
fi
fi
}
RestartDatabase() {
# debian11 uses mariadb as service now
if [[ "$OS" == "debian" && "$OSVERSION" -le "100" ]] || [ "$OS" == "ubuntu" ]; then
if [ -f /etc/init.d/mysql ]; then
/etc/init.d/mysql restart 1>/dev/null
else
systemctl restart mysql 1>/dev/null
fi
elif [[ "$OS" == "debian" && "$OSVERSION" -ge "110" ]]; then
if [ -f /etc/init.d/mariadb ]; then
/etc/init.d/mariadb restart 1>/dev/null
else
systemctl restart mariadb 1>/dev/null
fi
elif [ "$OS" == "centos" ]; then
systemctl restart mariadb.service 1>/dev/null
if [ "$?" -ne "0" ]; then
systemctl restart mysql.service 1>/dev/null
fi
elif [ "$OS" == "slackware" ]; then
/etc/rc.d/rc.mysqld restart 1>/dev/null
fi
}
doReboot() {
if [ -n "$2" ]; then
redMessage " "
redMessage "$2"
fi
cyanMessage " "
cyanMessage "Do you want to restart now?"
OPTIONS=("Yes" "No" "Quit")
select OPTION in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2 | 3) break ;;
*) errorAndContinue ;;
esac
done
if [ "$OPTION" == "Yes" ]; then
cyanMessage " "
redMessage "$1"
removeIfExists /tmp/easy-wi_reboot
shutdown -r now
errorAndQuit
else
touch /tmp/easy-wi_reboot
clearPassword
errorAndQuit
fi
}
clearPassword() {
# clear password variable
unset MYSQL_ROOT_PASSWORD MYSQL_USER_PASSWORD DB_PASSWORD QUERY_PASSWORD WEBGROUPNAME2 FIREWALL MASTERUSER MYSQL_USER HTTPDSCRIPT
}
portRange() {
RANDOMPORTRANGE=$(seq 1001 65536 | shuf -n 1)
PORT_RANGE=$((RANDOMPORTRANGE + 200))
echo "$RANDOMPORTRANGE" $PORT_RANGE
}
setPath() {
## As standard sudo users on Slackware do not have access to /sbin and /usr/sbin
## directories which blocks access to usermod, userdel and useradd commands.
CURRENTPATH=$(cat /etc/profile | grep PATH= | sed '/$PATH/d')
CORRECTPATH='PATH="/usr/local/bin:/usr/bin:/bin:/usr/games:/sbin:/usr/sbin"'
## If the PATH variable doesn't exist .. Yikes .. let's GTFO
yellowMessage " "
yellowMessage "Checking if PATH is set ...."
if [ $CURRENTPATH == "" ]; then
errorAndExit "No PATH detected, you need to fix this! ... Exiting"
exit 1
fi
## Write the new PATH to /etc/profile if it's not correct already
if [ $CURRENTPATH != $CORRECTPATH ]; then
yellowMessage " "
yellowMessage "Writing new PATH to /etc/profile ..."
sed -i "s|$CURRENTPATH|"'PATH="/usr/local/bin:/usr/bin:/bin:/usr/games:/sbin:/usr/sbin"|' /etc/profile
fi
}
# We need to be root to install and update
if [ "$(id -u)" != "0" ]; then
cyanMessage "Change to root account required"
su -
fi
if [ "$(id -u)" != "0" ]; then
errorAndExit "Still not root, aborting"
fi
cyanMessage " "
yellowMessage "Please wait... Update is currently running."
cyanMessage " "
if [ -f /etc/debian_version ]; then
INSTALLER="apt-get"
OS="debian"
$INSTALLER -y update
if [ -z "$(which wget)" ]; then
checkInstall wget
fi
if [ -z "$(which dialog)" ]; then
checkInstall dialog
fi
if [ -z "$(which logger)" ]; then
apt-get --reinstall install bsdutils
fi
if [ -z "$(which apt-utils)" ]; then
checkInstall apt-utils
fi
if [ -z "$(which sudo)" ]; then
checkInstall sudo
fi
elif [ -f /etc/centos-release ]; then
INSTALLER="yum"
OS="centos"
setenforce 0 >/dev/null 2>&1
systemctl stop postfix
systemctl disable postfix
$INSTALLER clean all
$INSTALLER -y update
if [ -z "$(rpm -qa wget)" ]; then
checkInstall wget
fi
if [ -z "$(rpm -qa which)" ]; then
checkInstall which
fi
elif [ -f /etc/os-release ]; then
INSTALLER="slackpkg"
OS="slackware"
$INSTALLER update
if [ -z "$(slackpkg search wget)" ]; then
checkInstall wget
fi
if [ -z "$(slackpkg search which)" ]; then
checkInstall which
fi
fi
INSTALLER_VERSION=3.3
PKILL=$(which pkill)
USERADD=$(which useradd)
USERMOD=$(which usermod)
USERDEL=$(which userdel)
GROUPADD=$(which groupadd)
MACHINE=$(uname -m)
HOST_NAME=$(hostname -f | awk '{print tolower($0)}')
LOCAL_IP=$(hostname -I | awk '{print $1}')
if [ -z "$LOCAL_IP" ] || [ "$LOCAL_IP" == "0" ] || [ "$LOCAL_IP" == "localhost" ]; then
LOCAL_IP=$(ip route get 8.8.8.8 | awk '{print $7; exit}')
fi
cyanMessage " "
cyanMessage "Checking for the latest installer version"
LATEST_VERSION=$(wget -q --timeout=60 -O - https://api.github.com/repos/easy-wi/installer/releases/latest | grep -Po '(?<="tag_name": ")([0-9]\.[0-9]+)')
if [ "$(printf "${LATEST_VERSION}\n${INSTALLER_VERSION}" | sort -V | tail -n 1)" != "$INSTALLER_VERSION" ]; then
errorAndExit "You are using the old version ${INSTALLER_VERSION}. Please upgrade to version ${LATEST_VERSION} and retry."
else
okAndSleep "You are using the up to date version ${INSTALLER_VERSION}"
fi
cyanMessage " "
okAndSleep "Update the system packages to the latest version? Required, as otherwise dependencies might break!"
OPTIONS=("Yes" "Quit")
select UPDATE_UPGRADE_SYSTEM in "${OPTIONS[@]}"; do
case "$REPLY" in
1) break ;;
2) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
if [ "$UPDATE_UPGRADE_SYSTEM" == "Yes" ]; then
cyanMessage " "
yellowMessage "Please wait... Update is currently running."
cyanMessage " "
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
cyanMessage " "
$INSTALLER -y upgrade
checkInstall debconf-utils
checkInstall lsb-release
elif [ "$OS" == "centos" ]; then
cyanMessage " "
cyanMessage "Update all obsolete packages."
$INSTALLER -y update
checkInstall redhat-lsb
checkInstall epel-release
importKey /etc/pki/rpm-gpg/RPM-GPG-KEY*
checkInstall yum-utils
elif [ "$OS" == "slackware" ]; then
cyanMessage " "
cyanMessage "Update all obsolete packages."
$INSTALLER update
fi
fi
checkInstall curl
yellowMessage ""
yellowMessage "Note: locales added en_US.UTF-8 if needed!"
yellowMessage ""
if [ "$OS" == "centos" ]; then
if [ "$(grep LANG= /etc/locale.conf)" != "LANG=en_US.UTF-8" ] && [ -n "$(localectl list-locales | grep en_US.UTF-8)" ]; then
localectl set-locale LANG=en_US.UTF-8
elif [ "$(grep LANG= /etc/locale.conf)" != "LANG=en_US.utf8" ] && [ -n "$(localectl list-locales | grep en_US.utf8)" ]; then
localectl set-locale LANG=en_US.utf8
fi
elif [ "$OS" == "slackware" ]; then
if [ "$(grep '\bexport LANG=en_US.UTF-8\b' /etc/profile.d/lang.sh)" != " export LANG=en_US.UTF-8" ]; then
echo "export LANG=en_US.UTF-8" >>/etc/profile.d/lang.sh
fi
else
checkInstall locales
if [ "$(grep en_US.UTF-8 /etc/locale.gen)" != "en_US.UTF-8 UTF-8" ]; then
sed -i "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" /etc/locale.gen
dpkg-reconfigure --frontend noninteractive locales
fi
fi
#CentOS - SELinux
if [ "$OS" == "centos" ]; then
if [ ! -f /tmp/easy-wi_reboot ]; then
if [ ! -d /home/easywi_web ] && [ -z "$(find /home -type d -name 'masterserver')" ] && [ -z "$(find /home -type f -name 'ts3server')" ]; then
yellowMessage ""
yellowMessage "Note: Please update your fresh operating system and restart it!"
yellowMessage ""
fi
if [ -f /etc/selinux/config ]; then
if [ "$(grep 'SELINUX=' /etc/selinux/config | sed -n '2 p')" != "SELINUX=disabled" ]; then
backUpFile /etc/selinux/config
sed -i "s/SELINUX=enforcing/SELINUX=disabled/g" /etc/selinux/config
redMessage " "
redMessage "Please reboot your Root/Vserver to disabled SELinux Security Function!"
redMessage "Otherwise, the WebInterface can not work."
redMessage " "
doReboot "System is rebooting now for finish SELinux Security Function! (if this message is permanent please disable it by hand and delete /tmp/easy-wi_reboot)"
fi
fi
else
doReboot "System is rebooting now for finish SELinux Security Function!(if this message is permanent please disable it by hand and delete /tmp/easy-wi_reboot)" "Please reboot your Root/Vserver to disabled SELinux Security Function(if this message is permanent please disable it by hand and delete /tmp/easy-wi_reboot)"
fi
fi
cyanMessage " "
if [ -f /etc/slackware-version ]; then
OS=$(grep '\bNAME=\b' /etc/os-release | sed -n 's/^.*NAME=//p' | sed -e 's/\(.*\)/\L\1/')
OSVERSION_TMP=$(grep '\bVERSION_ID=\b' /etc/os-release | sed -n 's/^.*VERSION_ID=//p')
OSBRANCH=$(grep '\bVERSION_CODENAME=\b' /etc/os-release | sed -n 's/^.*VERSION_CODENAME=//p')
else
OS=$(lsb_release -i 2>/dev/null | grep 'Distributor' | awk '{print tolower($3)}')
OSVERSION_TMP=$(lsb_release -r 2>/dev/null | grep 'Release' | awk '{print $2}')
OSBRANCH=$(lsb_release -c 2>/dev/null | grep 'Codename' | awk '{print $2}')
fi
if [ "$MACHINE" == "x86_64" ]; then
ARCH="amd64"
elif [ "$MACHINE" == "i386" ] || [ "$MACHINE" == "i686" ]; then
ARCH="x86"
fi
if [ -z "$OS" ]; then
errorAndExit "Error: Could not detect OS. Currently only Debian, Ubuntu and CentOS are supported. Aborting!"
else
okAndSleep "Detected OS: $OS"
fi
if [ -z "$OSBRANCH" ]; then
errorAndExit "Error: Could not detect branch of OS. Aborting"
else
okAndSleep "Detected branch: $OSBRANCH"
fi
if [ -z "$OSVERSION_TMP" ]; then
errorAndExit "Error: Could not detect version of OS. Aborting"
else
okAndSleep "Detected version: $OSVERSION_TMP"
if [ "$OS" == "ubuntu" ]; then
OSVERSION=$(echo "$OSVERSION_TMP" | tr -d .)
elif [ "$OS" == "centos" ]; then
OSVERSION=$(echo "$OSVERSION_TMP" | tr -d . | cut -c 1-2)
elif [ "$OS" == "debian" ]; then
if [ $(echo "$OSVERSION_TMP" | wc -c) == "3" ]; then
OSVERSION=$(echo "$OSVERSION_TMP")0
else
OSVERSION=$(echo "$OSVERSION_TMP" | tr -d . | cut -c 1-2)
fi
fi
fi
if [ -z "$ARCH" ]; then
errorAndExit "Error: $MACHINE is not supported! Aborting"
else
okAndSleep "Detected architecture: $ARCH"
fi
if [ "$OS" == "ubuntu" ] && [ "$OSVERSION" -lt "1604" ] || [ "$OS" == "debian" ] && [ "$OSVERSION" -lt "90" ] || [ "$OS" == "centos" ] && [ "$OSVERSION" -lt "60" ]; then
echo
echo
redMessage "Error: Your OS \"$OS $OSVERSION_TMP\" is not more supported from Easy-WI Installer."
redMessage "Please Upgrade to a newer OS Version!"
redMessage " "
if [ "$OS" == "centos" ]; then
redMessage "Reinstall CentOS to Version 7 or newer!"
redMessage "A Upgrade from your OS is not available."
redMessage " "
errorAndQuit
fi
if [ "$OS" == "ubuntu" ]; then
OSBRANCH_NEW="xenial (Ubuntu 16.04 LTS)"
else
OSBRANCH_NEW="stretch (Debian 9)"
fi
cyanMessage "Upgrade to $OS $OSBRANCH_NEW?"
OPTIONS=("Yes" "No" "Quit")
select OPTION in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2) break ;;
3) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
if [ "$OPTION" == "Yes" ]; then
if [ "$OS" == "ubuntu" ]; then
checkInstall update-manager-core
do-release-upgrade
elif [ "$OS" == "debian" ]; then
sed -i "s/$OSBRANCH/stretch/g" /etc/apt/sources.list
$INSTALLER -y update
$INSTALLER -y upgrade
$INSTALLER -y dist-upgrade -u
$INSTALLER -y autoremove
fi
doReboot "System is rebooting now for finish Upgrade!"
else
if [ "$OS" == "ubuntu" ]; then
redMessage "Run this command to manually update your OS: "
redMessage "Command: do-release-upgrade"
redMessage " "
errorAndQuit
elif [ "$OS" == "debian" ]; then
redMessage "Command: apt-get update; apt-get upgrade; apt-get dist-upgrade; apt-get autoremove"
redMessage " "
errorAndQuit
fi
fi
fi
yellowMessage " "
yellowOneLineMessage "If you want to install everything on this system, then please install the "
cyanOneLineMessage "Easy-WI Webpanel "
yellowMessage "first!"
cyanMessage " "
cyanMessage "What shall be installed/prepared?"
OPTIONS=("Easy-WI Webpanel" "Gameserver Root" "Voicemaster" "Webspace Root" "MySQL" "Quit")
select OPTION in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2 | 3 | 4 | 5) break ;;
6) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
if [ "$OPTION" == "Easy-WI Webpanel" ]; then
INSTALL="EW"
elif [ "$OPTION" == "Gameserver Root" ]; then
INSTALL="GS"
elif [ "$OPTION" == "Voicemaster" ]; then
INSTALL="VS"
elif [ "$OPTION" == "Webspace Root" ]; then
INSTALL="WR"
elif [ "$OPTION" == "MySQL" ]; then
INSTALL="MY"
fi
OTHER_PANEL=""
if [ "$INSTALL" != "VS" ]; then
if [ -f /etc/init.d/psa ]; then
OTHER_PANEL="Plesk"
elif [ -f /usr/local/vesta/bin/v-change-user-password ]; then
OTHER_PANEL="VestaCP"
elif [ -d /root/confixx ]; then
OTHER_PANEL="Confixx"
elif [ -d /var/www/froxlor ]; then
OTHER_PANEL="Froxlor"
elif [ -d /etc/imscp ]; then
OTHER_PANEL="i-MSCP"
elif [ -d /usr/local/ispconfig ]; then
OTHER_PANEL="ISPConfig"
elif [ -d /var/cpanel ]; then
OTHER_PANEL="cPanel"
elif [ -d /usr/local/directadmin ]; then
OTHER_PANEL="DirectAdmin"
fi
fi
if [ -n "$OTHER_PANEL" ]; then
if [ "$INSTALL" == "GS" ]; then
yellowMessage " "
yellowMessage "Warning an installation of the control panel $OTHER_PANEL has been detected."
yellowMessage "If you continue the installer might end up breaking $OTHER_PANEL or same parts of Easy-WI might not work."
OPTIONS=("Continue" "Quit")
select OTHER_PANEL_CONTINUE in "${OPTIONS[@]}"; do
case "$REPLY" in
1) break ;;
2) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
if [ "$OTHER_PANEL_CONTINUE" == "Continue" ]; then
redMessage " "
redMessage "At your own risk!"
redMessage "Easy-WI does not support anyone in using other panels."
fi
else
redMessage " "
errorAndExit "Aborting as the risk of breaking the installed panel $OTHER_PANEL is too high."
fi
fi
# Run the domain/IP check up front to avoid late error out.
if [ "$INSTALL" == "EW" ]; then
cyanMessage " "
cyanMessage "At which URL/Domain should Easy-Wi be placed?"
OPTIONS=("$LOCAL_IP" "Domain/IP" "Quit")
select OPTION in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2) break ;;
3) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
if [ "$OPTION" == "Domain/IP" ]; then
cyanMessage " "
cyanMessage "Please specify the IP or domain Easy-Wi should run at."
read IP_DOMAIN
else
IP_DOMAIN=$OPTION
fi
if [ -z "$(grep -E '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b' <<<"$IP_DOMAIN")" ] && [ -z "$(grep -E '^(([a-zA-Z](-?[a-zA-Z0-9])*)\.)*[a-zA-Z](-?[a-zA-Z0-9])+\.[a-zA-Z]{2,}$' <<<"$IP_DOMAIN")" ]; then
errorAndExit "Error: $IP_DOMAIN is neither a domain nor an IPv4 address!"
fi
FILE_NAME=${IP_DOMAIN//./_}
cyanMessage " "
cyanMessage "Install stable or latest developer version?"
OPTIONS=("Stable" "Developer" "Quit")
select OPTION in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2) break ;;
3) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
RELEASE_TYPE=$OPTION
fi
if [ "$INSTALL" == "EW" ] || [ "$INSTALL" == "WR" ]; then
if [ "$OS" == "ubuntu" ] || [ "$OS" == "debian" ]; then
checkInstall cron
elif [ "$OS" == "centos" ]; then
checkInstall crontabs
fi
if [ "$OS" == "debian" ] && [ "$OSVERSION" -lt "100" ]; then
cyanMessage " "
cyanMessage "Use dotdeb.org repository for more up to date server and PHP versions?"
OPTIONS=("Yes" "No" "Quit")
select DOTDEB in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2) break ;;
3) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
if [ "$DOTDEB" == "Yes" ]; then
if [ -z "$(grep 'packages.dotdeb.org' /etc/apt/sources.list)" ]; then
cyanMessage " "
okAndSleep "Adding entries to /etc/apt/sources.list"
if [ "$OSBRANCH" == "stretch" ]; then
checkInstall software-properties-common
fi
add-apt-repository "deb http://packages.dotdeb.org $OSBRANCH all"
curl --remote-name https://www.dotdeb.org/dotdeb.gpg
apt-key add dotdeb.gpg
removeIfExists dotdeb.gpg
$INSTALLER -y update
fi
fi
fi
if [ "$INSTALL" == "EW" ]; then
WEBSERVER="Apache"
elif [ "$INSTALL" == "WR" ]; then
if [ ! -d /home/easywi_web/htdocs/ ]; then
cyanMessage " "
cyanMessage "Please select the webserver you would like to use"
cyanMessage "Lighttpd is recommended for FastDL"
cyanMessage "Apache is recommended in case you want to run many PHP supporting Vhosts aka mass web hosting"
OPTIONS=("Apache" "Lighttpd" "None" "Quit")
select WEBSERVER in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2 | 3) break ;;
4) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
else
WEBSERVER="None"
fi
fi
fi
# If we need to install and configure a webspace then we need to identify the groupID
if [ "$INSTALL" == "EW" ] || [ "$INSTALL" == "WR" ]; then
if [ "$OS" == "debian" ] || [ "$OS" == "ubuntu" ]; then
WEBGROUPNAME="www-data"
WEBGROUPTMPID="33"
WEBGROUPPATH="/var/www"
WEBGROUPCOMMENT="Webserver"
elif [ "$OS" == "centos" ]; then
if [ "$WEBSERVER" == "Lighttpd" ]; then
WEBGROUPNAME="lighttpd"
WEBGROUPTMPID="993"
WEBGROUPPATH="/var/www/lighttpd"
WEBGROUPCOMMENT="lighttpd web server"
elif [ "$WEBSERVER" == "Apache" ]; then
WEBGROUPNAME="apache"
WEBGROUPTMPID="48"
WEBGROUPPATH="/usr/share/httpd"
WEBGROUPCOMMENT="Apache"
elif [ "$WEBSERVER" == "None" ]; then
if [ -f /etc/lighttpd/lighttpd.conf ]; then
WEBGROUPNAME="lighttpd"
WEBGROUPTMPID="993"
WEBGROUPPATH="/var/www/lighttpd"
WEBGROUPCOMMENT="lighttpd web server"
elif [ -f /etc/httpd/conf/httpd.conf ]; then
WEBGROUPNAME="apache"
WEBGROUPTMPID="48"
WEBGROUPPATH="/usr/share/httpd"
WEBGROUPCOMMENT="Apache"
if [ "$OS" == "centos" ] && [ "$INSTALL" == "WR" ]; then
WEBSERVER="Apache"
fi
else
errorAndExit "No Webserver Installation found. Aborting!"
fi
fi
fi
WEBGROUPID=$(getent group $WEBGROUPNAME | awk -F ':' '{print $3}')
if [ "$WEBGROUPID" != "$WEBGROUPTMPID" ]; then
$GROUPADD -g $WEBGROUPTMPID $WEBGROUPNAME >/dev/null 2>&1
if [ "$WEBSERVER" == "Lighttpd" ]; then
$USERADD -c "$WEBGROUPCOMMENT" -u $WEBGROUPTMPID -g $WEBGROUPTMPID -s /sbin/nologin -r -d $WEBGROUPPATH $WEBGROUPNAME
fi
WEBGROUPID=$(getent group $WEBGROUPNAME | awk -F ':' '{print $3}')
fi
if [ "$INSTALL" == "EW" ] || [ -d /home/easywi_web/htdocs/ ]; then
OPTION="Yes"
else
cyanMessage " "
cyanOneLineMessage 'Found group "'
yellowOneLineMessage "$WEBGROUPNAME"
cyanOneLineMessage '" with group ID "'
yellowOneLineMessage "$WEBGROUPID"
cyanMessage '". Use as webservergroup?'
OPTIONS=("Yes" "No" "Quit")
select OPTION in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2) break ;;
3) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
fi
if [ "$OPTION" == "No" ]; then
cyanMessage "Please name the group you want to use as webservergroup"
read WEBGROUP
WEBGROUPID=$(getent group "$WEBGROUP" | awk -F ':' '{print $3}')
if [ -z "$WEBGROUPID" ]; then
$GROUPADD "$WEBGROUP"
WEBGROUPID=$(getent group "$WEBGROUP" | awk -F ':' '{print $3}')
fi
fi
if [ -z "$WEBGROUPID" ]; then
errorAndExit "Fatal Error: missing webservergroup ID"
elif [ "$WEBGROUPID" != "$WEBGROUPTMPID" ]; then
errorAndExit "Fatal Error: wrong webservergroup ID"
fi
fi
# Run the TS3 server version detect up front to avoid user executing steps first and fail at download last.
if [ "$INSTALL" == "VS" ]; then
cyanMessage " "
okAndSleep "Searching latest build for hardware type $MACHINE with arch $ARCH."
for VERSION in $(curl -s "https://files.teamspeak-services.com/releases/server/?C=M;O=D" | grep -Po '(?<=href=")[0-9]+(\.[0-9]+){2,3}(?=")' | sort -Vr); do
DOWNLOAD_URL_VERSION="https://files.teamspeak-services.com/releases/server/$VERSION/teamspeak3-server_linux_$ARCH-$VERSION.tar.bz2"
DOWNLOAD_URL=$DOWNLOAD_URL_VERSION
break
done
okAndSleep "Detected latest server version as $VERSION with download URL $DOWNLOAD_URL"
fi
#evenntuell ändern
if [[ "$INSTALL" != "MY" ]]; then
cyanMessage " "
cyanMessage "Please enter the name of the masteruser, which does not exist yet."
read MASTERUSER
CHECK_USER=$(checkUser "$MASTERUSER")
if [ "$CHECK_USER" != "1" ]; then
echo "$CHECK_USER"
read MASTERUSER
CHECK_USER=$(checkUser "$MASTERUSER")
if [ "$CHECK_USER" != "1" ]; then
echo "$CHECK_USER"
errorAndExit "Fatal Error: No valid masteruser specified in two tries"
fi
fi
if [ "$INSTALL" == "EW" ] || [ "$INSTALL" == "WR" ]; then
$USERADD -m -b /home -s /bin/bash -g "$WEBGROUPNAME" "$MASTERUSER"
else
$GROUPADD "$MASTERUSER"
$USERADD -m -b /home -s /bin/bash -g "$MASTERUSER" "$MASTERUSER"
fi
cyanMessage " "
cyanMessage "Create key or set password for login?"
cyanMessage "Safest way of login is a password protected key."
if [ "$INSTALL" == "EW" ]; then
cyanMessage "Neither is required, when installing Easy-WI Webpanel."
fi
OPTIONS=("Create key" "Set password" "Skip" "Quit")
select OPTION in "${OPTIONS[@]}"; do
case "$REPLY" in
1 | 2 | 3) break ;;
4) errorAndQuit ;;
*) errorAndContinue ;;
esac
done
if [ "$OPTION" == "Create key" ]; then
if [ -d /home/"$MASTERUSER"/.ssh ]; then
rm -rf /home/"$MASTERUSER"/.ssh
fi
makeDir /home/"$MASTERUSER"/.ssh
chown "$MASTERUSER":$WEBGROUPNAME /home/"$MASTERUSER"/.ssh >/dev/null 2>&1
cd /home/"$MASTERUSER"/.ssh || exit
cyanMessage " "
cyanMessage "It is recommended but not required to set a password"
#ssh-keygen creates not yet supported encrypted open ssh keys since version 7.8 -> https://www.openssh.com/txt/release-7.8
# support for encrypted open ssh keys comes with phpseclib v3
if [ "$(ssh -V 2>&1 | awk -F'[_.]' '{ print $2 "." $3+0 }')" \< "7.8" ]; then
su -c "ssh-keygen -t rsa -f /home/$MASTERUSER/.ssh/id_rsa -N ''" "$MASTERUSER"
else
su -c "ssh-keygen -m PEM -f /home/$MASTERUSER/.ssh/id_rsa -N ''" "$MASTERUSER"
fi
KEYNAME=$(find -maxdepth 1 -name "*.pub" | head -n 1)
if [ -n "$KEYNAME" ]; then
su -c "cat $KEYNAME >> authorized_keys" "$MASTERUSER"
if [ "$INSTALL" != "EW" ] && [ "$INSTALL" != "MY" ]; then
if [ -d /home/easywi_web/htdocs/keys/ ]; then
cp /home/"$MASTERUSER"/.ssh/id_rsa.pub /home/easywi_web/htdocs/keys/"$MASTERUSER".pub
cp /home/"$MASTERUSER"/.ssh/id_rsa /home/easywi_web/htdocs/keys/"$MASTERUSER"
WEBGROUPNAME2=$(ls -ls /home/easywi_web/htdocs/keys/ | grep "easywi_web" | awk '{print $5}' | head -n1)
chown -cR easywi_web:"$WEBGROUPNAME2" /home/easywi_web/htdocs/keys/ >/dev/null 2>&1
fi
fi
else
redMessage "Error: could not find a key. You might need to create one manually at a later point."
fi
elif [ "$OPTION" == "Set password" ]; then
cyanMessage " "
cyanMessage "Please provide the user password for $MASTERUSER."
passwd "$MASTERUSER"
fi
fi
if [ "$INSTALL" == "WR" ] || [ "$INSTALL" == "EW" ]; then
makeDir /home/"$MASTERUSER"/sites-enabled/
makeDir /home/"$MASTERUSER"/skel
makeDir /home/"$MASTERUSER"/skel/htdocs
makeDir /home/"$MASTERUSER"/skel/logs
makeDir /home/"$MASTERUSER"/skel/sessions
makeDir /home/"$MASTERUSER"/skel/tmp
chown -cR "$MASTERUSER":$WEBGROUPNAME /home/"$MASTERUSER" >/dev/null 2>&1
#Fix Error 403 - You don't have permission to access /install/install.php on this server.
chmod +x /home/"$MASTERUSER"/ >/dev/null 2>&1
chmod +x /home/"$MASTERUSER"/skel/ >/dev/null 2>&1
chmod +x /home/"$MASTERUSER"/skel/htdocs >/dev/null 2>&1
cyanMessage " "