· 10 years ago · Aug 30, 2016, 03:44 PM
1#!/bin/bash
2
3# Author: Ulrich Block <ulrich.block@easy-wi.com>
4#
5# This file is part of Easy-WI.
6#
7# Easy-WI is free software: you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation, either version 3 of the License, or
10# (at your option) any later version.
11#
12# Easy-WI is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with Easy-WI. If not, see <http://www.gnu.org/licenses/>.
19#
20# Diese Datei ist Teil von Easy-WI.
21#
22# Easy-WI ist Freie Software: Sie koennen es unter den Bedingungen
23# der GNU General Public License, wie von der Free Software Foundation,
24# Version 3 der Lizenz oder (nach Ihrer Wahl) jeder spaeteren
25# veroeffentlichten Version, weiterverbreiten und/oder modifizieren.
26#
27# Easy-WI wird in der Hoffnung, dass es nuetzlich sein wird, aber
28# OHNE JEDE GEWAEHELEISTUNG, bereitgestellt; sogar ohne die implizite
29# Gewaehrleistung der MARKTFAEHIGKEIT oder EIGNUNG FUER EINEN BESTIMMTEN ZWECK.
30# Siehe die GNU General Public License fuer weitere Details.
31#
32# Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
33# Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
34
35function greenMessage {
36 echo -e "\\033[32;1m${@}\033[0m"
37}
38
39function cyanMessage {
40 echo -e "\\033[36;1m${@}\033[0m"
41}
42
43function redMessage {
44 echo -e "\\033[31;1m${@}\033[0m"
45}
46
47function yellowMessage {
48 echo -e "\\033[33;1m${@}\033[0m"
49}
50
51function errorAndQuit {
52 errorAndExit "Exit now!"
53}
54
55function errorAndExit {
56 redMessage ${@}
57 exit 0
58}
59
60function errorAndContinue {
61 redMessage "Invalid option."
62 continue
63}
64
65function removeIfExists {
66 if [ "$1" != "" -a -f "$1" ]; then
67 rm -f $1
68 fi
69}
70
71function runSpinner {
72
73 SPINNER=("-" "\\" "|" "/")
74
75 for SEQUENCE in `seq 1 $1`; do
76 for I in "${SPINNER[@]}"; do
77 echo -ne "\b$I"
78 sleep 0.1
79 done
80 done
81}
82
83function okAndSleep {
84 greenMessage $1
85 sleep 1
86}
87
88function makeDir {
89 if [ "$1" != "" -a ! -d $1 ]; then
90 mkdir -p $1
91 fi
92}
93
94function backUpFile {
95 if [ ! -f "$1.easy-install.backup" ]; then
96 cp "$1" "$1.easy-install.backup"
97 fi
98}
99
100function checkInstall {
101 if [ "`dpkg-query -s $1 2>/dev/null`" == "" ]; then
102 okAndSleep "Installing package $1"
103 apt-get install -y $1
104 fi
105}
106
107INSTALLER_VERSION="1.6"
108OS=""
109USERADD=`which useradd`
110USERMOD=`which usermod`
111USERDEL=`which userdel`
112GROUPADD=`which groupadd`
113MACHINE=`uname -m`
114LOCAL_IP=`ip route get 8.8.8.8 | awk '{print $NF; exit}'`
115
116if [ "$LOCAL_IP" == "" ]; then
117 HOST_NAME=`hostname -f | awk '{print tolower($0)}'`
118else
119 HOST_NAME=`getent hosts $LOCAL_IP | awk '{print tolower($2)}' | head -n 1`
120fi
121
122cyanMessage "Checking for the latest latest installer"
123LATEST_VERSION=`wget -q --timeout=60 -O - http://l.easy-wi.com/installer_version.php | sed 's/^\xef\xbb\xbf//g'`
124
125if [ "`printf "${LATEST_VERSION}\n${INSTALLER_VERSION}" | sort -V | tail -n 1`" != "$INSTALLER_VERSION" ]; then
126 errorAndExit "You are using the old version ${INSTALLER_VERSION}. Please upgrade to version ${LATEST_VERSION} and retry."
127else
128 okAndSleep "You are using the up to date version ${INSTALLER_VERSION}."
129fi
130
131# We need to be root to install and update
132if [ "`id -u`" != "0" ]; then
133 cyanMessage "Change to root account required"
134 su -
135fi
136
137if [ "`id -u`" != "0" ]; then
138 errorAndExit "Still not root, aborting"
139fi
140
141# Debian and its derivatives store their version at /etc/debian_version
142if [ -f /etc/debian_version ]; then
143
144 cyanMessage " "
145 okAndSleep "Update the system packages to the latest version? Required, as otherwise dependencies might brake!"
146
147 OPTIONS=("Yes" "Quit")
148 select UPDATE_UPGRADE_SYSTEM in "${OPTIONS[@]}"; do
149 case "$REPLY" in
150 1 ) break;;
151 2 ) errorAndQuit;;
152 *) errorAndContinue;;
153 esac
154 done
155
156 apt-get update && apt-get upgrade -y && apt-get dist-upgrade -y
157
158 checkInstall curl
159 checkInstall debconf-utils
160 checkInstall lsb-release
161
162 OS=`lsb_release -i 2> /dev/null | grep 'Distributor' | awk '{print tolower($3)}'`
163 OSVERSION=`lsb_release -r 2> /dev/null | grep 'Release' | awk '{print $2}'`
164 OSBRANCH=`lsb_release -c 2> /dev/null | grep 'Codename' | awk '{print $2}'`
165fi
166
167if [ "$OS" == "" ]; then
168 errorAndExit "Error: Could not detect OS. Currently only Debian and Ubuntuu are supported. Aborting!"
169else
170 okAndSleep "Detected OS $OS"
171fi
172
173if [ "$OSBRANCH" == "" ]; then
174 errorAndExit "Error: Could not detect branch of OS. Aborting"
175else
176 okAndSleep "Detected branch $OSBRANCH"
177fi
178
179cyanMessage " "
180cyanMessage "What shall be installed/prepared?"
181
182OPTIONS=("Gameserver Root" "Voicemaster" "Easy-WI Webpanel" "Webspace Root" "MySQL" "Quit")
183select OPTION in "${OPTIONS[@]}"; do
184 case "$REPLY" in
185 1|2|3|4|5 ) break;;
186 6 ) errorAndQuit;;
187 *) errorAndContinue;;
188 esac
189done
190
191if [ "$OPTION" == "Easy-WI Webpanel" ]; then
192 INSTALL="EW"
193elif [ "$OPTION" == "Gameserver Root" ]; then
194 INSTALL="GS"
195elif [ "$OPTION" == "Voicemaster" ]; then
196 INSTALL="VS"
197elif [ "$OPTION" == "Webspace Root" ]; then
198 INSTALL="WR"
199elif [ "$OPTION" == "MySQL" ]; then
200 INSTALL="MY"
201fi
202
203OTHER_PANEL=""
204
205if [ "$INSTALL" != "VS" ]; then
206 if [ -f /etc/init.d/psa ]; then
207 OTHER_PANEL="Plesk"
208 elif [ -f /usr/local/vesta/bin/v-change-user-password ]; then
209 OTHER_PANEL="VestaCP"
210 elif [ -d /root/confixx ]; then
211 OTHER_PANEL="Confixx"
212 elif [ -d /var/www/froxlor ]; then
213 OTHER_PANEL="Froxlor"
214 elif [ -d /etc/imscp ]; then
215 OTHER_PANEL="i-MSCP"
216 elif [ -d /usr/local/ispconfig ]; then
217 OTHER_PANEL="ISPConfig"
218 elif [ -d /var/cpanel ]; then
219 OTHER_PANEL="cPanel"
220 elif [ -d /usr/local/directadmin ]; then
221 OTHER_PANEL="DirectAdmin"
222 fi
223fi
224
225if [ "$OTHER_PANEL" != "" ]; then
226 if [ "$INSTALL" == "GS" ]; then
227 yellowMessage " "
228 yellowMessage "Warning an installation of the control panel $OTHER_PANEL has been detected."
229 yellowMessage "If you continue the installer might end up breaking $OTHER_PANEL or same parts of Easy-WI might not work."
230 OPTIONS=("Continue" "Quit")
231 select UPDATE_UPGRADE_SYSTEM in "${OPTIONS[@]}"; do
232 case "$REPLY" in
233 1 ) break;;
234 2 ) errorAndQuit;;
235 *) errorAndContinue;;
236 esac
237 done
238 else
239 errorAndExit "Aborting as the risk of breaking the installed panel $OTHER_PANEL is too high."
240 fi
241fi
242
243# Run the domain/IP check up front to avoid late error out.
244if [ "$INSTALL" == "EW" ]; then
245
246 cyanMessage " "
247 cyanMessage "At which URL/Domain should Easy-Wi be placed?"
248 OPTIONS=("$HOST_NAME" "$LOCAL_IP" "Other" "Quit")
249 select OPTION in "${OPTIONS[@]}"; do
250 case "$REPLY" in
251 1|2|3 ) break;;
252 4 ) errorAndQuit;;
253 *) errorAndContinue;;
254 esac
255 done
256
257 if [ "$OPTION" == "Other" ]; then
258 cyanMessage " "
259 cyanMessage "Please specify the IP or domain Easy-Wi should run at."
260 read IP_DOMAIN
261 else
262 IP_DOMAIN=$OPTION
263 fi
264
265 if [ "`grep -E '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b' <<< $IP_DOMAIN`" == "" -a "`grep -E '^(([a-zA-Z](-?[a-zA-Z0-9])*)\.)*[a-zA-Z](-?[a-zA-Z0-9])+\.[a-zA-Z]{2,}$' <<< $IP_DOMAIN`" == "" ]; then
266 errorAndExit "Error: $IP_DOMAIN is neither a domain nor an IPv4 address!"
267 fi
268fi
269
270# Run the TS3 server version detect up front to avoid user executing steps first and fail at download last.
271if [ "$INSTALL" == "VS" ]; then
272
273 if [ "$MACHINE" == "x86_64" ]; then
274 ARCH="amd64"
275 elif [ "$MACHINE" == "i386" ]||[ "$MACHINE" == "i686" ]; then
276 ARCH="x86"
277 else
278 errorAndExit "$MACHINE is not supported!"
279 fi
280
281 okAndSleep "Searching latest build for hardware type $MACHINE with arch $ARCH."
282
283 for VERSION in `curl -s "http://dl.4players.de/ts/releases/?C=M;O=D" | grep -Po '(?<=href=")[0-9]+(\.[0-9]+){2,3}(?=/")' | sort -Vr`; do
284
285 DOWNLOAD_URL_VERSION="http://dl.4players.de/ts/releases/$VERSION/teamspeak3-server_linux_$ARCH-$VERSION.tar.bz2"
286 STATUS=`curl -I $DOWNLOAD_URL_VERSION 2>&1 | grep "HTTP/" | awk '{print $2}'`
287
288 if [ "$STATUS" == "200" ]; then
289 DOWNLOAD_URL=$DOWNLOAD_URL_VERSION
290 break
291 fi
292 done
293
294 if [ "$STATUS" == "200" -a "$DOWNLOAD_URL" != "" ]; then
295 okAndSleep "Detected latest server version as $VERSION with download URL $DOWNLOAD_URL"
296 else
297 errorAndExit "Could not detect latest server version"
298 fi
299fi
300
301# If we need to install and configure a webspace than we need to identify the groupID
302if [ "$INSTALL" == "EW" -o "$INSTALL" == "WR" ]; then
303
304 WEBGROUPID=`getent group www-data | awk -F ':' '{print $3}'`
305
306 if [ "$INSTALL" == "EW" ]; then
307 OPTION="Yes"
308 else
309 cyanMessage " "
310 cyanMessage "Found group www-data with group ID $WEBGROUPID. Use as webservergroup?"
311
312 OPTIONS=("Yes" "No" "Quit")
313 select OPTION in "${OPTIONS[@]}"; do
314 case "$REPLY" in
315 1|2 ) break;;
316 3 ) errorAndQuit;;
317 *) errorAndContinue;;
318 esac
319 done
320 fi
321
322 if [ "$OPTION" == "No" ]; then
323
324 cyanMessage "Please name the group you want to use as webservergroup"
325 read WEBGROUP
326
327 WEBGROUPID=`getent group $WEBGROUP | awk -F ':' '{print $3}'`
328
329 if [ "$WEBGROUPID" == "" ]; then
330 $GROUPADD $WEBGROUP
331 WEBGROUPID=`getent group $WEBGROUP | awk -F ':' '{print $3}'`
332 fi
333 fi
334
335 if [ "$WEBGROUPID" == "" ]; then
336 errorAndExit "Fatal Error: missing webservergroup ID"
337 fi
338fi
339
340if [ "$INSTALL" != "MY" ]; then
341
342 cyanMessage "Please enter the name of the masteruser. If it does not exists, the installer will create it."
343 read MASTERUSER
344
345 if [ "$MASTERUSER" == "" ]; then
346 errorAndExit "Fatal Error: No masteruser specified"
347 fi
348
349 if [ "`id $MASTERUSER 2> /dev/null`" == "" ]; then
350
351 if [ "$INSTALL" == "EW" -o "$INSTALL" == "WR" ]; then
352 $USERADD -m -b /home -s /bin/bash -g $WEBGROUPID $MASTERUSER
353 else
354
355 if [ -d /home/$MASTERUSER ]; then
356 $GROUPADD $MASTERUSER
357 $USERADD -d /home/$MASTERUSER -s /bin/bash -g $MASTERUSER $MASTERUSER
358 else
359 $GROUPADD $MASTERUSER
360 $USERADD -m -b /home -s /bin/bash -g $MASTERUSER $MASTERUSER
361 fi
362 fi
363
364 elif [ "$INSTALL" != "VS" -a "$INSTALL" != "MY" ]; then
365
366 okAndSleep "User \"$MASTERUSER\" found setting group \"$MASTERUSER\" as mastegroup"
367
368 if [ "$INSTALL" == "EW" -o "$INSTALL" == "WR" ]; then
369 $USERMOD -G $WEBGROUPID $MASTERUSER
370 else
371
372 if [ "`getent group $MASTERUSER`" == "" ]; then
373 $GROUPADD $MASTERUSER
374 fi
375
376 $USERMOD -G $MASTERUSER $MASTERUSER
377 fi
378 else
379 okAndSleep "User \"$MASTERUSER\" already exists."
380 fi
381
382 cyanMessage " "
383 cyanMessage "Create key or set password for login?"
384 cyanMessage "Safest way of login is a password protected key."
385
386 if [ "$INSTALL" == "EW" ]; then
387 cyanMessage "Neither is not required, when installing Easy-WI Webpanel."
388 fi
389
390 OPTIONS=("Create key" "Set password" "Skip" "Quit")
391 select OPTION in "${OPTIONS[@]}"; do
392 case "$REPLY" in
393 1|2|3 ) break;;
394 4 ) errorAndQuit;;
395 *) errorAndContinue;;
396 esac
397 done
398
399 if [ "$OPTION" == "Create key" ]; then
400
401 if [ -d /home/$MASTERUSER/.ssh ]; then
402 rm -rf /home/$MASTERUSER/.ssh
403 mkdir -p /home/$MASTERUSER/.ssh
404 chown $MASTERUSER:$MASTERUSER /home/$MASTERUSER/.ssh
405 fi
406
407 cyanMessage " "
408 cyanMessage "It is recommended but not required to set a password"
409 su -c "ssh-keygen -t rsa" $MASTERUSER
410
411 cd /home/$MASTERUSER/.ssh
412
413 KEYNAME=`find -maxdepth 1 -name "*.pub" | head -n 1`
414
415 if [ "$KEYNAME" != "" ]; then
416 su -c "cat $KEYNAME >> authorized_keys" $MASTERUSER
417 else
418 redMessage "Error: could not find a key. You might need to create one manually at a later point."
419 fi
420
421 elif [ "$OPTION" == "Set password" ]; then
422 passwd $MASTERUSER
423 fi
424fi
425
426# only in case we want to manage webspace we need the additional skel dir
427if [ "$INSTALL" == "WR" -o "$INSTALL" == "EW" ]; then
428 makeDir /home/$MASTERUSER/sites-enabled/
429 makeDir /home/$MASTERUSER/skel/htdocs
430 makeDir /home/$MASTERUSER/skel/logs
431 makeDir /home/$MASTERUSER/skel/session
432 makeDir /home/$MASTERUSER/skel/tmp
433fi
434
435if [ "$INSTALL" == "EW" -o "$INSTALL" == "WR" -o "$INSTALL" == "MY" ]; then
436
437 if [ "$OS" == "debian" -a "$INSTALL" != "MY" ]; then
438
439 cyanMessage " "
440 cyanMessage "Use dotdeb.org repository for more up to date server and PHP versions?"
441
442 OPTIONS=("Yes" "No" "Quit")
443 select DOTDEB in "${OPTIONS[@]}"; do
444 case "$REPLY" in
445 1|2 ) break;;
446 3 ) errorAndQuit;;
447 *) errorAndContinue;;
448 esac
449 done
450
451 if [ "$DOTDEB" == "Yes" ]; then
452 if [ "`grep 'packages.dotdeb.org' /etc/apt/sources.list`" == "" ]; then
453
454 okAndSleep "Adding entries to /etc/apt/sources.list"
455
456 if [ "$OSBRANCH" == "squeeze" -o "$OSBRANCH" == "wheezy" ]; then
457 checkInstall python-software-properties
458 elif [ "$OSBRANCH" == "jessie" ]; then
459 checkInstall software-properties-common
460 fi
461
462 add-apt-repository "deb http://packages.dotdeb.org $OSBRANCH all"
463 add-apt-repository "deb-src http://packages.dotdeb.org $OSBRANCH all"
464 curl --remote-name http://www.dotdeb.org/dotdeb.gpg
465 apt-key add dotdeb.gpg
466 removeIfExists dotdeb.gpg
467 apt-get update
468 fi
469 fi
470 fi
471
472 if [ "$INSTALL" != "MY" ]; then
473 cyanMessage " "
474 cyanMessage "Please select the webserver you would like to use"
475 fi
476
477 if [ "$INSTALL" == "EW" ]; then
478
479 cyanMessage "Apache is recommended in case you want to run additional sites on this host."
480 cyanMessage "Nginx is recommended if the server should only run the Easy-WI Web Panel."
481
482 OPTIONS=("Nginx" "Apache" "Quit")
483 select WEBSERVER in "${OPTIONS[@]}"; do
484 case "$REPLY" in
485 1|2 ) break;;
486 3 ) errorAndQuit;;
487 *) errorAndContinue;;
488 esac
489 done
490
491 elif [ "$INSTALL" != "MY" ]; then
492
493 cyanMessage "Nginx is recommended for FastDL and few but high efficient vhosts"
494 cyanMessage "Apache is recommended in case you want to run many PHP supporting Vhosts aka mass web hosting"
495
496 OPTIONS=("Nginx" "Apache" "Lighttpd" "None" "Quit")
497 select WEBSERVER in "${OPTIONS[@]}"; do
498 case "$REPLY" in
499 1|2|3|4 ) break;;
500 5 ) errorAndQuit;;
501 *) errorAndContinue;;
502 esac
503 done
504 fi
505
506 if [ "$WEBSERVER" == "Nginx" -a "$INSTALL" != "MY" ]; then
507 checkInstall nginx-full
508 elif [ "$WEBSERVER" == "Lighttpd" -a "$INSTALL" != "MY" ]; then
509 checkInstall lighttpd
510 elif [ "$WEBSERVER" == "Apache" -a "$INSTALL" != "MY" ]; then
511 checkInstall apache2
512 fi
513
514 if [ "$INSTALL" == "EW" ]; then
515
516 okAndSleep "Please note that Easy-Wi requires a MySQL or MariaDB installed and will install MySQL if no DB is installed"
517
518 if [ "`ps ax | grep mysql | grep -v grep`" == "" ]; then
519 SQL="MySQL"
520 else
521 SQL=""
522 fi
523
524 else
525
526 cyanMessage " "
527 cyanMessage "Please select if an which database server to install."
528 cyanMessage "Select \"None\" in case this server should host only Fastdownload webspace."
529
530 OPTIONS=("MySQL" "MariaDB" "None" "Quit")
531 select SQL in "${OPTIONS[@]}"; do
532 case "$REPLY" in
533 1|2|3 ) break;;
534 4 ) errorAndQuit;;
535 *) errorAndContinue;;
536 esac
537 done
538 fi
539
540 if [ "$SQL" == "MySQL" -o "$SQL" == "MariaDB" ]; then
541 if [ "`ps fax | grep 'mysqld' | grep -v 'grep'`" ]; then
542
543 cyanMessage " "
544 cyanMessage "Please provide the root password for the MySQL Database."
545 read MYSQL_ROOT_PASSWORD
546
547 mysql -uroot -p$MYSQL_ROOT_PASSWORD -e exit 2> /dev/null
548 ERROR_CODE=$?
549
550 until [ $ERROR_CODE == 0 ]; do
551
552 cyanMessage "Password incorrect, please provide the root password for the MySQL Database."
553 read MYSQL_ROOT_PASSWORD
554
555 mysql -uroot -p$MYSQL_ROOT_PASSWORD -e exit 2> /dev/null
556 ERROR_CODE=$?
557 done
558
559 else
560 until [ "$MYSQL_ROOT_PASSWORD" != "" ]; do
561 cyanMessage "Please provide the root password for the MySQL Database."
562 read MYSQL_ROOT_PASSWORD
563 done
564 fi
565
566 export DEBIAN_FRONTEND="noninteractive"
567 echo "mysql-server mysql-server/root_password password $MYSQL_ROOT_PASSWORD" | debconf-set-selections
568 echo "mysql-server mysql-server/root_password_again password $MYSQL_ROOT_PASSWORD" | debconf-set-selections
569 fi
570
571 if [ "$SQL" == "MySQL" ]; then
572
573 apt-get install mysql-server mysql-client mysql-common -y
574
575 elif [ "$SQL" == "MariaDB" ]; then
576
577 RUNUPDATE=0
578
579 if ([ "`printf "${OSVERSION}\n8.0" | sort -V | tail -n 1`" == "8.0" -o "$OS" == "ubuntu" ] && [ "`grep '/mariadb/' /etc/apt/sources.list`" == "" ]); then
580
581 checkInstall python-software-properties
582 apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xcbcb082a1bb943db
583
584 if [ "$SQL" == "MariaDB" -a "`apt-cache search mariadb-server-10.0`" == "" ]; then
585 if [ "$OS" == "debian" ]; then
586 add-apt-repository "deb http://mirror.netcologne.de/mariadb/repo/10.0/debian $OSBRANCH main"
587 RUNUPDATE=1
588 elif [ "$OS" == "ubuntu" ]; then
589 add-apt-repository "deb http://mirror.netcologne.de/mariadb/repo/10.0/ubuntu $OSBRANCH main"
590 RUNUPDATE=1
591 fi
592 fi
593 fi
594
595 if [ "$OS" == "debian" -a "$DOTDEB" == "Yes" ]; then
596 echo "Package: *" > /etc/apt/preferences.d/mariadb.pref
597 echo "Pin: origin mirror.netcologne.de" >> /etc/apt/preferences.d/mariadb.pref
598 echo "Pin-Priority: 1000" >> /etc/apt/preferences.d/mariadb.pref
599 RUNUPDATE=1
600 fi
601
602 if [ "$RUNUPDATE" == "1" ]; then
603 apt-get update
604 fi
605
606 if ([ "`printf "${OSVERSION}\n8.0" | sort -V | tail -n 1`" == "8.0" -o "$OS" == "ubuntu" ] && [ "`grep '/mariadb/' /etc/apt/sources.list`" == "" ]); then
607 apt-get install mariadb-server mariadb-client mysql-common -y
608 else
609 apt-get install mariadb-server mariadb-client mariadb-common -y
610 fi
611 fi
612
613 if [ "$SQL" == "MySQL" -o "$SQL" == "MariaDB" ]; then
614
615 if [ "$INSTALL" == "WR" -o "$INSTALL" == "MY" ]; then
616
617 cyanMessage " "
618 cyanMessage "Is Easy-WI installed on a different server."
619
620 OPTIONS=("Yes" "No" "Quit")
621 select EXTERNAL_INSTALL in "${OPTIONS[@]}"; do
622 case "$REPLY" in
623 1|2 ) break;;
624 3 ) errorAndQuit;;
625 *) errorAndContinue;;
626 esac
627 done
628 fi
629
630 cyanMessage " "
631 okAndSleep "Securing MySQL by running \"mysql_secure_installation\" commands."
632 mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "DELETE FROM mysql.user WHERE User=''" 2> /dev/null
633 mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1')" 2> /dev/null
634 mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\_%'" 2> /dev/null
635 mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "FLUSH PRIVILEGES" 2> /dev/null
636 fi
637
638 if [ "$EXTERNAL_INSTALL" == "Yes" ]; then
639
640 mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "GRANT USAGE ON *.* TO 'root'@'' IDENTIFIED BY '$MYSQL_ROOT_PASSWORD' WITH MAX_QUERIES_PER_HOUR 0 MAX_CONNECTIONS_PER_HOUR 0 MAX_UPDATES_PER_HOUR 0 MAX_USER_CONNECTIONS 0" 2> /dev/null
641 mysql -u root -p"$MYSQL_ROOT_PASSWORD" -e "UPDATE mysql.user SET Select_priv='Y',Insert_priv='Y',Update_priv='Y',Delete_priv='Y',Create_priv='Y',Drop_priv='Y',Reload_priv='Y',Shutdown_priv='Y',Process_priv='Y',File_priv='Y',Grant_priv='Y',References_priv='Y',Index_priv='Y',Alter_priv='Y',Show_db_priv='Y',Super_priv='Y',Create_tmp_table_priv='Y',Lock_tables_priv='Y',Execute_priv='Y',Repl_slave_priv='Y',Repl_client_priv='Y',Create_view_priv='Y',Show_view_priv='Y',Create_routine_priv='Y',Alter_routine_priv='Y',Create_user_priv='Y',Event_priv='Y',Trigger_priv='Y',Create_tablespace_priv='Y' WHERE User='root' AND Host=''" 2> /dev/null
642
643 if [ "$LOCAL_IP" == "" ]; then
644
645 cyanMessage " "
646 cyanMessage "Could not detect lokal IP. Please specify which to use."
647 read LOCAL_IP
648 fi
649
650 if [ "$LOCAL_IP" != "" -a -f /etc/mysql/my.cnf ]; then
651 if [ "`grep 'bind-address' /etc/mysql/my.cnf`" ]; then
652 sed -i "s/bind-address.*/bind-address = 0.0.0.0/g" /etc/mysql/my.cnf
653 else
654 echo "bind-address = 0.0.0.0" >> /etc/mysql/my.cnf
655 fi
656 fi
657 fi
658
659 MYSQL_VERSION=`mysql -V | awk {'print $5'} | tr -d ,`
660
661 if [ "`grep -E 'key_buffer[[:space:]]*=' /etc/mysql/my.cnf`" != "" -a "printf "${MYSQL_VERSION}\n5.5" | sort -V | tail -n 1" != 5.5 ]; then
662 sed -i "s/key_buffer[[:space:]]*=/key_buffer_size = /g" /etc/mysql/my.cnf
663 fi
664
665 /etc/init.d/mysql restart
666
667 if [ "$INSTALL" == "EW" -a "`ps ax | grep mysql | grep -v grep`" == "" ]; then
668 cyanMessage " "
669 errorAndExit "Error: No SQL server running but required for Webpanel installation."
670 fi
671
672 if [ "$INSTALL" == "EW" ]; then
673
674 okAndSleep "Please note that Easy-Wi will install required PHP packages."
675 PHPINSTALL="Yes"
676
677 elif [ "$INSTALL" != "MY" ]; then
678
679 cyanMessage " "
680 cyanMessage "Install/Update PHP?"
681 cyanMessage "Select \"None\" in case this server should host only Fastdownload webspace."
682
683 OPTIONS=("Yes" "No" "None" "Quit")
684 select PHPINSTALL in "${OPTIONS[@]}"; do
685 case "$REPLY" in
686 1|2|3 ) break;;
687 4 ) errorAndQuit;;
688 *) errorAndContinue;;
689 esac
690 done
691 fi
692
693 if [ "$PHPINSTALL" == "Yes" ]; then
694
695 USE_PHP_VERSION='5'
696
697 if [ "$OS" == "ubuntu" -a "`printf "${OSVERSION}\n16.03" | sort -V | tail -n 1`" != "16.03" ]; then
698 USE_PHP_VERSION='7.0'
699 fi
700
701 if [ "$OS" == "debian" -a "$DOTDEB" == "Yes" ]; then
702
703 cyanMessage " "
704
705 if [ "$OSBRANCH" == "wheezy" ]; then
706
707 cyanMessage "Which PHP version should be used?"
708
709 OPTIONS=("5.4" "5.5", "5.6", "5.6 Zend thread safety" "Quit")
710 select DOTDEBPHPUPGRADE in "${OPTIONS[@]}"; do
711 case "$REPLY" in
712 1|2|3|4 ) break;;
713 5 ) errorAndQuit;;
714 *) errorAndContinue;;
715 esac
716 done
717
718 if [ "$DOTDEBPHPUPGRADE" == "5.5" -a "`grep 'wheezy-php55' /etc/apt/sources.list`" == "" ]; then
719 add-apt-repository "deb http://packages.dotdeb.org wheezy-php55 all"
720 add-apt-repository "deb-src http://packages.dotdeb.org wheezy-php55 all"
721 elif [ "$DOTDEBPHPUPGRADE" == "5.6" -a "`grep 'wheezy-php56' /etc/apt/sources.list`" == "" ]; then
722 add-apt-repository "deb http://packages.dotdeb.org wheezy-php56 all"
723 add-apt-repository "deb-src http://packages.dotdeb.org wheezy-php56 all"
724 elif [ "$DOTDEBPHPUPGRADE" == "5.6 Zend thread safety" -a "`grep 'wheezy-php56-zts' /etc/apt/sources.list`" == "" ]; then
725 add-apt-repository "deb http://packages.dotdeb.org wheezy-php56-zts all"
726 add-apt-repository "deb-src http://packages.dotdeb.org wheezy-php56-zts all"
727 fi
728
729 elif [ "$OSBRANCH" == "squeeze" -a "`grep 'squeeze-php54' /etc/apt/sources.list`" == "" ]; then
730 add-apt-repository "deb http://packages.dotdeb.org squeeze-php54 all"
731 add-apt-repository "deb-src http://packages.dotdeb.org squeeze-php54 all"
732 fi
733
734 if [ "$DOTDEBPHPUPGRADE" == "Yes" ]; then
735 apt-get update
736 apt-get upgrade -y && apt-get dist-upgrade -y
737 fi
738 fi
739
740 checkInstall php${USE_PHP_VERSION}-common
741 checkInstall php${USE_PHP_VERSION}-curl
742 checkInstall php${USE_PHP_VERSION}-gd
743 checkInstall php${USE_PHP_VERSION}-mcrypt
744 checkInstall php${USE_PHP_VERSION}-mysql
745 checkInstall php${USE_PHP_VERSION}-cli
746
747 if [ "$WEBSERVER" == "Nginx" -o "$WEBSERVER" == "Lighttpd" ]; then
748
749 checkInstall php${USE_PHP_VERSION}-fpm
750
751 if [ "$WEBSERVER" == "Lighttpd" ]; then
752 lighttpd-enable-mod fastcgi
753 lighttpd-enable-mod fastcgi-php
754 fi
755
756 makeDir /home/$MASTERUSER/fpm-pool.d/
757 sed -i "s/include=\/etc\/php5\/fpm\/pool.d\/\*.conf/include=\/home\/$MASTERUSER\/fpm-pool.d\/\*.conf/g" /etc/php5/fpm/php-fpm.conf
758 sed -i "s/include=\/etc\/php/7.0\/fpm\/pool.d\/\*.conf/include=\/home\/$MASTERUSER\/fpm-pool.d\/\*.conf/g" /etc/php/7.0/fpm/php-fpm.conf
759
760 elif [ "$WEBSERVER" == "Apache" ]; then
761 checkInstall apache2-mpm-itk
762 checkInstall libapache2-mpm-itk
763 checkInstall libapache2-mod-php${USE_PHP_VERSION}
764 checkInstall php${USE_PHP_VERSION}
765 a2enmod php${USE_PHP_VERSION}
766 fi
767
768 #In case of php 7 the socket is different
769 PHP_VERSION=`php -v | grep -E '^PHP' | awk '{print $2}' | awk -F '.' '{print $1}'`
770 PHP_SOCKET="/var/run/php${PHP_VERSION}-fpm-${FILE_NAME}.sock"
771 fi
772fi
773
774if ([ "$INSTALL" == "WR" -o "$INSTALL" == "EW" ] && [ "`grep '/bin/false' /etc/shells`" == "" ]); then
775 echo "/bin/false" >> /etc/shells
776fi
777
778if [ "$INSTALL" != "VS" -a "$INSTALL" != "EW" -a "$INSTALL" != "MY" ]; then
779
780 cyanMessage " "
781 cyanMessage "Install/Update ProFTPD?"
782
783 OPTIONS=("Yes" "No" "Quit")
784 select OPTION in "${OPTIONS[@]}"; do
785 case "$REPLY" in
786 1|2 ) break;;
787 3 ) errorAndQuit;;
788 *) errorAndContinue;;
789 esac
790 done
791
792 if [ "$OPTION" == "Yes" ]; then
793
794 echo "proftpd-basic shared/proftpd/inetd_or_standalone select standalone" | debconf-set-selections
795 apt-get install proftpd -y
796
797 if [ -f /etc/proftpd/modules.conf ]; then
798
799 backUpFile /etc/proftpd/modules.conf
800
801 sed -i 's/.*LoadModule mod_tls_memcache.c.*/#LoadModule mod_tls_memcache.c/g' /etc/proftpd/modules.conf
802 fi
803
804 backUpFile /etc/proftpd/proftpd.conf
805
806 sed -i 's/.*UseIPv6.*/UseIPv6 off/g' /etc/proftpd/proftpd.conf
807 sed -i 's/#.*DefaultRoot.*~/DefaultRoot ~/g' /etc/proftpd/proftpd.conf
808 sed -i 's/# RequireValidShell.*/RequireValidShell on/g' /etc/proftpd/proftpd.conf
809
810 if [ -f /etc/proftpd/proftpd.conf -a "$INSTALL" != "GS" ]; then
811
812 sed -i 's/Umask.*/Umask 037 027/g' /etc/proftpd/proftpd.conf
813
814 elif [ -f /etc/proftpd/proftpd.conf -a "$INSTALL" == "GS" ]; then
815
816 sed -i 's/Umask.*/Umask 077 077/g' /etc/proftpd/proftpd.conf
817
818 cyanMessage " "
819 cyanMessage "Install/Update ProFTPD Rules?"
820
821 OPTIONS=("Yes" "No" "Quit")
822 select OPTION in "${OPTIONS[@]}"; do
823 case "$REPLY" in
824 1|2 ) break;;
825 3 ) errorAndQuit;;
826 *) errorAndContinue;;
827 esac
828 done
829
830 if [ "$OPTION" == "Yes" -a "`grep '<Directory \/home\/\*\/pserver\/\*>' /etc/proftpd/proftpd.conf`" == "" -a ! -f "/etc/proftpd/conf.d/easy-wi.conf" ]; then
831
832 makeDir /etc/proftpd/conf.d/
833 chmod 755 /etc/proftpd/conf.d/
834
835 echo "
836<Directory ~>
837 HideFiles (^\..+|\.ssh|\.bash_history|\.bash_logout|\.bashrc|\.profile|srcds_run|srcds_linux|hlds_run|hlds_amd|hlds_i686|\.rc|\.sh|\.zip|\.rar|\.7z|\.dll)$
838 PathDenyFilter (^\..+|\.ssh|\.bash_history|\.bash_logout|\.bashrc|\.profile|srcds_run|srcds_linux|hlds_run|hlds_amd|hlds_i686|\.rc|\.sh|\.zip|\.rar|\.7z|\.dll)$
839 HideNoAccess on
840 <Limit RNTO RNFR STOR DELE CHMOD SITE_CHMOD MKD RMD>
841 DenyAll
842 </Limit>
843</Directory>" > /etc/proftpd/conf.d/easy-wi.conf
844 echo "<Directory /home/$MASTERUSER>" >> /etc/proftpd/conf.d/easy-wi.conf
845 echo " HideFiles (^\..+|\.ssh|\.bash_history|\.bash_logout|\.bashrc|\.profile)$
846 PathDenyFilter (^\..+|\.ssh|\.bash_history|\.bash_logout|\.bashrc|\.profile)$
847 HideNoAccess on
848 Umask 137 027
849 <Limit RNTO RNFR STOR DELE CHMOD SITE_CHMOD MKD RMD>
850 AllowAll
851 </Limit>
852</Directory>
853<Directory /home/*/pserver/*>
854 Umask 077 077
855 <Limit RNFR RNTO STOR DELE MKD RMD>
856 AllowAll
857 </Limit>
858</Directory>
859<Directory ~/backup>
860 Umask 177 077
861 <Limit RNTO RNFR STOR DELE>
862 AllowAll
863 </Limit>
864</Directory>
865<Directory ~/*/*/>
866 HideFiles (^\..+|srcds_run|srcds_linux|hlds_run|hlds_amd|hlds_i686|\.rc|\.sh|\.zip|\.rar|\.7z|\.dll)$
867 PathDenyFilter (^\..+|srcds_run|srcds_linux|hlds_run|hlds_amd|hlds_i686|\.rc|\.sh|\.zip|\.rar|\.7z|\.dll)$
868 HideNoAccess on
869</Directory>" >> /etc/proftpd/conf.d/easy-wi.conf
870
871
872 GAMES=("ark" "arma3" "bukkit" "hexxit" "mc" "mtasa" "projectcars" "rust" "samp" "spigot" "teeworlds" "tekkit" "tekkit-classic")
873
874 for GAME in ${GAMES[@]}; do
875 echo "<Directory ~/server/*/$GAME*/*>
876 Umask 077 077
877 <Limit RNFR RNTO STOR DELE MKD RMD>
878 AllowAll
879 </Limit>
880</Directory>" >> /etc/proftpd/conf.d/easy-wi.conf
881 done
882
883 GAME_MODS=("csgo" "cstrike" "czero" "orangebox" "dod" "garrysmod")
884
885 for GAME_MOD in ${GAME_MODS[@]}; do
886 echo "<Directory ~/server/*/*/${GAME_MOD}/*>
887 Umask 077 077
888 <Limit RNFR RNTO STOR DELE MKD RMD>
889 AllowAll
890 </Limit>
891</Directory>" >> /etc/proftpd/conf.d/easy-wi.conf
892 done
893
894 FOLDERS=("addons" "cfg" "maps")
895
896 for FOLDER in ${FOLDERS[@]}; do
897 echo "<Directory ~/*/*/*/*/${FOLDER}>
898 Umask 077 077
899 <Limit RNFR RNTO STOR DELE>
900 AllowAll
901 </Limit>
902</Directory>
903<Directory ~/*/*/*/${FOLDER}>
904 Umask 077 077
905 <Limit RNFR RNTO STOR DELE MKD RMD>
906 AllowAll
907 </Limit>
908</Directory>" >> /etc/proftpd/conf.d/easy-wi.conf
909 done
910 fi
911 fi
912
913 if [ -f /etc/init.d/proftpd ]; then
914 service proftpd restart
915 fi
916 fi
917fi
918
919if [ "$INSTALL" == "GS" -o "$INSTALL" == "WR" ]; then
920
921 cyanMessage " "
922 cyanMessage "Install Quota?"
923
924 OPTIONS=("Yes" "No" "Quit")
925 select QUOTAINSTALL in "${OPTIONS[@]}"; do
926 case "$REPLY" in
927 1|2 ) break;;
928 3 ) errorAndQuit;;
929 *) errorAndContinue;;
930 esac
931 done
932
933 if [ "$QUOTAINSTALL" == "Yes" ]; then
934
935 checkInstall quota
936
937 cyanMessage " "
938 cyanMessage " "
939 removeIfExists /root/tempfstab
940 removeIfExists /root/tempmountpoints
941
942 cat /etc/fstab | while read LINE; do
943 if [[ `echo $LINE | grep '/' | egrep -v '#|boot|proc|swap|floppy|cdrom|usrquota|usrjquota|/sys|/shm|/pts'` ]]; then
944 CURRENTOPTIONS=`echo $LINE | awk '{print $4}'`
945 echo $LINE | sed "s/$CURRENTOPTIONS/$CURRENTOPTIONS,usrjquota=aquota.user,jqfmt=vfsv0/g" >> /root/tempfstab
946 echo $LINE | awk '{print $2}' >> /root/tempmountpoints
947 else
948 echo $LINE >> /root/tempfstab
949 fi
950 done
951
952 cat /root/tempfstab
953
954 cyanMessage " "
955 cyanMessage " "
956 cyanMessage "Please check above output and confirm it is correct. On confirmation the current /etc/fstab will be replaced in order to activate Quotas!"
957
958 OPTIONS=("Yes" "No" "Quit")
959 select QUOTAFSTAB in "${OPTIONS[@]}"; do
960 case "$REPLY" in
961 1|2 ) break;;
962 3 ) errorAndQuit;;
963 *) errorAndContinue;;
964 esac
965 done
966
967 if [ "$QUOTAFSTAB" == "Yes" ]; then
968 backUpFile /etc/fstab
969 mv /root/tempfstab /etc/fstab
970 fi
971
972 removeIfExists /root/tempfstab
973 removeIfExists /aquota.user
974 touch /aquota.user
975 chmod 600 /aquota.user
976
977 if [ -f /root/tempmountpoints ]; then
978
979 cat /root/tempmountpoints | while read LINE; do
980
981 quotaoff -ugv $LINE
982
983 removeIfExists $LINE/aquota.user
984
985 okAndSleep "Remounting $LINE"
986 mount -o remount $LINE
987
988 quotacheck -vumc $LINE
989 quotaon -uv $LINE
990 done
991
992 removeIfExists /root/tempmountpoints
993 fi
994 fi
995fi
996
997if [ "$INSTALL" == "WR" -o "$INSTALL" == "EW" ]; then
998
999 if [ "$WEBSERVER" == "Nginx" ]; then
1000
1001 backUpFile /etc/nginx/nginx.conf
1002
1003 if [ "`grep '/home/$MASTERUSER/sites-enabled/' /etc/nginx/nginx.conf`" == "" ]; then
1004 sed -i "\/etc\/nginx\/sites-enabled\/\*;/a \ \ \ \ \ \ \ \ include \/home\/$MASTERUSER\/sites-enabled\/\*;" /etc/nginx/nginx.conf
1005 fi
1006
1007 elif [ "$WEBSERVER" == "Lighttpd" ]; then
1008
1009 backUpFile /etc/lighttpd/lighttpd.conf
1010 echo "include_shell \"find /home/$MASTERUSER/sites-enabled/ -maxdepth 1 -type f -exec cat {} \;\"" >> /etc/lighttpd/lighttpd.conf
1011
1012 elif [ "$WEBSERVER" == "Apache" ]; then
1013
1014 backUpFile /etc/apache2/apache2.conf
1015
1016 if [ "`grep 'ServerName localhost' /etc/apache2/apache2.conf`" == "" ]; then
1017 echo '# Added to prevent error message Could not reliably determine the servers fully qualified domain name' >> /etc/apache2/apache2.conf
1018 echo 'ServerName localhost' >> /etc/apache2/apache2.conf
1019 fi
1020
1021 APACHE_VERSION=`apache2 -v | grep 'Server version'`
1022
1023 if [ "`grep '/home/$MASTERUSER/sites-enabled/' /etc/apache2/apache2.conf`" == "" ]; then
1024 if [[ $APACHE_VERSION =~ .*Apache/2.2.* ]]; then
1025 sed -i "/Include sites-enabled\//a Include \/home\/$MASTERUSER\/sites-enabled\/" /etc/apache2/apache2.conf
1026 sed -i "/Include \/etc\/apache2\/sites-enabled\//a \/home\/$MASTERUSER\/sites-enabled\/" /etc/apache2/apache2.conf
1027 else
1028 sed -i "/IncludeOptional sites-enabled\//a IncludeOptional \/home\/$MASTERUSER\/sites-enabled\/*.conf" /etc/apache2/apache2.conf
1029 sed -i "/IncludeOptional \/etc\/apache2\/sites-enabled\//a IncludeOptional \/home\/$MASTERUSER\/sites-enabled\/*.conf" /etc/apache2/apache2.conf
1030 fi
1031 fi
1032
1033 okAndSleep "Activating Apache mod_rewrite module."
1034 a2enmod rewrite
1035 a2enmod version 2> /dev/null
1036 fi
1037
1038 #TODO: Logrotate
1039fi
1040
1041# No direct root access for masteruser. Only limited access through sudo
1042if [ "$INSTALL" == "GS" -o "$INSTALL" == "WR" ]; then
1043
1044 checkInstall sudo
1045
1046 if [ -f /etc/sudoers -a "`grep $MASTERUSER /etc/sudoers | grep $USERADD`" == "" ]; then
1047 echo "$MASTERUSER ALL = NOPASSWD: $USERADD" >> /etc/sudoers
1048 fi
1049
1050 if [ -f /etc/sudoers -a "`grep $MASTERUSER /etc/sudoers | grep $USERMOD`" == "" ]; then
1051 echo "$MASTERUSER ALL = NOPASSWD: $USERMOD" >> /etc/sudoers
1052 fi
1053
1054 if [ -f /etc/sudoers -a "`grep $MASTERUSER /etc/sudoers | grep $USERDEL`" == "" ]; then
1055 echo "$MASTERUSER ALL = NOPASSWD: $USERDEL" >> /etc/sudoers
1056 fi
1057
1058 if [ "$QUOTAINSTALL" == "Yes" -a -f /etc/sudoers ]; then
1059 if [ "`grep $MASTERUSER /etc/sudoers | grep setquota`" == "" ]; then
1060 echo "$MASTERUSER ALL = NOPASSWD: `which setquota`" >> /etc/sudoers
1061 fi
1062
1063 if [ "`grep $MASTERUSER /etc/sudoers | grep repquota`" == "" ]; then
1064 echo "$MASTERUSER ALL = NOPASSWD: `which repquota`" >> /etc/sudoers
1065 fi
1066 fi
1067
1068 if [ "$INSTALL" == "GS" -a -f /etc/sudoers -a "`grep $MASTERUSER /etc/sudoers | grep temp`" == "" ]; then
1069 echo "$MASTERUSER ALL = (ALL, !root:easywi) NOPASSWD: /home/$MASTERUSER/temp/*.sh" >> /etc/sudoers
1070 fi
1071
1072 if [ "$WEBSERVER" == "Nginx" ]; then
1073 HTTPDBIN=`which nginx`
1074 HTTPDSCRIPT="/etc/init.d/nginx"
1075 elif [ "$WEBSERVER" == "Lighttpd" ]; then
1076 HTTPDBIN=`which lighttpd`
1077 HTTPDSCRIPT="/etc/init.d/lighttpd"
1078 elif [ "$WEBSERVER" == "Apache" ]; then
1079 HTTPDBIN=`which apache2`
1080 HTTPDSCRIPT="/etc/init.d/apache2"
1081 fi
1082
1083 if [ "$HTTPDBIN" != "" -a -f /etc/sudoers ]; then
1084 if [ "`grep $MASTERUSER /etc/sudoers | grep $HTTPDBIN`" == "" ]; then
1085 echo "$MASTERUSER ALL = NOPASSWD: $HTTPDBIN" >> /etc/sudoers
1086 fi
1087
1088 if [ "`grep $MASTERUSER /etc/sudoers | grep $HTTPDSCRIPT`" == "" ]; then
1089 echo "$MASTERUSER ALL = NOPASSWD: $HTTPDSCRIPT" >> /etc/sudoers
1090 fi
1091 fi
1092fi
1093
1094if [ "$INSTALL" == "WR" ]; then
1095
1096 chown -R $MASTERUSER:$WEBGROUPID /home/$MASTERUSER/
1097
1098 greenMessage "Following data need to be configured at the easy-wi.com panel:"
1099
1100 greenMessage "The path to the folder \"sites-enabled\" is:"
1101 greenMessage "/home/$MASTERUSER/sites-enabled/"
1102
1103 greenMessage "The useradd command is:"
1104 greenMessage "sudo $USERADD %cmd%"
1105
1106 greenMessage "The usermod command is:"
1107 greenMessage "sudo $USERMOD %cmd%"
1108
1109 greenMessage "The userdel command is:"
1110 greenMessage "sudo $USERDEL %cmd%"
1111
1112 greenMessage "The HTTPD restart command is:"
1113 greenMessage "sudo $HTTPDSCRIPT reload"
1114fi
1115
1116if ([ "$INSTALL" == "GS" -o "$INSTALL" == "WR" ] && [ "$QUOTAINSTALL" == "Yes" ]); then
1117 greenMessage "The setquota command is:"
1118 greenMessage "sudo `which setquota` %cmd%"
1119 greenMessage "The repquota command is:"
1120 greenMessage "sudo `which repquota` %cmd%"
1121fi
1122
1123if [ "$INSTALL" == "GS" ]; then
1124
1125 cyanMessage " "
1126 cyanMessage "Java JRE will be required for running Minecraft and its mods. Shall it be installed?"
1127 OPTIONS=("Yes" "No" "Quit")
1128 select OPTION in "${OPTIONS[@]}"; do
1129 case "$REPLY" in
1130 1|2 ) break;;
1131 3 ) errorAndQuit;;
1132 *) errorAndContinue;;
1133 esac
1134 done
1135
1136 if [ "$OPTION" == "Yes" ]; then
1137 checkInstall default-jre
1138 fi
1139
1140 okAndSleep "Creating folders and files"
1141 CREATEDIRS=("conf" "fdl_data/hl2" "logs" "masteraddons" "mastermaps" "masterserver" "temp")
1142 for CREATEDIR in ${CREATEDIRS[@]}; do
1143 greenMessage "Adding dir: /home/$MASTERUSER/$CREATEDIR"
1144 makeDir /home/$MASTERUSER/$CREATEDIR
1145 done
1146
1147 LOGFILES=("addons" "hl2" "server" "fdl" "update" "fdl-hl2")
1148 for LOGFILE in ${LOGFILES[@]}; do
1149 touch "/home/$MASTERUSER/logs/$LOGFILE.log"
1150 done
1151 chmod 660 /home/$MASTERUSER/logs/*.log
1152
1153 chown -R $MASTERUSER:$MASTERUSER /home/$MASTERUSER/
1154 chmod -R 750 /home/$MASTERUSER/
1155 chmod -R 770 /home/$MASTERUSER/logs/ /home/$MASTERUSER/temp/ /home/$MASTERUSER/fdl_data/
1156
1157 if [ "$OS" == "debian" -a "`uname -m`" == "x86_64" -a "`cat /etc/debian_version | grep '6.'`" == "" ]; then
1158 dpkg --add-architecture i386
1159 fi
1160
1161 if [ "$OS" == "debian" -o "$OS" == "ubuntu" ]; then
1162
1163 okAndSleep "Installing required packages wput screen bzip2 sudo rsync zip unzip"
1164 apt-get install wput screen bzip2 sudo rsync zip unzip -y
1165
1166 if [ "`uname -m`" == "x86_64" ]; then
1167
1168 okAndSleep "Installing 32bit support for 64bit systems."
1169
1170 if ([ "$OS" == "ubuntu" ] || [ "$OS" == "debian" -a "`printf "${OSVERSION}\n8.0" | sort -V | tail -n 1`" == "$OSVERSION" ]); then
1171 apt-get install zlib1g lib32z1 lib32gcc1 lib32readline5 lib32ncursesw5 -y
1172 apt-get install lib32stdc++6 -y
1173 apt-get install lib64stdc++6 -y
1174 apt-get install libstdc++6 -y
1175 apt-get install libgcc1:i386 -y
1176 apt-get install libreadline5:i386 -y
1177 apt-get install libncursesw5:i386 -y
1178 apt-get install zlib1g:i386 -y
1179 else
1180 apt-get install ia32-libs lib32readline5 lib32ncursesw5 lib32stdc++6 -y
1181 fi
1182 else
1183 apt-get install libreadline5 libncursesw5 -y
1184 fi
1185 fi
1186
1187 okAndSleep "Downloading SteamCmd"
1188
1189 cd /home/$MASTERUSER/masterserver
1190 makeDir /home/$MASTERUSER/masterserver/steamCMD/
1191 cd /home/$MASTERUSER/masterserver/steamCMD/
1192 curl --remote-name http://media.steampowered.com/client/steamcmd_linux.tar.gz
1193
1194 if [ -f steamcmd_linux.tar.gz ]; then
1195 tar xfvz steamcmd_linux.tar.gz
1196 removeIfExists steamcmd_linux.tar.gz
1197 chown -R $MASTERUSER:$MASTERUSER /home/$MASTERUSER/masterserver/steamCMD
1198 su -c "./steamcmd.sh +login anonymous +quit" $MASTERUSER
1199 if [ -f /home/$MASTERUSER/masterserver/steamCMD/linux32/steamclient.so ]; then
1200 su -c "mkdir -p ~/.steam/sdk32/" $MASTERUSER
1201 su -c "chmod 750 -R ~/.steam/" $MASTERUSER
1202 su -c "ln -s ~/masterserver/steamCMD/linux32/steamclient.so ~/.steam/sdk32/steamclient.so" $MASTERUSER
1203 fi
1204 fi
1205
1206 chown -R $INSTALLMASTER:$INSTALLMASTER /home/$INSTALLMASTER
1207
1208 if [ -f /etc/crontab -a "`grep 'Minecraft can easily produce 1GB' /etc/crontab`" == "" ]; then
1209
1210 if ionice -c3 true 2>/dev/null; then
1211 IONICE="ionice -n 7 "
1212 fi
1213
1214 echo "#Minecraft can easily produce 1GB+ logs within one hour" >> /etc/crontab
1215 echo "*/5 * * * * root nice -n +19 ionice -n 7 find /home/*/server/*/*/ -maxdepth 2 -type f -name \"screenlog.0\" -size +100M -delete" >> /etc/crontab
1216 echo "# Even sudo /usr/sbin/deluser --remove-all-files is used some data remain from time to time" >> /etc/crontab
1217 echo "*/5 * * * * root nice -n +19 $IONICE find /home/ -maxdepth 2 -type d -nouser -delete" >> /etc/crontab
1218 echo "*/5 * * * * root nice -n +19 $IONICE find /home/*/fdl_data/ /home/*/temp/ /tmp/ /var/run/screen/ -nouser -print0 | xargs -0 rm -rf" >> /etc/crontab
1219 echo "*/5 * * * * root nice -n +19 $IONICE find /var/run/screen/ -maxdepth 1 -type d -nouser -print0 | xargs -0 rm -rf" >> /etc/crontab
1220
1221 service cron restart
1222 fi
1223fi
1224
1225if [ "$INSTALL" == "EW" ]; then
1226
1227 makeDir /home/$MASTERUSER/fpm-pool.d/
1228
1229 if [ -f /home/easywi_web/htdocs/serverallocation.php ]; then
1230
1231 cyanMessage " "
1232 cyanMessage "There is already an existing installation. Should it be removed?"
1233 OPTIONS=("Yes" "Quit")
1234 select OPTION in "${OPTIONS[@]}"; do
1235 case "$REPLY" in
1236 1 ) break;;
1237 2 ) errorAndQuit;;
1238 *) errorAndContinue;;
1239 esac
1240 done
1241
1242 rm -rf /home/easywi_web/htdocs/*
1243 fi
1244
1245 if [ "`id easywi_web 2> /dev/null`" == "" -a ! -d /home/easywi_web ]; then
1246 $USERADD -md /home/easywi_web -g www-data -s /bin/bash -k /home/$MASTERUSER/skel/ easywi_web
1247 elif [ "`id easywi_web 2> /dev/null`" == "" -a -d /home/easywi_web ]; then
1248 $USERADD -d /home/easywi_web -g www-data -s /bin/bash easywi_web
1249 fi
1250
1251 makeDir /home/easywi_web/htdocs/
1252 makeDir /home/easywi_web/logs/
1253 makeDir /home/easywi_web/tmp/
1254 makeDir /home/easywi_web/session/
1255 chown -R easywi_web:$WEBGROUPID /home/easywi_web/htdocs/ /home/easywi_web/logs/ /home/easywi_web/tmp/ /home/easywi_web/session/
1256
1257 if [ "`id easywi_web 2> /dev/null`" == "" ]; then
1258 errorAndExit "Web user easywi_web does not exists! Exiting now!"
1259 fi
1260
1261 if [ ! -d /home/easywi_web/htdocs ]; then
1262 errorAndExit "No home/htdocs dir created! Exiting now!"
1263 fi
1264
1265 checkInstall unzip
1266
1267 cd /home/easywi_web/htdocs/
1268
1269 okAndSleep "Downloading latest Easy-WI stable."
1270 curl https://easy-wi.com/uk/downloads/get/3/ -o web.zip
1271
1272 if [ ! -f web.zip ]; then
1273 errorAndExit "Can not download Easy-WI. Aborting!"
1274 fi
1275
1276 okAndSleep "Unpack zipped Easy-WI archive."
1277 unzip -u web.zip >/dev/null 2>&1
1278 removeIfExists web.zip
1279
1280 find /home/easywi_web/ -type f -print0 | xargs -0 chmod 640
1281 find /home/easywi_web/ -mindepth 1 -type d -print0 | xargs -0 chmod 750
1282
1283 chown -R easywi_web:www-data /home/easywi_web
1284
1285 DB_PASSWORD=`< /dev/urandom tr -dc A-Za-z0-9 | head -c18`
1286
1287 okAndSleep "Creating database easy_wi and connected user easy_wi"
1288 mysql -uroot -p$MYSQL_ROOT_PASSWORD -Bse "CREATE DATABASE IF NOT EXISTS easy_wi; GRANT ALL ON easy_wi.* TO 'easy_wi'@'localhost' IDENTIFIED BY '$DB_PASSWORD'; FLUSH PRIVILEGES;"
1289
1290 cyanMessage " "
1291 cyanMessage "Secure Vhost with SSL? (recommended!)"
1292 OPTIONS=("Yes" "No" "Quit")
1293 select SSL in "${OPTIONS[@]}"; do
1294 case "$REPLY" in
1295 1|2 ) break;;
1296 3 ) errorAndQuit;;
1297 *) errorAndContinue;;
1298 esac
1299 done
1300
1301 FILE_NAME=${IP_DOMAIN//./_}
1302
1303 if [ "$SSL" == "Yes" ]; then
1304
1305 checkInstall openssl
1306
1307 if [ "$WEBSERVER" == "Nginx" ]; then
1308 SSL_DIR=/etc/nginx/ssl
1309 elif [ "$WEBSERVER" == "Apache" ]; then
1310 SSL_DIR=/etc/apache2/ssl
1311 fi
1312
1313 makeDir $SSL_DIR
1314
1315 cyanMessage " "
1316 okAndSleep "Creating a self-signed SSL certificate."
1317 openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout $SSL_DIR/$FILE_NAME.key -out $SSL_DIR/$FILE_NAME.crt -subj "/C=/ST=/L=/O=/OU=/CN=$IP_DOMAIN"
1318 fi
1319
1320 if [ "$WEBSERVER" == "Nginx" -o "$WEBSERVER" == "Lighttpd" ]; then
1321
1322 FILE_NAME_POOL=/home/$MASTERUSER/fpm-pool.d/$FILE_NAME.conf
1323
1324 echo "[$IP_DOMAIN]" > $FILE_NAME_POOL
1325 echo "user = easywi_web" >> $FILE_NAME_POOL
1326 echo "group = www-data" >> $FILE_NAME_POOL
1327 echo "listen = ${PHP_SOCKET}" >> $FILE_NAME_POOL
1328 echo "listen.owner = easywi_web" >> $FILE_NAME_POOL
1329 echo "listen.group = www-data" >> $FILE_NAME_POOL
1330 echo "pm = dynamic" >> $FILE_NAME_POOL
1331 echo "pm.max_children = 1" >> $FILE_NAME_POOL
1332 echo "pm.start_servers = 1" >> $FILE_NAME_POOL
1333 echo "pm.min_spare_servers = 1" >> $FILE_NAME_POOL
1334 echo "pm.max_spare_servers = 1" >> $FILE_NAME_POOL
1335 echo "pm.max_requests = 500" >> $FILE_NAME_POOL
1336 echo "chdir = /" >> $FILE_NAME_POOL
1337 echo "access.log = /home/easywi_web/logs/fpm-access.log" >> $FILE_NAME_POOL
1338 echo "php_flag[display_errors] = off" >> $FILE_NAME_POOL
1339 echo "php_admin_flag[log_errors] = on" >> $FILE_NAME_POOL
1340 echo "php_admin_value[error_log] = /home/easywi_web/logs/fpm-error.log" >> $FILE_NAME_POOL
1341 echo "php_admin_value[memory_limit] = 32M" >> $FILE_NAME_POOL
1342 echo "php_admin_value[open_basedir] = /home/easywi_web/htdocs/:/home/easywi_web/tmp/" >> $FILE_NAME_POOL
1343 echo "php_admin_value[upload_tmp_dir] = /home/easywi_web/tmp" >> $FILE_NAME_POOL
1344 echo "php_admin_value[session.save_path] = /home/easywi_web/session" >> $FILE_NAME_POOL
1345
1346 chown $MASTERUSER:www-data $FILE_NAME_POOL
1347 fi
1348
1349 FILE_NAME_VHOST=/home/$MASTERUSER/sites-enabled/$FILE_NAME
1350
1351 if [ "$WEBSERVER" == "Nginx" ]; then
1352 echo 'server {' > $FILE_NAME_VHOST
1353 echo ' listen 80;' >> $FILE_NAME_VHOST
1354
1355 if [ "$SSL" == "Yes" ]; then
1356
1357 echo " server_name $IP_DOMAIN;" >> $FILE_NAME_VHOST
1358 echo " return 301 https://$IP_DOMAIN"'$request_uri;' >> $FILE_NAME_VHOST
1359 echo '}' >> $FILE_NAME_VHOST
1360
1361 backUpFile /etc/nginx/nginx.conf
1362
1363 if [ "`grep 'ssl_ecdh_curve secp384r1;' /etc/nginx/nginx.conf`" == "" ]; then
1364 sed -i '/ssl_prefer_server_ciphers on;/a \\tssl_ecdh_curve secp384r1;' /etc/nginx/nginx.conf
1365 fi
1366 if [ "`grep 'ssl_session_cache' /etc/nginx/nginx.conf`" == "" ]; then
1367 sed -i '/ssl_prefer_server_ciphers on;/a \\tssl_session_cache shared:SSL:10m;' /etc/nginx/nginx.conf
1368 fi
1369 if [ "`grep 'ssl_session_timeout' /etc/nginx/nginx.conf`" == "" ]; then
1370 sed -i '/ssl_prefer_server_ciphers on;/a \\tssl_session_timeout 10m;' /etc/nginx/nginx.conf
1371 fi
1372 if [ "`grep 'ssl_ciphers' /etc/nginx/nginx.conf`" == "" ]; then
1373 sed -i '/ssl_prefer_server_ciphers on;/a \\tssl_ciphers EECDH+AESGCM:EDH+AESGCM:EECDH:EDH:!MD5:!RC4:!LOW:!MEDIUM:!CAMELLIA:!ECDSA:!DES:!DSS:!3DES:!NULL;' /etc/nginx/nginx.conf
1374 fi
1375
1376 echo 'server {' >> $FILE_NAME_VHOST
1377 echo ' listen 443 ssl;' >> $FILE_NAME_VHOST
1378 echo " ssl_certificate /etc/nginx/ssl/$FILE_NAME.crt;" >> $FILE_NAME_VHOST
1379 echo " ssl_certificate_key /etc/nginx/ssl/$FILE_NAME.key;" >> $FILE_NAME_VHOST
1380 fi
1381
1382 echo ' root /home/easywi_web/htdocs/;' >> $FILE_NAME_VHOST
1383 echo ' index index.html index.htm index.php;' >> $FILE_NAME_VHOST
1384 echo " server_name $IP_DOMAIN;" >> $FILE_NAME_VHOST
1385 echo ' location ~ /(keys|stuff|template|languages|downloads|tmp) { deny all; }' >> $FILE_NAME_VHOST
1386 echo ' location / {' >> $FILE_NAME_VHOST
1387 echo ' try_files $uri $uri/ =404;' >> $FILE_NAME_VHOST
1388 echo ' }' >> $FILE_NAME_VHOST
1389 echo ' location ~ \.php$ {' >> $FILE_NAME_VHOST
1390 echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> $FILE_NAME_VHOST
1391 echo ' try_files $fastcgi_script_name =404;' >> $FILE_NAME_VHOST
1392 echo ' set $path_info $fastcgi_path_info;' >> $FILE_NAME_VHOST
1393 echo ' fastcgi_param PATH_INFO $path_info;' >> $FILE_NAME_VHOST
1394 echo ' fastcgi_index index.php;' >> $FILE_NAME_VHOST
1395
1396 if [ -f /etc/nginx/fastcgi.conf ]; then
1397 echo ' include /etc/nginx/fastcgi.conf;' >> $FILE_NAME_VHOST
1398 elif [ -f /etc/nginx/fastcgi_params ]; then
1399 echo ' include /etc/nginx/fastcgi_params;' >> $FILE_NAME_VHOST
1400 fi
1401
1402 echo " fastcgi_pass unix:${PHP_SOCKET};" >> $FILE_NAME_VHOST
1403 echo ' }' >> $FILE_NAME_VHOST
1404 echo '}' >> $FILE_NAME_VHOST
1405
1406 chown -R $MASTERUSER:$WEBGROUPID /home/$MASTERUSER/
1407
1408 okAndSleep "Restarting PHP-FPM and Nginx."
1409 service php${USE_PHP_VERSION}-fpm restart
1410 service nginx restart
1411
1412 elif [ "$WEBSERVER" == "Apache" ]; then
1413
1414 FILE_NAME_VHOST="$FILE_NAME_VHOST.conf"
1415
1416 echo '<VirtualHost *:80>' > $FILE_NAME_VHOST
1417 echo " ServerName $IP_DOMAIN" >> $FILE_NAME_VHOST
1418 echo " ServerAdmin info@$IP_DOMAIN" >> $FILE_NAME_VHOST
1419
1420 if [ "$SSL" == "Yes" ]; then
1421
1422 echo " Redirect permanent / https://$IP_DOMAIN/" >> $FILE_NAME_VHOST
1423 echo '</VirtualHost>' >> $FILE_NAME_VHOST
1424
1425 okAndSleep "Activating TLS/SSL related Apache modules."
1426 a2enmod ssl
1427 service apache2 restart
1428
1429 echo '<VirtualHost *:443>' >> $FILE_NAME_VHOST
1430 echo " ServerName $IP_DOMAIN" >> $FILE_NAME_VHOST
1431 echo ' SSLEngine on' >> $FILE_NAME_VHOST
1432 echo " SSLCertificateFile /etc/apache2/ssl/$FILE_NAME.crt" >> $FILE_NAME_VHOST
1433 echo " SSLCertificateKeyFile /etc/apache2/ssl/$FILE_NAME.key" >> $FILE_NAME_VHOST
1434
1435 fi
1436
1437
1438 echo ' DocumentRoot "/home/easywi_web/htdocs/"' >> $FILE_NAME_VHOST
1439 echo ' ErrorLog "/home/easywi_web/logs/error.log"' >> $FILE_NAME_VHOST
1440 echo ' CustomLog "/home/easywi_web/logs/access.log" common' >> $FILE_NAME_VHOST
1441 echo ' DirectoryIndex index.php index.html' >> $FILE_NAME_VHOST
1442 echo ' <IfModule mpm_itk_module>' >> $FILE_NAME_VHOST
1443 echo ' AssignUserId easywi_web www-data' >> $FILE_NAME_VHOST
1444 echo ' MaxClientsVHost 50' >> $FILE_NAME_VHOST
1445 echo ' NiceValue 10' >> $FILE_NAME_VHOST
1446 echo ' php_admin_flag allow_url_fopen off' >> $FILE_NAME_VHOST
1447 echo ' php_admin_flag allow_url_include off' >> $FILE_NAME_VHOST
1448 echo ' php_admin_flag display_errors off' >> $FILE_NAME_VHOST
1449 echo ' php_admin_flag log_errors on' >> $FILE_NAME_VHOST
1450 echo ' php_admin_flag mod_rewrite on' >> $FILE_NAME_VHOST
1451 echo ' php_admin_value open_basedir "/home/easywi_web/htdocs/:/home/easywi_web/tmp"' >> $FILE_NAME_VHOST
1452 echo ' php_admin_value session.save_path "/home/easywi_web/session"' >> $FILE_NAME_VHOST
1453 echo ' php_admin_value upload_tmp_dir "/home/easywi_web/tmp"' >> $FILE_NAME_VHOST
1454 echo ' php_admin_value upload_max_size 32M' >> $FILE_NAME_VHOST
1455 echo ' php_admin_value memory_limit 32M' >> $FILE_NAME_VHOST
1456 echo ' </IfModule>' >> $FILE_NAME_VHOST
1457 echo ' <Directory /home/easywi_web/htdocs/>' >> $FILE_NAME_VHOST
1458 echo ' Options -Indexes +FollowSymLinks +Includes' >> $FILE_NAME_VHOST
1459 echo ' AllowOverride None' >> $FILE_NAME_VHOST
1460 echo ' <IfVersion >= 2.4>' >> $FILE_NAME_VHOST
1461 echo ' Require all granted' >> $FILE_NAME_VHOST
1462 echo ' </IfVersion>' >> $FILE_NAME_VHOST
1463 echo ' <IfVersion < 2.4>' >> $FILE_NAME_VHOST
1464 echo ' Order allow,deny' >> $FILE_NAME_VHOST
1465 echo ' Allow from all' >> $FILE_NAME_VHOST
1466 echo ' </IfVersion>' >> $FILE_NAME_VHOST
1467 echo ' </Directory>' >> $FILE_NAME_VHOST
1468 echo ' <LocationMatch "/(keys|stuff|template|languages|downloads|tmp)">' >> $FILE_NAME_VHOST
1469 echo ' <IfVersion >= 2.4>' >> $FILE_NAME_VHOST
1470 echo ' Require all denied' >> $FILE_NAME_VHOST
1471 echo ' </IfVersion>' >> $FILE_NAME_VHOST
1472 echo ' <IfVersion < 2.4>' >> $FILE_NAME_VHOST
1473 echo ' Order deny,allow' >> $FILE_NAME_VHOST
1474 echo ' Deny from all' >> $FILE_NAME_VHOST
1475 echo ' </IfVersion>' >> $FILE_NAME_VHOST
1476 echo ' </LocationMatch>' >> $FILE_NAME_VHOST
1477 echo '</VirtualHost>' >> $FILE_NAME_VHOST
1478
1479 okAndSleep "Restarting Apache2."
1480 service apache2 restart
1481 fi
1482
1483 chown $MASTERUSER:www-data $FILE_NAME_VHOST
1484
1485 if [ "`grep reboot.php /etc/crontab`" == "" ]; then
1486 echo '0 */1 * * * easywi_web cd /home/easywi_web/htdocs && timeout 300 php ./reboot.php >/dev/null 2>&1
14870 */1 * * * easywi_web cd /home/easywi_web/htdocs && timeout 300 php ./reboot.php >/dev/null 2>&1
1488*/5 * * * * easywi_web cd /home/easywi_web/htdocs && timeout 290 php ./statuscheck.php >/dev/null 2>&1
1489*/1 * * * * easywi_web cd /home/easywi_web/htdocs && timeout 290 php ./startupdates.php >/dev/null 2>&1
1490*/5 * * * * easywi_web cd /home/easywi_web/htdocs && timeout 290 php ./jobs.php >/dev/null 2>&1
1491*/10 * * * * easywi_web cd /home/easywi_web/htdocs && timeout 290 php ./cloud.php >/dev/null 2>&1' >> /etc/crontab
1492 fi
1493
1494 service cron restart
1495fi
1496
1497if [ "$INSTALL" == "VS" ]; then
1498
1499 ps -u $MASTERUSER | grep ts3server | awk '{print $1}' | while read PID; do
1500 kill $PID
1501 done
1502
1503 if [ -f /home/$MASTERUSER/ts3server_startscript.sh ]; then
1504 rm -rf /home/$MASTERUSER/*
1505 fi
1506
1507 makeDir /home/$MASTERUSER/
1508 chmod 750 /home/$MASTERUSER/
1509 chown -R $MASTERUSER:$MASTERUSER /home/$MASTERUSER
1510
1511 cd /home/$MASTERUSER/
1512
1513 okAndSleep "Downloading TS3 server files."
1514 su -c "curl $DOWNLOAD_URL -o teamspeak3-server.tar.bz2" $MASTERUSER
1515
1516 if [ ! -f teamspeak3-server.tar.bz2 ]; then
1517 errorAndExit "Download failed! Exiting now!"
1518 fi
1519
1520 okAndSleep "Extracting TS3 server files."
1521 su -c "tar -xf teamspeak3-server.tar.bz2 --strip-components=1" $MASTERUSER
1522
1523 removeIfExists teamspeak3-server.tar.bz2
1524
1525 QUERY_WHITLIST_TXT=/home/$MASTERUSER/query_ip_whitelist.txt
1526
1527 if [ ! -f $QUERY_WHITLIST_TXT ]; then
1528 touch $QUERY_WHITLIST_TXT
1529 chown $MASTERUSER:$MASTERUSER $QUERY_WHITLIST_TXT
1530 fi
1531
1532 if [ -f $QUERY_WHITLIST_TXT ]; then
1533
1534 if [ "`grep '127.0.0.1' $QUERY_WHITLIST_TXT`" == "" ]; then
1535 echo "127.0.0.1" >> $QUERY_WHITLIST_TXT
1536 fi
1537
1538 if [ "$LOCAL_IP" != "" ]; then
1539 if [ "`grep -E '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b' <<< $LOCAL_IP`" != "" -a "`grep $LOCAL_IP $QUERY_WHITLIST_TXT`" == "" ]; then
1540 echo $LOCAL_IP >> $QUERY_WHITLIST_TXT
1541 fi
1542 fi
1543
1544 cyanMessage " "
1545 cyanMessage "Please secify the IPv4 address of the Easy-WI web panel."
1546 read IP_ADDRESS
1547
1548 if [ "$IP_ADDRESS" != "" ]; then
1549 if [ "`grep -E '\b((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.|$)){4}\b' <<< $IP_ADDRESS`" != "" -a "`grep $IP_ADDRESS $QUERY_WHITLIST_TXT`" == "" ]; then
1550 echo $IP_ADDRESS >> $QUERY_WHITLIST_TXT
1551 fi
1552 fi
1553 else
1554 redMessage "Cannot edit the file $QUERY_WHITLIST_TXT, please maintain it manually."
1555 fi
1556
1557 QUERY_PASSWORD=`< /dev/urandom tr -dc A-Za-z0-9 | head -c12`
1558
1559 greenMessage "Starting the TS3 server for the first time and shutting it down again as the password will be visible in the process tree."
1560 su -c "./ts3server_startscript.sh start serveradmin_password=$QUERY_PASSWORD createinifile=1 inifile=ts3server.ini" $MASTERUSER
1561 runSpinner 25
1562 su -c "./ts3server_startscript.sh stop" $MASTERUSER
1563
1564 greenMessage "Starting the TS3 server permanently."
1565 su -c "./ts3server_startscript.sh start inifile=ts3server.ini" $MASTERUSER
1566fi
1567
1568okAndSleep "Removing not needed packages."
1569apt-get autoremove -y
1570
1571if [ "$INSTALL" == "EW" ]; then
1572
1573 if [ "$SSL" == "Yes" ]; then
1574 PROTOCOL="https"
1575 else
1576 PROTOCOL="http"
1577 fi
1578
1579 greenMessage "Easy-WI Webpanel setup is done regarding architecture. Please open $PROTOCOL://$IP_DOMAIN/install/install.php and complete the installation dialog."
1580 greenMessage "DB user and table name are \"easy_wi\". The password is \"$DB_PASSWORD\"."
1581
1582elif [ "$INSTALL" == "GS" ]; then
1583 greenMessage "Gameserver Root setup is done. Please enter the above data at the webpanel at \"App/Game Master > Overview > Add\"."
1584elif [ "$INSTALL" == "VS" ]; then
1585 greenMessage "Teamspeak 3 setup is done. TS3 Query password is $QUERY_PASSWORD. Please enter the data at the webpanel at \"Voiceserver > Master > Add\"."
1586elif [ "$INSTALL" == "WR" ]; then
1587 greenMessage "Webspace Root setup is done. Please enter the above data at the webpanel at \"Webspace > Master > Add\"."
1588fi
1589
1590if ([ "$INSTALL" == "MY" ] || [ "$INSTALL" == "WR" -a "$SQL" != "None" ]); then
1591 greenMessage "MySQL Root setup is done. Please enter the server at the webpanel at \"MySQL > Master > Add\"."
1592fi
1593
1594exit 0