· 9 years ago · Mar 31, 2017, 07:34 PM
1#!/usr/bin/env bash
2
3# Official Sentora Automated Installation Script
4# =============================================
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18#
19# Supported Operating Systems: CentOS 6.*/7.* Minimal, Ubuntu server 12.04/14.04
20# 32bit and 64bit
21#
22# Author Pascal Peyremorte (ppeyremorte@sentora.org)
23# (main merge of all installers, modularization, reworks and comments)
24# With huge help and contributions from Mehdi Blagui, Kevin Andrews and
25# all those who participated to this and to previous installers.
26# Thanks to all.
27
28SENTORA_INSTALLER_VERSION="1.0.3"
29SENTORA_CORE_VERSION="1.0.0"
30SENTORA_PRECONF_VERSION="1.0.3"
31
32PANEL_PATH="/etc/sentora"
33PANEL_DATA="/var/sentora"
34
35#--- Display the 'welcome' splash/user warning info..
36echo ""
37echo "############################################################"
38echo "# Welcome to the Official Sentora Installer $SENTORA_INSTALLER_VERSION #"
39echo "############################################################"
40
41echo -e "\nChecking that minimal requirements are ok"
42
43# Ensure the OS is compatible with the launcher
44if [ -f /etc/centos-release ]; then
45 OS="CentOs"
46 VERFULL=$(sed 's/^.*release //;s/ (Fin.*$//' /etc/centos-release)
47 VER=${VERFULL:0:1} # return 6 or 7
48elif [ -f /etc/lsb-release ]; then
49 OS=$(grep DISTRIB_ID /etc/lsb-release | sed 's/^.*=//')
50 VER=$(grep DISTRIB_RELEASE /etc/lsb-release | sed 's/^.*=//')
51else
52 OS=$(uname -s)
53 VER=$(uname -r)
54fi
55ARCH=$(uname -m)
56
57echo "Detected : $OS $VER $ARCH"
58
59if [[ "$OS" = "CentOs" && ("$VER" = "6" || "$VER" = "7" ) ||
60 "$OS" = "Ubuntu" && ("$VER" = "12.04" || "$VER" = "14.04" ) ]] ; then
61 echo "Ok."
62else
63 echo "Sorry, this OS is not supported by Sentora."
64 exit 1
65fi
66
67# Centos uses repo directory that depends of architecture. Ensure it is compatible
68if [[ "$OS" = "CentOs" ]] ; then
69 if [[ "$ARCH" == "i386" || "$ARCH" == "i486" || "$ARCH" == "i586" || "$ARCH" == "i686" ]]; then
70 ARCH="i386"
71 elif [[ "$ARCH" != "x86_64" ]]; then
72 echo "Unexpected architecture name was returned ($ARCH ). :-("
73 echo "The installer have been designed for i[3-6]8- and x86_64' architectures. If you"
74 echo " think it may work on your, please report it to the Sentora forum or bugtracker."
75 exit 1
76 fi
77fi
78
79# Check if the user is 'root' before allowing installation to commence
80if [ $UID -ne 0 ]; then
81 echo "Install failed: you must be logged in as 'root' to install."
82 echo "Use command 'sudo -i', then enter root password and then try again."
83 exit 1
84fi
85
86# Check for some common control panels that we know will affect the installation/operating of Sentora.
87if [ -e /usr/local/cpanel ] || [ -e /usr/local/directadmin ] || [ -e /usr/local/solusvm/www ] || [ -e /usr/local/home/admispconfig ] || [ -e /usr/local/lxlabs/kloxo ] ; then
88 echo "It appears that a control panel is already installed on your server; This installer"
89 echo "is designed to install and configure Sentora on a clean OS installation only."
90 echo -e "\nPlease re-install your OS before attempting to install using this script."
91 exit 1
92fi
93
94# Check for some common packages that we know will affect the installation/operating of Sentora.
95if [[ "$OS" = "CentOs" ]] ; then
96 PACKAGE_INSTALLER="yum -y -q install"
97 PACKAGE_REMOVER="yum -y -q remove"
98
99 inst() {
100 rpm -q "$1" &> /dev/null
101 }
102
103 if [[ "$VER" = "7" ]]; then
104 DB_PCKG="mariadb" && echo "DB server will be mariaDB"
105 else
106 DB_PCKG="mysql" && echo "DB server will be mySQL"
107 fi
108 HTTP_PCKG="httpd"
109 PHP_PCKG="php"
110 BIND_PCKG="bind"
111elif [[ "$OS" = "Ubuntu" ]]; then
112 PACKAGE_INSTALLER="apt-get -yqq install"
113 PACKAGE_REMOVER="apt-get -yqq remove"
114
115 inst() {
116 dpkg -l "$1" 2> /dev/null | grep '^ii' &> /dev/null
117 }
118
119 DB_PCKG="mysql-server"
120 HTTP_PCKG="apache2"
121 PHP_PCKG="apache2-mod-php5"
122 BIND_PCKG="bind9"
123fi
124
125# Note : Postfix is installed by default on centos netinstall / minimum install.
126# The installer seems to work fine even if Postfix is already installed.
127# -> The check of postfix is removed, but this comment remains to remember
128for package in "$DB_PCKG" "dovecot-mysql" "$HTTP_PCKG" "$PHP_PCKG" "proftpd" "$BIND_PCKG" ; do
129 if (inst "$package"); then
130 echo "It appears that package $package is already installed. This installer"
131 echo "is designed to install and configure Sentora on a clean OS installation only!"
132 echo -e "\nPlease re-install your OS before attempting to install using this script."
133 exit 1
134 fi
135done
136
137# *************************************************
138#--- Prepare or query informations required to install
139
140# Update repositories and Install wget and util used to grab server IP
141echo -e "\n-- Installing wget and dns utils required to manage inputs"
142if [[ "$OS" = "CentOs" ]]; then
143 yum -y update
144 $PACKAGE_INSTALLER bind-utils
145elif [[ "$OS" = "Ubuntu" ]]; then
146 apt-get -yqq update #ensure we can install
147 $PACKAGE_INSTALLER dnsutils
148fi
149$PACKAGE_INSTALLER wget
150
151extern_ip="$(wget -qO- http://api.sentora.org/ip.txt)"
152#local_ip=$(ifconfig eth0 | sed -En 's|.*inet [^0-9]*(([0-9]*\.){3}[0-9]*).*$|\1|p')
153local_ip=$(ip addr show | awk '$1 == "inet" && $3 == "brd" { sub (/\/.*/,""); print $2 }')
154
155# Enable parameters to be entered on commandline, required for vagrant install
156# -d <panel-domain>
157# -i <server-ip> (or -i local or -i public, see below)
158# -t <timezone-string>
159# like :
160# sentora_install.sh -t Europe/Paris -d panel.domain.tld -i xxx.xxx.xxx.xxx
161# notes:
162# -d and -i must be both present or both absent
163# -i local force use of local detected ip
164# -i public force use of public detected ip
165# if -t is used without -d/-i, timezone is set from value given and not asked to user
166# if -t absent and -d/-i are present, timezone is not set at all
167
168while getopts d:i:t: opt; do
169 case $opt in
170 d)
171 PANEL_FQDN=$OPTARG
172 INSTALL="auto"
173 ;;
174 i)
175 PUBLIC_IP=$OPTARG
176 if [[ "$PUBLIC_IP" == "local" ]] ; then
177 PUBLIC_IP=$local_ip
178 elif [[ "$PUBLIC_IP" == "public" ]] ; then
179 PUBLIC_IP=$extern_ip
180 fi
181 ;;
182 t)
183 echo "$OPTARG" > /etc/timezone
184 tz=$(cat /etc/timezone)
185 ;;
186 esac
187done
188if [[ ("$PANEL_FQDN" != "" && "$PUBLIC_IP" == "") ||
189 ("$PANEL_FQDN" == "" && "$PUBLIC_IP" != "") ]] ; then
190 echo "-d and -i must be both present or both absent."
191 exit 2
192fi
193
194
195if [[ "$tz" == "" && "$PANEL_FQDN" == "" ]] ; then
196 # Propose selection list for the time zone
197 echo "Preparing to select timezone, please wait a few seconds..."
198 $PACKAGE_INSTALLER tzdata
199 # setup server timezone
200 if [[ "$OS" = "CentOs" ]]; then
201 # make tzselect to save TZ in /etc/timezone
202 echo "echo \$TZ > /etc/timezone" >> /usr/bin/tzselect
203 tzselect
204 tz=$(cat /etc/timezone)
205 elif [[ "$OS" = "Ubuntu" ]]; then
206 dpkg-reconfigure tzdata
207 tz=$(cat /etc/timezone)
208 fi
209fi
210# clear timezone information to focus user on important notice
211clear
212
213# Installer parameters
214if [[ "$PANEL_FQDN" == "" ]] ; then
215 echo -e "\n\e[1;33m=== Informations required to build your server ===\e[0m"
216 echo 'The installer requires 2 pieces of information:'
217 echo ' 1) the sub-domain that you want to use to access Sentora panel,'
218 echo ' - do not use your main domain (like domain.com)'
219 echo ' - use a sub-domain, e.g panel.domain.com'
220 echo ' - or use the server hostname, e.g server1.domain.com'
221 echo ' - DNS must already be configured and pointing to the server IP'
222 echo ' for this sub-domain'
223 echo ' 2) The public IP of the server.'
224 echo ''
225
226 PANEL_FQDN="$(/bin/hostname)"
227 PUBLIC_IP=$extern_ip
228 while true; do
229 echo ""
230 read -e -p "Enter the sub-domain you want to access Sentora panel: " -i "$PANEL_FQDN" PANEL_FQDN
231
232 if [[ "$PUBLIC_IP" != "$local_ip" ]]; then
233 echo -e "\nThe public IP of the server is $PUBLIC_IP. Its local IP is $local_ip"
234 echo " For a production server, the PUBLIC IP must be used."
235 fi
236 read -e -p "Enter (or confirm) the public IP for this server: " -i "$PUBLIC_IP" PUBLIC_IP
237 echo ""
238
239 # Checks if the panel domain is a subdomain
240 sub=$(echo "$PANEL_FQDN" | sed -n 's|\(.*\)\..*\..*|\1|p')
241 if [[ "$sub" == "" ]]; then
242 echo -e "\e[1;31mWARNING: $PANEL_FQDN is not a subdomain!\e[0m"
243 confirm="true"
244 fi
245
246 # Checks if the panel domain is already assigned in DNS
247 dns_panel_ip=$(host "$PANEL_FQDN"|grep address|cut -d" " -f4)
248 if [[ "$dns_panel_ip" == "" ]]; then
249 echo -e "\e[1;31mWARNING: $PANEL_FQDN is not defined in your DNS!\e[0m"
250 echo " You must add records in your DNS manager (and then wait until propagation is done)."
251 echo " For more information, read the Sentora documentation:"
252 echo " - http://docs.sentora.org/index.php?node=7 (Installing Sentora)"
253 echo " - http://docs.sentora.org/index.php?node=51 (Installer questions)"
254 echo " If this is a production installation, set the DNS up as soon as possible."
255 confirm="true"
256 else
257 echo -e "\e[1;32mOK\e[0m: DNS successfully resolves $PANEL_FQDN to $dns_panel_ip"
258
259 # Check if panel domain matches public IP
260 if [[ "$dns_panel_ip" != "$PUBLIC_IP" ]]; then
261 echo -e -n "\e[1;31mWARNING: $PANEL_FQDN DNS record does not point to $PUBLIC_IP!\e[0m"
262 echo " Sentora will not be reachable from http://$PANEL_FQDN"
263 confirm="true"
264 fi
265 fi
266
267 if [[ "$PUBLIC_IP" != "$extern_ip" && "$PUBLIC_IP" != "$local_ip" ]]; then
268 echo -e -n "\e[1;31mWARNING: $PUBLIC_IP does not match detected IP !\e[0m"
269 echo " Sentora will not work with this IP..."
270 confirm="true"
271 fi
272
273 echo ""
274 # if any warning, ask confirmation to continue or propose to change
275 if [[ "$confirm" != "" ]] ; then
276 echo "There are some warnings..."
277 echo "Are you really sure that you want to setup Sentora with these parameters?"
278 read -e -p "(y):Accept and install, (n):Change domain or IP, (q):Quit installer? " yn
279 case $yn in
280 [Yy]* ) break;;
281 [Nn]* ) continue;;
282 [Qq]* ) exit;;
283 esac
284 else
285 read -e -p "All is ok. Do you want to install Sentora now (y/n)? " yn
286 case $yn in
287 [Yy]* ) break;;
288 [Nn]* ) exit;;
289 esac
290 fi
291 done
292fi
293
294# ***************************************
295# Installation really starts here
296
297#--- Set custom logging methods so we create a log file in the current working directory.
298logfile=$(date +%Y-%m-%d_%H.%M.%S_sentora_install.log)
299touch "$logfile"
300exec > >(tee "$logfile")
301exec 2>&1
302
303echo "Installer version $SENTORA_INSTALLER_VERSION"
304echo "Sentora core version $SENTORA_CORE_VERSION"
305echo "Sentora preconf version $SENTORA_PRECONF_VERSION"
306echo ""
307echo "Installing Sentora $SENTORA_CORE_VERSION at http://$PANEL_FQDN and ip $PUBLIC_IP"
308echo "on server under: $OS $VER $ARCH"
309uname -a
310
311# Function to disable a file by appending its name with _disabled
312disable_file() {
313 mv "$1" "$1_disabled_by_sentora" &> /dev/null
314}
315
316#--- AppArmor must be disabled to avoid problems
317if [[ "$OS" = "Ubuntu" ]]; then
318 [ -f /etc/init.d/apparmor ]
319 if [ $? = "0" ]; then
320 echo -e "\n-- Disabling and removing AppArmor, please wait..."
321 /etc/init.d/apparmor stop &> /dev/null
322 update-rc.d -f apparmor remove &> /dev/null
323 apt-get remove -y --purge apparmor* &> /dev/null
324 disable_file /etc/init.d/apparmor &> /dev/null
325 echo -e "AppArmor has been removed."
326 fi
327fi
328
329#--- Adapt repositories and packages sources
330echo -e "\n-- Updating repositories and packages sources"
331if [[ "$OS" = "CentOs" ]]; then
332 #EPEL Repo Install
333 EPEL_BASE_URL="http://dl.fedoraproject.org/pub/epel/$VER/$ARCH";
334 if [[ "$VER" = "7" ]]; then
335 EPEL_FILE=$(wget -q -O- "$EPEL_BASE_URL/e/" | grep -oP '(?<=href=")epel-release.*(?=">)')
336 wget "$EPEL_BASE_URL/e/$EPEL_FILE"
337 else
338 EPEL_FILE=$(wget -q -O- "$EPEL_BASE_URL/" | grep -oP '(?<=href=")epel-release.*(?=">)')
339 wget "$EPEL_BASE_URL/$EPEL_FILE"
340 fi
341 $PACKAGE_INSTALLER -y install epel-release*.rpm
342 rm "$EPEL_FILE"
343
344 #To fix some problems of compatibility use of mirror centos.org to all users
345 #Replace all mirrors by base repos to avoid any problems.
346 sed -i 's|mirrorlist=http://mirrorlist.centos.org|#mirrorlist=http://mirrorlist.centos.org|' "/etc/yum.repos.d/CentOS-Base.repo"
347 sed -i 's|#baseurl=http://mirror.centos.org|baseurl=http://mirror.centos.org|' "/etc/yum.repos.d/CentOS-Base.repo"
348
349 #check if the machine and on openvz
350 if [ -f "/etc/yum.repos.d/vz.repo" ]; then
351 sed -i "s|mirrorlist=http://vzdownload.swsoft.com/download/mirrors/centos-$VER|baseurl=http://vzdownload.swsoft.com/ez/packages/centos/$VER/$ARCH/os/|" "/etc/yum.repos.d/vz.repo"
352 sed -i "s|mirrorlist=http://vzdownload.swsoft.com/download/mirrors/updates-released-ce$VER|baseurl=http://vzdownload.swsoft.com/ez/packages/centos/$VER/$ARCH/updates/|" "/etc/yum.repos.d/vz.repo"
353 fi
354
355 #disable deposits that could result in installation errors
356 disablerepo() {
357 if [ -f "/etc/yum.repos.d/$1.repo" ]; then
358 sed -i 's/enabled=1/enabled=0/g' "/etc/yum.repos.d/$1.repo"
359 fi
360 }
361 disablerepo "elrepo"
362 disablerepo "epel-testing"
363 disablerepo "remi"
364 disablerepo "rpmforge"
365 disablerepo "rpmfusion-free-updates"
366 disablerepo "rpmfusion-free-updates-testing"
367
368 # We need to disable SELinux...
369 sed -i 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/selinux/config
370 setenforce 0
371
372 # Stop conflicting services and iptables to ensure all services will work
373 service sendmail stop
374 chkconfig sendmail off
375
376 # disable firewall
377 if [[ "$VER" = "7" ]]; then
378 FIREWALL_SERVICE="firewalld"
379 else
380 FIREWALL_SERVICE="iptables"
381 fi
382 service "$FIREWALL_SERVICE" save
383 service "$FIREWALL_SERVICE" stop
384 chkconfig "$FIREWALL_SERVICE" off
385
386 # Removal of conflicting packages prior to Sentora installation.
387 if (inst bind-chroot) ; then
388 $PACKAGE_REMOVER bind-chroot
389 fi
390 if (inst qpid-cpp-client) ; then
391 $PACKAGE_REMOVER qpid-cpp-client
392 fi
393
394elif [[ "$OS" = "Ubuntu" ]]; then
395 # Update the enabled Aptitude repositories
396 echo -ne "\nUpdating Aptitude Repos: " >/dev/tty
397
398 mkdir -p "/etc/apt/sources.list.d.save"
399 cp -R "/etc/apt/sources.list.d/*" "/etc/apt/sources.list.d.save" &> /dev/null
400 rm -rf "/etc/apt/sources.list/*"
401 cp "/etc/apt/sources.list" "/etc/apt/sources.list.save"
402
403 if [ "$VER" = "14.04" ]; then
404 cat > /etc/apt/sources.list <<EOF
405#Depots main restricted
406deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc) main restricted universe multiverse
407deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-security main restricted universe multiverse
408deb http://archive.ubuntu.com/ubuntu $(lsb_release -sc)-updates main restricted universe multiverse
409EOF
410 else
411 cat > /etc/apt/sources.list <<EOF
412#Depots main restricted
413deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main restricted
414deb http://security.ubuntu.com/ubuntu $(lsb_release -sc)-security main restricted
415deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc)-updates main restricted
416
417deb-src http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main restricted
418deb-src http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc)-updates main restricted
419deb-src http://security.ubuntu.com/ubuntu $(lsb_release -sc)-security main restricted
420
421#Depots Universe Multiverse
422deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) universe multiverse
423deb http://security.ubuntu.com/ubuntu $(lsb_release -sc)-security universe multiverse
424deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc)-updates universe multiverse
425
426deb-src http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) universe multiverse
427deb-src http://security.ubuntu.com/ubuntu $(lsb_release -sc)-security universe multiverse
428deb-src http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc)-updates universe multiverse
429EOF
430 fi
431fi
432
433#--- List all already installed packages (may help to debug)
434echo -e "\n-- Listing of all packages installed:"
435if [[ "$OS" = "CentOs" ]]; then
436 rpm -qa | sort
437elif [[ "$OS" = "Ubuntu" ]]; then
438 dpkg --get-selections
439fi
440
441#--- Ensures that all packages are up to date
442echo -e "\n-- Updating+upgrading system, it may take some time..."
443if [[ "$OS" = "CentOs" ]]; then
444 yum -y update
445 yum -y upgrade
446elif [[ "$OS" = "Ubuntu" ]]; then
447 apt-get -yqq update
448 apt-get -yqq upgrade
449fi
450
451#--- Install utility packages required by the installer and/or Sentora.
452echo -e "\n-- Downloading and installing required tools..."
453if [[ "$OS" = "CentOs" ]]; then
454 $PACKAGE_INSTALLER sudo vim make zip unzip chkconfig bash-completion
455 $PACKAGE_INSTALLER ld-linux.so.2 libbz2.so.1 libdb-4.7.so libgd.so.2
456 $PACKAGE_INSTALLER curl curl-devel perl-libwww-perl libxml2 libxml2-devel zip bzip2-devel gcc gcc-c++ at make
457 $PACKAGE_INSTALLER redhat-lsb-core
458elif [[ "$OS" = "Ubuntu" ]]; then
459 $PACKAGE_INSTALLER sudo vim make zip unzip debconf-utils at build-essential bash-completion
460fi
461
462#--- Download Sentora archive from GitHub
463echo -e "\n-- Downloading Sentora, Please wait, this may take several minutes, the installer will continue after this is complete!"
464# Get latest sentora
465while true; do
466 wget -nv -O sentora_core.zip https://github.com/sentora/sentora-core/archive/master.zip
467 if [[ -f sentora_core.zip ]]; then
468 break;
469 else
470 echo "Failed to download sentora core from Github"
471 echo "If you quit now, you can run again the installer later."
472 read -e -p "Press r to retry or q to quit the installer? " resp
473 case $resp in
474 [Rr]* ) continue;;
475 [Qq]* ) exit 3;;
476 esac
477 fi
478done
479mkdir -p $PANEL_PATH
480chown -R root:root $PANEL_PATH
481unzip -oq sentora_core.zip -d $PANEL_PATH
482mv "$PANEL_PATH/sentora-core-$SENTORA_CORE_VERSION" "$PANEL_PATH/panel"
483rm sentora_core.zip
484rm "$PANEL_PATH/panel/LICENSE.md" "$PANEL_PATH/panel/README.md" "$PANEL_PATH/panel/.gitignore"
485rm -rf "$PANEL_PATH/_delete_me" "$PANEL_PATH/.gitignore"
486
487# Temp patch
488wget -O hotfix_controller.ext.php "https://raw.githubusercontent.com/sentora/sentora-core/b176df0e29e52e14d778ca6cb47c5765cf3c4953/modules/ftp_management/code/controller.ext.php"
489mv /etc/sentora/panel/modules/ftp_management/code/controller.ext.php controller.ext.php_backup
490mv hotfix_controller.ext.php /etc/sentora/panel/modules/ftp_management/code/controller.ext.php
491chown root:root /etc/sentora/panel/modules/ftp_management/code/controller.ext.php
492chmod 777 /etc/sentora/panel/modules/ftp_management/code/controller.ext.php
493
494
495#--- Set-up Sentora directories and configure permissions
496PANEL_CONF="$PANEL_PATH/configs"
497
498mkdir -p $PANEL_CONF
499mkdir -p $PANEL_PATH/docs
500chmod -R 777 $PANEL_PATH
501
502mkdir -p $PANEL_DATA/backups
503chmod -R 777 $PANEL_DATA/
504
505# Links for compatibility with zpanel access
506ln -s $PANEL_PATH /etc/zpanel
507ln -s $PANEL_DATA /var/zpanel
508
509#--- Prepare Sentora executables
510chmod +x $PANEL_PATH/panel/bin/zppy
511ln -s $PANEL_PATH/panel/bin/zppy /usr/bin/zppy
512
513chmod +x $PANEL_PATH/panel/bin/setso
514ln -s $PANEL_PATH/panel/bin/setso /usr/bin/setso
515
516chmod +x $PANEL_PATH/panel/bin/setzadmin
517ln -s $PANEL_PATH/panel/bin/setzadmin /usr/bin/setzadmin
518
519#--- Install preconfig
520while true; do
521 wget -nv -O sentora_preconfig.zip https://github.com/sentora/sentora-installers/archive/$SENTORA_PRECONF_VERSION.zip
522 if [[ -f sentora_preconfig.zip ]]; then
523 break;
524 else
525 echo "Failed to download sentora preconfig from Github"
526 echo "If you quit now, you can run again the installer later."
527 read -e -p "Press r to retry or q to quit the installer? " resp
528 case $resp in
529 [Rr]* ) continue;;
530 [Qq]* ) exit 3;;
531 esac
532 fi
533done
534
535unzip -oq sentora_preconfig.zip
536cp -rf sentora-installers-$SENTORA_PRECONF_VERSION/preconf/* $PANEL_CONF
537rm sentora_preconfig*
538rm -rf sentora-*
539
540#--- Prepare zsudo
541cc -o $PANEL_PATH/panel/bin/zsudo $PANEL_CONF/bin/zsudo.c
542sudo chown root $PANEL_PATH/panel/bin/zsudo
543chmod +s $PANEL_PATH/panel/bin/zsudo
544
545#--- Resolv.conf protect
546chattr +i /etc/resolv.conf
547
548#--- Prepare hostname
549old_hostname=$(cat /etc/hostname)
550# In file hostname
551echo "$PANEL_FQDN" > /etc/hostname
552
553# In file hosts
554sed -i "/127.0.1.1[\t ]*$old_hostname/d" /etc/hosts
555sed -i "s|$old_hostname|$PANEL_FQDN|" /etc/hosts
556
557# For current session
558hostname "$PANEL_FQDN"
559
560# In network file
561if [[ "$OS" = "CentOs" && "$VER" = "6" ]]; then
562 sed -i "s|^\(HOSTNAME=\).*\$|HOSTNAME=$PANEL_FQDN|" /etc/sysconfig/network
563 /etc/init.d/network restart
564fi
565
566#--- Some functions used many times below
567# Random password generator function
568passwordgen() {
569 l=$1
570 [ "$l" == "" ] && l=16
571 tr -dc A-Za-z0-9 < /dev/urandom | head -c ${l} | xargs
572}
573
574# Add first parameter in hosts file as local IP domain
575add_local_domain() {
576 if ! grep -q "127.0.0.1 $1" /etc/hosts; then
577 echo "127.0.0.1 $1" >> /etc/hosts;
578 fi
579}
580
581#-----------------------------------------------------------
582# Install all softwares and dependencies required by Sentora.
583
584if [[ "$OS" = "Ubuntu" ]]; then
585 # Disable the DPKG prompts before we run the software install to enable fully automated install.
586 export DEBIAN_FRONTEND=noninteractive
587fi
588
589#--- MySQL
590echo -e "\n-- Installing MySQL"
591mysqlpassword=$(passwordgen);
592$PACKAGE_INSTALLER "$DB_PCKG"
593if [[ "$OS" = "CentOs" ]]; then
594 $PACKAGE_INSTALLER "DB_PCKG-devel" "$DB_PCKG-server"
595 MY_CNF_PATH="/etc/my.cnf"
596 if [[ "$VER" = "7" ]]; then
597 DB_SERVICE="mariadb"
598 else
599 DB_SERVICE="mysqld"
600 fi
601elif [[ "$OS" = "Ubuntu" ]]; then
602 $PACKAGE_INSTALLER bsdutils libsasl2-modules-sql libsasl2-modules
603 if [ "$VER" = "12.04" ]; then
604 $PACKAGE_INSTALLER db4.7-util
605 fi
606 MY_CNF_PATH="/etc/mysql/my.cnf"
607 DB_SERVICE="mysql"
608fi
609service $DB_SERVICE start
610
611# setup mysql root password
612mysqladmin -u root password "$mysqlpassword"
613
614# small cleaning of mysql access
615mysql -u root -p"$mysqlpassword" -e "DELETE FROM mysql.user WHERE User='root' AND Host != 'localhost'";
616mysql -u root -p"$mysqlpassword" -e "DELETE FROM mysql.user WHERE User=''";
617mysql -u root -p"$mysqlpassword" -e "FLUSH PRIVILEGES";
618
619# remove test table that is no longer used
620mysql -u root -p"$mysqlpassword" -e "DROP DATABASE IF EXISTS test";
621
622# secure SELECT "hacker-code" INTO OUTFILE
623sed -i "s|\[mysqld\]|&\nsecure-file-priv = /var/tmp|" $MY_CNF_PATH
624
625# setup sentora access and core database
626sed -i "s|YOUR_ROOT_MYSQL_PASSWORD|$mysqlpassword|" $PANEL_PATH/panel/cnf/db.php
627mysql -u root -p"$mysqlpassword" < $PANEL_CONF/sentora-install/sql/sentora_core.sql
628
629# Register mysql/mariadb service for autostart
630if [[ "$OS" = "CentOs" ]]; then
631 if [[ "$VER" == "7" ]]; then
632 systemctl enable "$DB_SERVICE".service
633 else
634 chkconfig "$DB_SERVICE" on
635 fi
636fi
637
638
639#--- Postfix
640echo -e "\n-- Installing Postfix"
641if [[ "$OS" = "CentOs" ]]; then
642 $PACKAGE_INSTALLER postfix postfix-perl-scripts
643 USR_LIB_PATH="/usr/libexec"
644elif [[ "$OS" = "Ubuntu" ]]; then
645 $PACKAGE_INSTALLER postfix postfix-mysql
646 USR_LIB_PATH="/usr/lib"
647fi
648
649postfixpassword=$(passwordgen);
650mysql -u root -p"$mysqlpassword" < $PANEL_CONF/sentora-install/sql/sentora_postfix.sql
651mysql -u root -p"$mysqlpassword" -e "UPDATE mysql.user SET Password=PASSWORD('$postfixpassword') WHERE User='postfix' AND Host='localhost';";
652
653mkdir $PANEL_DATA/vmail
654useradd -r -g mail -d $PANEL_DATA/vmail -s /sbin/nologin -c "Virtual maildir" vmail
655chown -R vmail:mail $PANEL_DATA/vmail
656chmod -R 770 $PANEL_DATA/vmail
657
658mkdir -p /var/spool/vacation
659useradd -r -d /var/spool/vacation -s /sbin/nologin -c "Virtual vacation" vacation
660chown -R vacation:vacation /var/spool/vacation
661chmod -R 770 /var/spool/vacation
662
663#Removed optionnal transport that was leaved empty, until it is fully handled.
664#ln -s $PANEL_CONF/postfix/transport /etc/postfix/transport
665#postmap /etc/postfix/transport
666
667add_local_domain "$PANEL_FQDN"
668add_local_domain "autoreply.$PANEL_FQDN"
669
670rm -rf /etc/postfix/main.cf /etc/postfix/master.cf
671ln -s $PANEL_CONF/postfix/master.cf /etc/postfix/master.cf
672ln -s $PANEL_CONF/postfix/main.cf /etc/postfix/main.cf
673ln -s $PANEL_CONF/postfix/vacation.pl /var/spool/vacation/vacation.pl
674
675sed -i "s|!POSTFIX_PASSWORD!|$postfixpassword|" $PANEL_CONF/postfix/*.cf
676sed -i "s|!POSTFIX_PASSWORD!|$postfixpassword|" $PANEL_CONF/postfix/vacation.conf
677sed -i "s|!PANEL_FQDN!|$PANEL_FQDN|" $PANEL_CONF/postfix/main.cf
678
679sed -i "s|!USR_LIB!|$USR_LIB_PATH|" $PANEL_CONF/postfix/master.cf
680sed -i "s|!USR_LIB!|$USR_LIB_PATH|" $PANEL_CONF/postfix/main.cf
681sed -i "s|!SERVER_IP!|$PUBLIC_IP|" $PANEL_CONF/postfix/main.cf
682
683VMAIL_UID=$(id -u vmail)
684MAIL_GID=$(sed -nr "s/^mail:x:([0-9]+):.*/\1/p" /etc/group)
685sed -i "s|!POS_UID!|$VMAIL_UID|" $PANEL_CONF/postfix/main.cf
686sed -i "s|!POS_GID!|$MAIL_GID|" $PANEL_CONF/postfix/main.cf
687
688# remove unusued directives that issue warnings
689sed -i '/virtual_mailbox_limit_maps/d' $PANEL_CONF/postfix/main.cf
690sed -i '/smtpd_bind_address/d' $PANEL_CONF/postfix/master.cf
691
692# Register postfix service for autostart (it is automatically started)
693if [[ "$OS" = "CentOs" ]]; then
694 if [[ "$VER" == "7" ]]; then
695 systemctl enable postfix.service
696 # systemctl start postfix.service
697 else
698 chkconfig postfix on
699 # /etc/init.d/postfix start
700 fi
701fi
702
703
704#--- Dovecot (includes Sieve)
705echo -e "\n-- Installing Dovecot"
706if [[ "$OS" = "CentOs" ]]; then
707 $PACKAGE_INSTALLER dovecot dovecot-mysql dovecot-pigeonhole
708 sed -i "s|#first_valid_uid = ?|first_valid_uid = $VMAIL_UID\n#last_valid_uid = $VMAIL_UID\n\nfirst_valid_gid = $MAIL_GID\n#last_valid_gid = $MAIL_GID|" $PANEL_CONF/dovecot2/dovecot.conf
709elif [[ "$OS" = "Ubuntu" ]]; then
710 $PACKAGE_INSTALLER dovecot-mysql dovecot-imapd dovecot-pop3d dovecot-common dovecot-managesieved dovecot-lmtpd
711 sed -i "s|#first_valid_uid = ?|first_valid_uid = $VMAIL_UID\nlast_valid_uid = $VMAIL_UID\n\nfirst_valid_gid = $MAIL_GID\nlast_valid_gid = $MAIL_GID|" $PANEL_CONF/dovecot2/dovecot.conf
712fi
713
714mkdir -p $PANEL_DATA/sieve
715chown -R vmail:mail $PANEL_DATA/sieve
716mkdir -p /var/lib/dovecot/sieve/
717touch /var/lib/dovecot/sieve/default.sieve
718ln -s $PANEL_CONF/dovecot2/globalfilter.sieve $PANEL_DATA/sieve/globalfilter.sieve
719
720rm -rf /etc/dovecot/dovecot.conf
721ln -s $PANEL_CONF/dovecot2/dovecot.conf /etc/dovecot/dovecot.conf
722sed -i "s|!POSTMASTER_EMAIL!|postmaster@$PANEL_FQDN|" $PANEL_CONF/dovecot2/dovecot.conf
723sed -i "s|!POSTFIX_PASSWORD!|$postfixpassword|" $PANEL_CONF/dovecot2/dovecot-dict-quota.conf
724sed -i "s|!POSTFIX_PASSWORD!|$postfixpassword|" $PANEL_CONF/dovecot2/dovecot-mysql.conf
725sed -i "s|!DOV_UID!|$VMAIL_UID|" $PANEL_CONF/dovecot2/dovecot-mysql.conf
726sed -i "s|!DOV_GID!|$MAIL_GID|" $PANEL_CONF/dovecot2/dovecot-mysql.conf
727
728touch /var/log/dovecot.log /var/log/dovecot-info.log /var/log/dovecot-debug.log
729chown vmail:mail /var/log/dovecot*
730chmod 660 /var/log/dovecot*
731
732# Register dovecot service for autostart and start it
733if [[ "$OS" = "CentOs" ]]; then
734 if [[ "$VER" == "7" ]]; then
735 systemctl enable dovecot.service
736 systemctl start dovecot.service
737 else
738 chkconfig dovecot on
739 /etc/init.d/dovecot start
740 fi
741fi
742
743#--- Apache server
744echo -e "\n-- Installing and configuring Apache"
745$PACKAGE_INSTALLER "$HTTP_PCKG"
746if [[ "$OS" = "CentOs" ]]; then
747 $PACKAGE_INSTALLER "$HTTP_PCKG-devel"
748 HTTP_CONF_PATH="/etc/httpd/conf/httpd.conf"
749 HTTP_VARS_PATH="/etc/sysconfig/httpd"
750 HTTP_SERVICE="httpd"
751 HTTP_USER="apache"
752 HTTP_GROUP="apache"
753 if [[ "$VER" = "7" ]]; then
754 # Disable extra modules in centos 7
755 disable_file /etc/httpd/conf.modules.d/01-cgi.conf
756 disable_file /etc/httpd/conf.modules.d/00-lua.conf
757 disable_file /etc/httpd/conf.modules.d/00-dav.conf
758 else
759 disable_file /etc/httpd/conf.d/welcome.conf
760 disable_file /etc/httpd/conf.d/webalizer.conf
761 # Disable more extra modules in centos 6.x /etc/httpd/httpd.conf dav/ldap/cgi/proxy_ajp
762 sed -i "s|LoadModule suexec_module modules|#LoadModule suexec_module modules|" "$HTTP_CONF_PATH"
763 sed -i "s|LoadModule cgi_module modules|#LoadModule cgi_module modules|" "$HTTP_CONF_PATH"
764 sed -i "s|LoadModule dav_module modules|#LoadModule dav_module modules|" "$HTTP_CONF_PATH"
765 sed -i "s|LoadModule dav_fs_module modules|#LoadModule dav_fs_module modules|" "$HTTP_CONF_PATH"
766 sed -i "s|LoadModule proxy_ajp_module modules|#LoadModule proxy_ajp_module modules|" "$HTTP_CONF_PATH"
767
768 fi
769elif [[ "$OS" = "Ubuntu" ]]; then
770 $PACKAGE_INSTALLER libapache2-mod-bw
771 HTTP_CONF_PATH="/etc/apache2/apache2.conf"
772 HTTP_VARS_PATH="/etc/apache2/envvars"
773 HTTP_SERVICE="apache2"
774 HTTP_USER="www-data"
775 HTTP_GROUP="www-data"
776 a2enmod rewrite
777fi
778
779if ! grep -q "Include $PANEL_CONF/apache/httpd.conf" "$HTTP_CONF_PATH"; then
780 echo "Include $PANEL_CONF/apache/httpd.conf" >> "$HTTP_CONF_PATH";
781fi
782add_local_domain "$(hostname)"
783
784if ! grep -q "apache ALL=NOPASSWD: $PANEL_PATH/panel/bin/zsudo" /etc/sudoers; then
785 echo "apache ALL=NOPASSWD: $PANEL_PATH/panel/bin/zsudo" >> /etc/sudoers;
786fi
787
788# Create root directory for public HTTP docs
789mkdir -p $PANEL_DATA/hostdata/zadmin/public_html
790chown -R $HTTP_USER:$HTTP_GROUP $PANEL_DATA/hostdata/
791chmod -R 770 $PANEL_DATA/hostdata/
792
793mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$HTTP_SERVICE' WHERE so_name_vc='httpd_exe'"
794mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$HTTP_SERVICE' WHERE so_name_vc='apache_sn'"
795
796#Set keepalive on (default is off)
797sed -i "s|KeepAlive Off|KeepAlive On|" "$HTTP_CONF_PATH"
798
799# Permissions fix for Apache and ProFTPD (to enable them to play nicely together!)
800if ! grep -q "umask 002" "$HTTP_VARS_PATH"; then
801 echo "umask 002" >> "$HTTP_VARS_PATH";
802fi
803
804# remove default virtual site to ensure Sentora is the default vhost
805if [[ "$OS" = "CentOs" ]]; then
806 sed -i "s|DocumentRoot \"/var/www/html\"|DocumentRoot $PANEL_PATH/panel|" "$HTTP_CONF_PATH"
807elif [[ "$OS" = "Ubuntu" ]]; then
808 # disable completely sites-enabled/000-default.conf
809 if [[ "$VER" = "14.04" ]]; then
810 sed -i "s|IncludeOptional sites-enabled|#&|" "$HTTP_CONF_PATH"
811 else
812 sed -i "s|Include sites-enabled|#&|" "$HTTP_CONF_PATH"
813 fi
814fi
815
816# Comment "NameVirtualHost" and Listen directives that are handled in vhosts file
817if [[ "$OS" = "CentOs" ]]; then
818 sed -i "s|^\(NameVirtualHost .*$\)|#\1\n# NameVirtualHost is now handled in Sentora vhosts file|" "$HTTP_CONF_PATH"
819 sed -i 's|^\(Listen .*$\)|#\1\n# Listen is now handled in Sentora vhosts file|' "$HTTP_CONF_PATH"
820elif [[ "$OS" = "Ubuntu" ]]; then
821 sed -i "s|\(Include ports.conf\)|#\1\n# Ports are now handled in Sentora vhosts file|" "$HTTP_CONF_PATH"
822 disable_file /etc/apache2/ports.conf
823fi
824
825# adjustments for apache 2.4
826if [[ ("$OS" = "CentOs" && "$VER" = "7") ||
827 ("$OS" = "Ubuntu" && "$VER" = "14.04") ]] ; then
828 # Order deny,allow / Deny from all -> Require all denied
829 sed -i 's|Order deny,allow|Require all denied|I' $PANEL_CONF/apache/httpd.conf
830 sed -i '/Deny from all/d' $PANEL_CONF/apache/httpd.conf
831
832 # Order allow,deny / Allow from all -> Require all granted
833 sed -i 's|Order allow,deny|Require all granted|I' $PANEL_CONF/apache/httpd-vhosts.conf
834 sed -i '/Allow from all/d' $PANEL_CONF/apache/httpd-vhosts.conf
835
836 sed -i 's|Order allow,deny|Require all granted|I' $PANEL_PATH/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
837 sed -i '/Allow from all/d' $PANEL_PATH/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
838
839 # Remove NameVirtualHost that is now without effect and generate warning
840 sed -i '/NameVirtualHost/{N;d}' $PANEL_CONF/apache/httpd-vhosts.conf
841 sed -i '/# NameVirtualHost is/ {N;N;N;N;N;d}' $PANEL_PATH/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
842
843 # Options must have ALL (or none) +/- prefix, disable listing directories
844 sed -i 's| FollowSymLinks [-]Indexes| +FollowSymLinks -Indexes|' $PANEL_PATH/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
845fi
846
847
848#--- PHP
849echo -e "\n-- Installing and configuring PHP"
850if [[ "$OS" = "CentOs" ]]; then
851 $PACKAGE_INSTALLER php php-devel php-gd php-mbstring php-intl php-mysql php-xml php-xmlrpc
852 $PACKAGE_INSTALLER php-mcrypt php-imap #Epel packages
853 PHP_INI_PATH="/etc/php.ini"
854 PHP_EXT_PATH="/etc/php.d"
855elif [[ "$OS" = "Ubuntu" ]]; then
856 $PACKAGE_INSTALLER libapache2-mod-php5 php5-common php5-cli php5-mysql php5-gd php5-mcrypt php5-curl php-pear php5-imap php5-xmlrpc php5-xsl php5-intl
857 if [ "$VER" = "14.04" ]; then
858 php5enmod mcrypt # missing in the package for Ubuntu 14!
859 else
860 $PACKAGE_INSTALLER php5-suhosin
861 fi
862 PHP_INI_PATH="/etc/php5/apache2/php.ini"
863fi
864# Setup php upload dir
865mkdir -p $PANEL_DATA/temp
866chmod 1777 $PANEL_DATA/temp/
867chown -R $HTTP_USER:$HTTP_GROUP $PANEL_DATA/temp/
868
869# Setup php session save directory
870mkdir "$PANEL_DATA/sessions"
871chown $HTTP_USER:$HTTP_GROUP "$PANEL_DATA/sessions"
872chmod 733 "$PANEL_DATA/sessions"
873chmod +t "$PANEL_DATA/sessions"
874
875if [[ "$OS" = "CentOs" ]]; then
876 # Remove session & php values from apache that cause override
877 sed -i "/php_value/d" /etc/httpd/conf.d/php.conf
878elif [[ "$OS" = "Ubuntu" ]]; then
879 sed -i "s|;session.save_path = \"/var/lib/php5\"|session.save_path = \"$PANEL_DATA/sessions\"|" $PHP_INI_PATH
880fi
881sed -i "/php_value/d" $PHP_INI_PATH
882echo "session.save_path = $PANEL_DATA/sessions;">> $PHP_INI_PATH
883
884# setup timezone and upload temp dir
885sed -i "s|;date.timezone =|date.timezone = $tz|" $PHP_INI_PATH
886sed -i "s|;upload_tmp_dir =|upload_tmp_dir = $PANEL_DATA/temp/|" $PHP_INI_PATH
887
888# Disable php signature in headers to hide it from hackers
889sed -i "s|expose_php = On|expose_php = Off|" $PHP_INI_PATH
890
891# Build suhosin for PHP 5.x which is required by Sentora.
892if [[ "$OS" = "CentOs" || ( "$OS" = "Ubuntu" && "$VER" = "14.04") ]] ; then
893 echo -e "\n# Building suhosin"
894 if [[ "$OS" = "Ubuntu" ]]; then
895 $PACKAGE_INSTALLER php5-dev
896 fi
897 SUHOSIN_VERSION="0.9.37.1"
898 wget -nv -O suhosin.zip https://github.com/stefanesser/suhosin/archive/$SUHOSIN_VERSION.zip
899 unzip -q suhosin.zip
900 rm -f suhosin.zip
901 cd suhosin-$SUHOSIN_VERSION
902 phpize &> /dev/null
903 ./configure &> /dev/null
904 make &> /dev/null
905 make install
906 cd ..
907 rm -rf suhosin-$SUHOSIN_VERSION
908 if [[ "$OS" = "CentOs" ]]; then
909 echo 'extension=suhosin.so' > $PHP_EXT_PATH/suhosin.ini
910 elif [[ "$OS" = "Ubuntu" ]]; then
911 sed -i 'N;/default extension directory./a\extension=suhosin.so' $PHP_INI_PATH
912 fi
913fi
914
915# Register apache(+php) service for autostart and start it
916if [[ "$OS" = "CentOs" ]]; then
917 if [[ "$VER" == "7" ]]; then
918 systemctl enable "$HTTP_SERVICE.service"
919 systemctl start "$HTTP_SERVICE.service"
920 else
921 chkconfig "$HTTP_SERVICE" on
922 "/etc/init.d/$HTTP_SERVICE" start
923 fi
924fi
925
926
927#--- ProFTPd
928echo -e "\n-- Installing ProFTPD"
929if [[ "$OS" = "CentOs" ]]; then
930 $PACKAGE_INSTALLER proftpd proftpd-mysql
931 FTP_CONF_PATH='/etc/proftpd.conf'
932 sed -i "s|nogroup|nobody|" $PANEL_CONF/proftpd/proftpd-mysql.conf
933elif [[ "$OS" = "Ubuntu" ]]; then
934 $PACKAGE_INSTALLER proftpd-mod-mysql
935 FTP_CONF_PATH='/etc/proftpd/proftpd.conf'
936fi
937
938# Create and init proftpd database
939mysql -u root -p"$mysqlpassword" < $PANEL_CONF/sentora-install/sql/sentora_proftpd.sql
940
941# Create and configure mysql password for proftpd
942proftpdpassword=$(passwordgen);
943sed -i "s|!SQL_PASSWORD!|$proftpdpassword|" $PANEL_CONF/proftpd/proftpd-mysql.conf
944mysql -u root -p"$mysqlpassword" -e "UPDATE mysql.user SET Password=PASSWORD('$proftpdpassword') WHERE User='proftpd' AND Host='localhost'";
945
946# Assign httpd user and group to all users that will be created
947HTTP_UID=$(id -u "$HTTP_USER")
948HTTP_GID=$(sed -nr "s/^$HTTP_GROUP:x:([0-9]+):.*/\1/p" /etc/group)
949mysql -u root -p"$mysqlpassword" -e "ALTER TABLE sentora_proftpd.ftpuser ALTER COLUMN uid SET DEFAULT $HTTP_UID"
950mysql -u root -p"$mysqlpassword" -e "ALTER TABLE sentora_proftpd.ftpuser ALTER COLUMN gid SET DEFAULT $HTTP_GID"
951sed -i "s|!SQL_MIN_ID!|$HTTP_UID|" $PANEL_CONF/proftpd/proftpd-mysql.conf
952
953# Setup proftpd base file to call sentora config
954rm -f "$FTP_CONF_PATH"
955#touch "$FTP_CONF_PATH"
956#echo "include $PANEL_CONF/proftpd/proftpd-mysql.conf" >> "$FTP_CONF_PATH";
957ln -s "$PANEL_CONF/proftpd/proftpd-mysql.conf" "$FTP_CONF_PATH"
958
959# setup proftpd log dir
960mkdir -p $PANEL_DATA/logs/proftpd
961chmod -R 644 $PANEL_DATA/logs/proftpd
962
963# Correct bug from package in Ubutu14.04 which screw service proftpd restart
964# see https://bugs.launchpad.net/ubuntu/+source/proftpd-dfsg/+bug/1246245
965if [[ "$OS" = "Ubuntu" && "$VER" = "14.04" ]]; then
966 sed -i 's|\([ \t]*start-stop-daemon --stop --signal $SIGNAL \)\(--quiet --pidfile "$PIDFILE"\)$|\1--retry 1 \2|' /etc/init.d/proftpd
967fi
968
969# Register proftpd service for autostart and start it
970if [[ "$OS" = "CentOs" ]]; then
971 if [[ "$VER" == "7" ]]; then
972 systemctl enable proftpd.service
973 systemctl start proftpd.service
974 else
975 chkconfig proftpd on
976 /etc/init.d/proftpd start
977 fi
978fi
979
980#--- BIND
981echo -e "\n-- Installing and configuring Bind"
982if [[ "$OS" = "CentOs" ]]; then
983 $PACKAGE_INSTALLER bind bind-utils bind-libs
984 BIND_PATH="/etc/named/"
985 BIND_FILES="/etc"
986 BIND_SERVICE="named"
987 BIND_USER="named"
988elif [[ "$OS" = "Ubuntu" ]]; then
989 $PACKAGE_INSTALLER bind9 bind9utils
990 BIND_PATH="/etc/bind/"
991 BIND_FILES="/etc/bind"
992 BIND_SERVICE="bind9"
993 BIND_USER="bind"
994 mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='' WHERE so_name_vc='bind_log'"
995fi
996mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$BIND_PATH' WHERE so_name_vc='bind_dir'"
997mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$BIND_SERVICE' WHERE so_name_vc='bind_service'"
998chmod -R 777 $PANEL_CONF/bind/zones/
999
1000# Setup logging directory
1001mkdir $PANEL_DATA/logs/bind
1002touch $PANEL_DATA/logs/bind/bind.log $PANEL_DATA/logs/bind/debug.log
1003chown $BIND_USER $PANEL_DATA/logs/bind/bind.log $PANEL_DATA/logs/bind/debug.log
1004chmod 660 $PANEL_DATA/logs/bind/bind.log $PANEL_DATA/logs/bind/debug.log
1005
1006if [[ "$OS" = "CentOs" ]]; then
1007 chmod 751 /var/named
1008 chmod 771 /var/named/data
1009 sed -i 's|bind/zones.rfc1918|named.rfc1912.zones|' $PANEL_CONF/bind/named.conf
1010elif [[ "$OS" = "Ubuntu" ]]; then
1011 mkdir -p /var/named/dynamic
1012 touch /var/named/dynamic/managed-keys.bind
1013 chown -R bind:bind /var/named/
1014 chmod -R 777 $PANEL_CONF/bind/etc
1015
1016 chown root:root $BIND_FILES/rndc.key
1017 chmod 755 $BIND_FILES/rndc.key
1018fi
1019# Some link to enable call from path
1020ln -s /usr/sbin/named-checkconf /usr/bin/named-checkconf
1021ln -s /usr/sbin/named-checkzone /usr/bin/named-checkzone
1022ln -s /usr/sbin/named-compilezone /usr/bin/named-compilezone
1023
1024# Setup acl IP to forbid zone transfer
1025sed -i "s|!SERVER_IP!|$PUBLIC_IP|" $PANEL_CONF/bind/named.conf
1026
1027# Build key and conf files
1028rm -rf $BIND_FILES/named.conf $BIND_FILES/rndc.conf $BIND_FILES/rndc.key
1029rndc-confgen -a -r /dev/urandom
1030cat $BIND_FILES/rndc.key $PANEL_CONF/bind/named.conf > $BIND_FILES/named.conf
1031cat $BIND_FILES/rndc.key $PANEL_CONF/bind/rndc.conf > $BIND_FILES/rndc.conf
1032rm -f $BIND_FILES/rndc.key
1033
1034# Register Bind service for autostart and start it
1035if [[ "$OS" = "CentOs" ]]; then
1036 if [[ "$VER" == "7" ]]; then
1037 systemctl enable named.service
1038 systemctl start named.service
1039 else
1040 chkconfig named on
1041 /etc/init.d/named start
1042 fi
1043fi
1044
1045
1046#--- CRON and ATD
1047echo -e "\n-- Installing and configuring cron tasks"
1048if [[ "$OS" = "CentOs" ]]; then
1049 #cronie & crontabs may be missing
1050 $PACKAGE_INSTALLER crontabs
1051 CRON_DIR="/var/spool/cron"
1052 CRON_SERVICE="crond"
1053elif [[ "$OS" = "Ubuntu" ]]; then
1054 CRON_DIR="/var/spool/cron/crontabs"
1055 CRON_SERVICE="cron"
1056fi
1057CRON_USER="$HTTP_USER"
1058
1059# prepare daemon crontab
1060# sed -i "s|!USER!|$CRON_USER|" "$PANEL_CONF/cron/zdaemon" #it screw update search!#
1061sed -i "s|!USER!|root|" "$PANEL_CONF/cron/zdaemon"
1062cp "$PANEL_CONF/cron/zdaemon" /etc/cron.d/zdaemon
1063chmod 644 /etc/cron.d/zdaemon
1064
1065# prepare user crontabs
1066CRON_FILE="$CRON_DIR/$CRON_USER"
1067mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$CRON_FILE' WHERE so_name_vc='cron_file'"
1068mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$CRON_FILE' WHERE so_name_vc='cron_reload_path'"
1069mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$CRON_USER' WHERE so_name_vc='cron_reload_user'"
1070{
1071 echo "SHELL=/bin/bash"
1072 echo "PATH=/sbin:/bin:/usr/sbin:/usr/bin"
1073 echo ""
1074} > mycron
1075crontab -u $HTTP_USER mycron
1076rm -f mycron
1077
1078chmod 744 "$CRON_DIR"
1079chown -R $HTTP_USER:$HTTP_USER "$CRON_DIR"
1080chmod 644 "$CRON_FILE"
1081
1082# Register cron and atd services for autostart and start them
1083if [[ "$OS" = "CentOs" ]]; then
1084 if [[ "$VER" == "7" ]]; then
1085 systemctl enable crond.service
1086 systemctl start crond.service
1087 systemctl start atd.service
1088 else
1089 chkconfig crond on
1090 /etc/init.d/crond start
1091 /etc/init.d/atd start
1092 fi
1093fi
1094
1095
1096#--- phpMyAdmin
1097echo -e "\n-- Configuring phpMyAdmin"
1098phpmyadminsecret=$(passwordgen);
1099chmod 644 $PANEL_CONF/phpmyadmin/config.inc.php
1100sed -i "s|\$cfg\['blowfish_secret'\] \= 'SENTORA';|\$cfg\['blowfish_secret'\] \= '$phpmyadminsecret';|" $PANEL_CONF/phpmyadmin/config.inc.php
1101ln -s $PANEL_CONF/phpmyadmin/config.inc.php $PANEL_PATH/panel/etc/apps/phpmyadmin/config.inc.php
1102# Remove phpMyAdmin's setup folder in case it was left behind
1103rm -rf $PANEL_PATH/panel/etc/apps/phpmyadmin/setup
1104
1105
1106#--- Roundcube
1107echo -e "\n-- Configuring Roundcube"
1108
1109# Import roundcube default table
1110mysql -u root -p"$mysqlpassword" < $PANEL_CONF/sentora-install/sql/sentora_roundcube.sql
1111
1112# Create and configure mysql password for roundcube
1113roundcubepassword=$(passwordgen);
1114sed -i "s|!ROUNDCUBE_PASSWORD!|$roundcubepassword|" $PANEL_CONF/roundcube/roundcube_config.inc.php
1115mysql -u root -p"$mysqlpassword" -e "UPDATE mysql.user SET Password=PASSWORD('$roundcubepassword') WHERE User='roundcube' AND Host='localhost'";
1116
1117# Create and configure des key
1118roundcube_des_key=$(passwordgen 24);
1119sed -i "s|!ROUNDCUBE_DESKEY!|$roundcube_des_key|" $PANEL_CONF/roundcube/roundcube_config.inc.php
1120
1121# Create and configure specials directories and rights
1122chown "$HTTP_USER:$HTTP_GROUP" "$PANEL_PATH/panel/etc/apps/webmail/temp"
1123mkdir "$PANEL_DATA/logs/roundcube"
1124chown "$HTTP_USER:$HTTP_GROUP" "$PANEL_DATA/logs/roundcube"
1125
1126# Map config file in roundcube with symbolic links
1127ln -s $PANEL_CONF/roundcube/roundcube_config.inc.php $PANEL_PATH/panel/etc/apps/webmail/config/config.inc.php
1128ln -s $PANEL_CONF/roundcube/sieve_config.inc.php $PANEL_PATH/panel/etc/apps/webmail/plugins/managesieve/config.inc.php
1129
1130
1131#--- Webalizer
1132echo -e "\n-- Configuring Webalizer"
1133$PACKAGE_INSTALLER webalizer
1134if [[ "$OS" = "CentOs" ]]; then
1135 rm -rf /etc/webalizer.conf
1136elif [[ "$OS" = "Ubuntu" ]]; then
1137 rm -rf /etc/webalizer/webalizer.conf
1138fi
1139
1140
1141#--- Set some Sentora database entries using. setso and setzadmin (require PHP)
1142echo -e "\n-- Configuring Sentora"
1143zadminpassword=$(passwordgen);
1144setzadmin --set "$zadminpassword";
1145$PANEL_PATH/panel/bin/setso --set sentora_domain "$PANEL_FQDN"
1146$PANEL_PATH/panel/bin/setso --set server_ip "$PUBLIC_IP"
1147
1148# if not release, set beta version in database
1149if [[ $(echo "$SENTORA_CORE_VERSION" | sed 's|.*-\(beta\).*$|\1|') = "beta" ]] ; then
1150 $PANEL_PATH/panel/bin/setso --set dbversion "$SENTORA_CORE_VERSION"
1151fi
1152
1153# make the daemon to build vhosts file.
1154$PANEL_PATH/panel/bin/setso --set apache_changed "true"
1155php -q $PANEL_PATH/panel/bin/daemon.php
1156
1157
1158#--- Firewall ?
1159
1160#--- Resolv.conf deprotect
1161chattr -i /etc/resolv.conf
1162
1163
1164#--- Restart all services to capture output messages, if any
1165if [[ "$OS" = "CentOs" && "$VER" == "7" ]]; then
1166 # CentOs7 does not return anything except redirection to systemctl :-(
1167 service() {
1168 echo "Restarting $1"
1169 systemctl restart "$1.service"
1170 }
1171fi
1172
1173service "$DB_SERVICE" restart
1174service "$HTTP_SERVICE" restart
1175service postfix restart
1176service dovecot restart
1177service "$CRON_SERVICE" restart
1178service "$BIND_SERVICE" restart
1179service proftpd restart
1180service atd restart
1181
1182#--- Store the passwords for user reference
1183{
1184 echo "Server IP address : $PUBLIC_IP"
1185 echo "Panel URL : http://$PANEL_FQDN"
1186 echo "zadmin Password : $zadminpassword"
1187 echo ""
1188 echo "MySQL Root Password : $mysqlpassword"
1189 echo "MySQL Postfix Password : $postfixpassword"
1190 echo "MySQL ProFTPd Password : $proftpdpassword"
1191 echo "MySQL Roundcube Password : $roundcubepassword"
1192} >> /root/passwords.txt
1193
1194#--- Advise the admin that Sentora is now installed and accessible.
1195{
1196echo "########################################################"
1197echo " Congratulations Sentora has now been installed on your"
1198echo " server. Please review the log file left in /root/ for "
1199echo " any errors encountered during installation."
1200echo ""
1201echo " Login to Sentora at http://$PANEL_FQDN"
1202echo " Sentora Username : zadmin"
1203echo " Sentora Password : $zadminpassword"
1204echo ""
1205echo " MySQL Root Password : $mysqlpassword"
1206echo " MySQL Postfix Password : $postfixpassword"
1207echo " MySQL ProFTPd Password : $proftpdpassword"
1208echo " MySQL Roundcube Password : $roundcubepassword"
1209echo " (theses passwords are saved in /root/passwords.txt)"
1210echo "########################################################"
1211echo ""
1212} &>/dev/tty
1213
1214# Wait until the user have read before restarts the server...
1215if [[ "$INSTALL" != "auto" ]] ; then
1216 while true; do
1217 read -e -p "Restart your server now to complete the install (y/n)? " rsn
1218 case $rsn in
1219 [Yy]* ) break;;
1220 [Nn]* ) exit;
1221 esac
1222 done
1223 shutdown -r now
1224fi