· 10 years ago · Jun 15, 2016, 11:18 AM
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" || "$VER" = "16.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
433if [ "$VER" = "16.04" ]; then
434 LC_ALL=C.UTF-8 sudo add-apt-repository -y ppa:ondrej/php
435 cat > /etc/apt/sources.list <<EOF
436#Depots main restricted
437deb http://ppa.launchpad.net/ondrej/php/ubuntu xenial main
438
439EOF
440fi
441
442#--- List all already installed packages (may help to debug)
443echo -e "\n-- Listing of all packages installed:"
444if [[ "$OS" = "CentOs" ]]; then
445 rpm -qa | sort
446elif [[ "$OS" = "Ubuntu" ]]; then
447 dpkg --get-selections
448fi
449
450#--- Ensures that all packages are up to date
451echo -e "\n-- Updating+upgrading system, it may take some time..."
452if [[ "$OS" = "CentOs" ]]; then
453 yum -y update
454 yum -y upgrade
455elif [[ "$OS" = "Ubuntu" ]]; then
456 apt-get -yqq update
457 apt-get -yqq upgrade
458fi
459
460#--- Install utility packages required by the installer and/or Sentora.
461echo -e "\n-- Downloading and installing required tools..."
462if [[ "$OS" = "CentOs" ]]; then
463 $PACKAGE_INSTALLER sudo vim make zip unzip chkconfig bash-completion
464 $PACKAGE_INSTALLER ld-linux.so.2 libbz2.so.1 libdb-4.7.so libgd.so.2
465 $PACKAGE_INSTALLER curl curl-devel perl-libwww-perl libxml2 libxml2-devel zip bzip2-devel gcc gcc-c++ at make
466 $PACKAGE_INSTALLER redhat-lsb-core
467elif [[ "$OS" = "Ubuntu" ]]; then
468 $PACKAGE_INSTALLER sudo vim make zip unzip debconf-utils at build-essential bash-completion
469fi
470
471#--- Download Sentora archive from GitHub
472echo -e "\n-- Downloading Sentora, Please wait, this may take several minutes, the installer will continue after this is complete!"
473# Get latest sentora
474while true; do
475 wget -nv -O sentora_core.zip https://github.com/sentora/sentora-core/archive/$SENTORA_CORE_VERSION.zip
476 if [[ -f sentora_core.zip ]]; then
477 break;
478 else
479 echo "Failed to download sentora core from Github"
480 echo "If you quit now, you can run again the installer later."
481 read -e -p "Press r to retry or q to quit the installer? " resp
482 case $resp in
483 [Rr]* ) continue;;
484 [Qq]* ) exit 3;;
485 esac
486 fi
487done
488mkdir -p $PANEL_PATH
489chown -R root:root $PANEL_PATH
490unzip -oq sentora_core.zip -d $PANEL_PATH
491mv "$PANEL_PATH/sentora-core-$SENTORA_CORE_VERSION" "$PANEL_PATH/panel"
492rm sentora_core.zip
493rm "$PANEL_PATH/panel/LICENSE.md" "$PANEL_PATH/panel/README.md" "$PANEL_PATH/panel/.gitignore"
494rm -rf "$PANEL_PATH/_delete_me" "$PANEL_PATH/.gitignore"
495
496# Temp patch
497wget -O hotfix_controller.ext.php "https://raw.githubusercontent.com/sentora/sentora-core/b176df0e29e52e14d778ca6cb47c5765cf3c4953/modules/ftp_management/code/controller.ext.php"
498mv /etc/sentora/panel/modules/ftp_management/code/controller.ext.php controller.ext.php_backup
499mv hotfix_controller.ext.php /etc/sentora/panel/modules/ftp_management/code/controller.ext.php
500chown root:root /etc/sentora/panel/modules/ftp_management/code/controller.ext.php
501chmod 777 /etc/sentora/panel/modules/ftp_management/code/controller.ext.php
502
503
504#--- Set-up Sentora directories and configure permissions
505PANEL_CONF="$PANEL_PATH/configs"
506
507mkdir -p $PANEL_CONF
508mkdir -p $PANEL_PATH/docs
509chmod -R 777 $PANEL_PATH
510
511mkdir -p $PANEL_DATA/backups
512chmod -R 777 $PANEL_DATA/
513
514# Links for compatibility with zpanel access
515ln -s $PANEL_PATH /etc/zpanel
516ln -s $PANEL_DATA /var/zpanel
517
518#--- Prepare Sentora executables
519chmod +x $PANEL_PATH/panel/bin/zppy
520ln -s $PANEL_PATH/panel/bin/zppy /usr/bin/zppy
521
522chmod +x $PANEL_PATH/panel/bin/setso
523ln -s $PANEL_PATH/panel/bin/setso /usr/bin/setso
524
525chmod +x $PANEL_PATH/panel/bin/setzadmin
526ln -s $PANEL_PATH/panel/bin/setzadmin /usr/bin/setzadmin
527
528#--- Install preconfig
529while true; do
530 wget -nv -O sentora_preconfig.zip https://github.com/sentora/sentora-installers/archive/$SENTORA_PRECONF_VERSION.zip
531 if [[ -f sentora_preconfig.zip ]]; then
532 break;
533 else
534 echo "Failed to download sentora preconfig from Github"
535 echo "If you quit now, you can run again the installer later."
536 read -e -p "Press r to retry or q to quit the installer? " resp
537 case $resp in
538 [Rr]* ) continue;;
539 [Qq]* ) exit 3;;
540 esac
541 fi
542done
543
544unzip -oq sentora_preconfig.zip
545cp -rf sentora-installers-$SENTORA_PRECONF_VERSION/preconf/* $PANEL_CONF
546rm sentora_preconfig*
547rm -rf sentora-*
548
549#--- Prepare zsudo
550cc -o $PANEL_PATH/panel/bin/zsudo $PANEL_CONF/bin/zsudo.c
551sudo chown root $PANEL_PATH/panel/bin/zsudo
552chmod +s $PANEL_PATH/panel/bin/zsudo
553
554#--- Resolv.conf protect
555chattr +i /etc/resolv.conf
556
557#--- Prepare hostname
558old_hostname=$(cat /etc/hostname)
559# In file hostname
560echo "$PANEL_FQDN" > /etc/hostname
561
562# In file hosts
563sed -i "/127.0.1.1[\t ]*$old_hostname/d" /etc/hosts
564sed -i "s|$old_hostname|$PANEL_FQDN|" /etc/hosts
565
566# For current session
567hostname "$PANEL_FQDN"
568
569# In network file
570if [[ "$OS" = "CentOs" && "$VER" = "6" ]]; then
571 sed -i "s|^\(HOSTNAME=\).*\$|HOSTNAME=$PANEL_FQDN|" /etc/sysconfig/network
572 /etc/init.d/network restart
573fi
574
575#--- Some functions used many times below
576# Random password generator function
577passwordgen() {
578 l=$1
579 [ "$l" == "" ] && l=16
580 tr -dc A-Za-z0-9 < /dev/urandom | head -c ${l} | xargs
581}
582
583# Add first parameter in hosts file as local IP domain
584add_local_domain() {
585 if ! grep -q "127.0.0.1 $1" /etc/hosts; then
586 echo "127.0.0.1 $1" >> /etc/hosts;
587 fi
588}
589
590#-----------------------------------------------------------
591# Install all softwares and dependencies required by Sentora.
592
593if [[ "$OS" = "Ubuntu" ]]; then
594 # Disable the DPKG prompts before we run the software install to enable fully automated install.
595 export DEBIAN_FRONTEND=noninteractive
596fi
597
598#--- MySQL
599echo -e "\n-- Installing MySQL"
600mysqlpassword=$(passwordgen);
601$PACKAGE_INSTALLER "$DB_PCKG"
602if [[ "$OS" = "CentOs" ]]; then
603 $PACKAGE_INSTALLER "DB_PCKG-devel" "$DB_PCKG-server"
604 MY_CNF_PATH="/etc/my.cnf"
605 if [[ "$VER" = "7" ]]; then
606 DB_SERVICE="mariadb"
607 else
608 DB_SERVICE="mysqld"
609 fi
610elif [[ "$OS" = "Ubuntu" ]]; then
611 $PACKAGE_INSTALLER bsdutils libsasl2-modules-sql libsasl2-modules
612 if [ "$VER" = "12.04" ]; then
613 $PACKAGE_INSTALLER db4.7-util
614 fi
615 MY_CNF_PATH="/etc/mysql/my.cnf"
616 DB_SERVICE="mysql"
617fi
618service $DB_SERVICE start
619
620# setup mysql root password
621mysqladmin -u root password "$mysqlpassword"
622
623# small cleaning of mysql access
624mysql -u root -p"$mysqlpassword" -e "DELETE FROM mysql.user WHERE User='root' AND Host != 'localhost'";
625mysql -u root -p"$mysqlpassword" -e "DELETE FROM mysql.user WHERE User=''";
626mysql -u root -p"$mysqlpassword" -e "FLUSH PRIVILEGES";
627
628# remove test table that is no longer used
629mysql -u root -p"$mysqlpassword" -e "DROP DATABASE IF EXISTS test";
630
631# secure SELECT "hacker-code" INTO OUTFILE
632sed -i "s|\[mysqld\]|&\nsecure-file-priv = /var/tmp|" $MY_CNF_PATH
633
634# setup sentora access and core database
635sed -i "s|YOUR_ROOT_MYSQL_PASSWORD|$mysqlpassword|" $PANEL_PATH/panel/cnf/db.php
636mysql -u root -p"$mysqlpassword" < $PANEL_CONF/sentora-install/sql/sentora_core.sql
637
638# Register mysql/mariadb service for autostart
639if [[ "$OS" = "CentOs" ]]; then
640 if [[ "$VER" == "7" ]]; then
641 systemctl enable "$DB_SERVICE".service
642 else
643 chkconfig "$DB_SERVICE" on
644 fi
645fi
646
647
648#--- Postfix
649echo -e "\n-- Installing Postfix"
650if [[ "$OS" = "CentOs" ]]; then
651 $PACKAGE_INSTALLER postfix postfix-perl-scripts
652 USR_LIB_PATH="/usr/libexec"
653elif [[ "$OS" = "Ubuntu" ]]; then
654 $PACKAGE_INSTALLER postfix postfix-mysql
655 USR_LIB_PATH="/usr/lib"
656fi
657
658postfixpassword=$(passwordgen);
659mysql -u root -p"$mysqlpassword" < $PANEL_CONF/sentora-install/sql/sentora_postfix.sql
660mysql -u root -p"$mysqlpassword" -e "UPDATE mysql.user SET Password=PASSWORD('$postfixpassword') WHERE User='postfix' AND Host='localhost';";
661
662mkdir $PANEL_DATA/vmail
663useradd -r -g mail -d $PANEL_DATA/vmail -s /sbin/nologin -c "Virtual maildir" vmail
664chown -R vmail:mail $PANEL_DATA/vmail
665chmod -R 770 $PANEL_DATA/vmail
666
667mkdir -p /var/spool/vacation
668useradd -r -d /var/spool/vacation -s /sbin/nologin -c "Virtual vacation" vacation
669chown -R vacation:vacation /var/spool/vacation
670chmod -R 770 /var/spool/vacation
671
672#Removed optionnal transport that was leaved empty, until it is fully handled.
673#ln -s $PANEL_CONF/postfix/transport /etc/postfix/transport
674#postmap /etc/postfix/transport
675
676add_local_domain "$PANEL_FQDN"
677add_local_domain "autoreply.$PANEL_FQDN"
678
679rm -rf /etc/postfix/main.cf /etc/postfix/master.cf
680ln -s $PANEL_CONF/postfix/master.cf /etc/postfix/master.cf
681ln -s $PANEL_CONF/postfix/main.cf /etc/postfix/main.cf
682ln -s $PANEL_CONF/postfix/vacation.pl /var/spool/vacation/vacation.pl
683
684sed -i "s|!POSTFIX_PASSWORD!|$postfixpassword|" $PANEL_CONF/postfix/*.cf
685sed -i "s|!POSTFIX_PASSWORD!|$postfixpassword|" $PANEL_CONF/postfix/vacation.conf
686sed -i "s|!PANEL_FQDN!|$PANEL_FQDN|" $PANEL_CONF/postfix/main.cf
687
688sed -i "s|!USR_LIB!|$USR_LIB_PATH|" $PANEL_CONF/postfix/master.cf
689sed -i "s|!USR_LIB!|$USR_LIB_PATH|" $PANEL_CONF/postfix/main.cf
690sed -i "s|!SERVER_IP!|$PUBLIC_IP|" $PANEL_CONF/postfix/main.cf
691
692VMAIL_UID=$(id -u vmail)
693MAIL_GID=$(sed -nr "s/^mail:x:([0-9]+):.*/\1/p" /etc/group)
694sed -i "s|!POS_UID!|$VMAIL_UID|" $PANEL_CONF/postfix/main.cf
695sed -i "s|!POS_GID!|$MAIL_GID|" $PANEL_CONF/postfix/main.cf
696
697# remove unusued directives that issue warnings
698sed -i '/virtual_mailbox_limit_maps/d' $PANEL_CONF/postfix/main.cf
699sed -i '/smtpd_bind_address/d' $PANEL_CONF/postfix/master.cf
700
701# Register postfix service for autostart (it is automatically started)
702if [[ "$OS" = "CentOs" ]]; then
703 if [[ "$VER" == "7" ]]; then
704 systemctl enable postfix.service
705 # systemctl start postfix.service
706 else
707 chkconfig postfix on
708 # /etc/init.d/postfix start
709 fi
710fi
711
712
713#--- Dovecot (includes Sieve)
714echo -e "\n-- Installing Dovecot"
715if [[ "$OS" = "CentOs" ]]; then
716 $PACKAGE_INSTALLER dovecot dovecot-mysql dovecot-pigeonhole
717 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
718elif [[ "$OS" = "Ubuntu" ]]; then
719 $PACKAGE_INSTALLER dovecot-mysql dovecot-imapd dovecot-pop3d dovecot-common dovecot-managesieved dovecot-lmtpd
720 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
721fi
722
723mkdir -p $PANEL_DATA/sieve
724chown -R vmail:mail $PANEL_DATA/sieve
725mkdir -p /var/lib/dovecot/sieve/
726touch /var/lib/dovecot/sieve/default.sieve
727ln -s $PANEL_CONF/dovecot2/globalfilter.sieve $PANEL_DATA/sieve/globalfilter.sieve
728
729rm -rf /etc/dovecot/dovecot.conf
730ln -s $PANEL_CONF/dovecot2/dovecot.conf /etc/dovecot/dovecot.conf
731sed -i "s|!POSTMASTER_EMAIL!|postmaster@$PANEL_FQDN|" $PANEL_CONF/dovecot2/dovecot.conf
732sed -i "s|!POSTFIX_PASSWORD!|$postfixpassword|" $PANEL_CONF/dovecot2/dovecot-dict-quota.conf
733sed -i "s|!POSTFIX_PASSWORD!|$postfixpassword|" $PANEL_CONF/dovecot2/dovecot-mysql.conf
734sed -i "s|!DOV_UID!|$VMAIL_UID|" $PANEL_CONF/dovecot2/dovecot-mysql.conf
735sed -i "s|!DOV_GID!|$MAIL_GID|" $PANEL_CONF/dovecot2/dovecot-mysql.conf
736
737touch /var/log/dovecot.log /var/log/dovecot-info.log /var/log/dovecot-debug.log
738chown vmail:mail /var/log/dovecot*
739chmod 660 /var/log/dovecot*
740
741# Register dovecot service for autostart and start it
742if [[ "$OS" = "CentOs" ]]; then
743 if [[ "$VER" == "7" ]]; then
744 systemctl enable dovecot.service
745 systemctl start dovecot.service
746 else
747 chkconfig dovecot on
748 /etc/init.d/dovecot start
749 fi
750fi
751
752#--- Apache server
753echo -e "\n-- Installing and configuring Apache"
754$PACKAGE_INSTALLER "$HTTP_PCKG"
755if [[ "$OS" = "CentOs" ]]; then
756 $PACKAGE_INSTALLER "$HTTP_PCKG-devel"
757 HTTP_CONF_PATH="/etc/httpd/conf/httpd.conf"
758 HTTP_VARS_PATH="/etc/sysconfig/httpd"
759 HTTP_SERVICE="httpd"
760 HTTP_USER="apache"
761 HTTP_GROUP="apache"
762 if [[ "$VER" = "7" ]]; then
763 # Disable extra modules in centos 7
764 disable_file /etc/httpd/conf.modules.d/01-cgi.conf
765 disable_file /etc/httpd/conf.modules.d/00-lua.conf
766 disable_file /etc/httpd/conf.modules.d/00-dav.conf
767 else
768 disable_file /etc/httpd/conf.d/welcome.conf
769 disable_file /etc/httpd/conf.d/webalizer.conf
770 # Disable more extra modules in centos 6.x /etc/httpd/httpd.conf dav/ldap/cgi/proxy_ajp
771 sed -i "s|LoadModule suexec_module modules|#LoadModule suexec_module modules|" "$HTTP_CONF_PATH"
772 sed -i "s|LoadModule cgi_module modules|#LoadModule cgi_module modules|" "$HTTP_CONF_PATH"
773 sed -i "s|LoadModule dav_module modules|#LoadModule dav_module modules|" "$HTTP_CONF_PATH"
774 sed -i "s|LoadModule dav_fs_module modules|#LoadModule dav_fs_module modules|" "$HTTP_CONF_PATH"
775 sed -i "s|LoadModule proxy_ajp_module modules|#LoadModule proxy_ajp_module modules|" "$HTTP_CONF_PATH"
776
777 fi
778elif [[ "$OS" = "Ubuntu" ]]; then
779 $PACKAGE_INSTALLER libapache2-mod-bw
780 HTTP_CONF_PATH="/etc/apache2/apache2.conf"
781 HTTP_VARS_PATH="/etc/apache2/envvars"
782 HTTP_SERVICE="apache2"
783 HTTP_USER="www-data"
784 HTTP_GROUP="www-data"
785 a2enmod rewrite
786fi
787
788if ! grep -q "Include $PANEL_CONF/apache/httpd.conf" "$HTTP_CONF_PATH"; then
789 echo "Include $PANEL_CONF/apache/httpd.conf" >> "$HTTP_CONF_PATH";
790fi
791add_local_domain "$(hostname)"
792
793if ! grep -q "apache ALL=NOPASSWD: $PANEL_PATH/panel/bin/zsudo" /etc/sudoers; then
794 echo "apache ALL=NOPASSWD: $PANEL_PATH/panel/bin/zsudo" >> /etc/sudoers;
795fi
796
797# Create root directory for public HTTP docs
798mkdir -p $PANEL_DATA/hostdata/zadmin/public_html
799chown -R $HTTP_USER:$HTTP_GROUP $PANEL_DATA/hostdata/
800chmod -R 770 $PANEL_DATA/hostdata/
801
802mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$HTTP_SERVICE' WHERE so_name_vc='httpd_exe'"
803mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$HTTP_SERVICE' WHERE so_name_vc='apache_sn'"
804
805#Set keepalive on (default is off)
806sed -i "s|KeepAlive Off|KeepAlive On|" "$HTTP_CONF_PATH"
807
808# Permissions fix for Apache and ProFTPD (to enable them to play nicely together!)
809if ! grep -q "umask 002" "$HTTP_VARS_PATH"; then
810 echo "umask 002" >> "$HTTP_VARS_PATH";
811fi
812
813# remove default virtual site to ensure Sentora is the default vhost
814if [[ "$OS" = "CentOs" ]]; then
815 sed -i "s|DocumentRoot \"/var/www/html\"|DocumentRoot $PANEL_PATH/panel|" "$HTTP_CONF_PATH"
816elif [[ "$OS" = "Ubuntu" ]]; then
817 # disable completely sites-enabled/000-default.conf
818 if [[ "$VER" = "14.04" ]]; then
819 sed -i "s|IncludeOptional sites-enabled|#&|" "$HTTP_CONF_PATH"
820 else
821 sed -i "s|Include sites-enabled|#&|" "$HTTP_CONF_PATH"
822 fi
823fi
824
825# Comment "NameVirtualHost" and Listen directives that are handled in vhosts file
826if [[ "$OS" = "CentOs" ]]; then
827 sed -i "s|^\(NameVirtualHost .*$\)|#\1\n# NameVirtualHost is now handled in Sentora vhosts file|" "$HTTP_CONF_PATH"
828 sed -i 's|^\(Listen .*$\)|#\1\n# Listen is now handled in Sentora vhosts file|' "$HTTP_CONF_PATH"
829elif [[ "$OS" = "Ubuntu" ]]; then
830 sed -i "s|\(Include ports.conf\)|#\1\n# Ports are now handled in Sentora vhosts file|" "$HTTP_CONF_PATH"
831 disable_file /etc/apache2/ports.conf
832fi
833
834# adjustments for apache 2.4
835if [[ ("$OS" = "CentOs" && "$VER" = "7") ||
836 ("$OS" = "Ubuntu" && "$VER" = "14.04") ]] ; then
837 # Order deny,allow / Deny from all -> Require all denied
838 sed -i 's|Order deny,allow|Require all denied|I' $PANEL_CONF/apache/httpd.conf
839 sed -i '/Deny from all/d' $PANEL_CONF/apache/httpd.conf
840
841 # Order allow,deny / Allow from all -> Require all granted
842 sed -i 's|Order allow,deny|Require all granted|I' $PANEL_CONF/apache/httpd-vhosts.conf
843 sed -i '/Allow from all/d' $PANEL_CONF/apache/httpd-vhosts.conf
844
845 sed -i 's|Order allow,deny|Require all granted|I' $PANEL_PATH/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
846 sed -i '/Allow from all/d' $PANEL_PATH/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
847
848 # Remove NameVirtualHost that is now without effect and generate warning
849 sed -i '/NameVirtualHost/{N;d}' $PANEL_CONF/apache/httpd-vhosts.conf
850 sed -i '/# NameVirtualHost is/ {N;N;N;N;N;d}' $PANEL_PATH/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
851
852 # Options must have ALL (or none) +/- prefix, disable listing directories
853 sed -i 's| FollowSymLinks [-]Indexes| +FollowSymLinks -Indexes|' $PANEL_PATH/panel/modules/apache_admin/hooks/OnDaemonRun.hook.php
854fi
855
856
857#--- PHP
858echo -e "\n-- Installing and configuring PHP"
859if [[ "$OS" = "CentOs" ]]; then
860 $PACKAGE_INSTALLER php php-devel php-gd php-mbstring php-intl php-mysql php-xml php-xmlrpc
861 $PACKAGE_INSTALLER php-mcrypt php-imap #Epel packages
862 PHP_INI_PATH="/etc/php.ini"
863 PHP_EXT_PATH="/etc/php.d"
864elif [[ "$OS" = "Ubuntu" ]]; then
865 $PACKAGE_INSTALLER libapache2-mod-php5.5 php5.5-common php5.5-cli php5.5-mysql php5.5-gd php5.5-mcrypt php5.5-curl php-pear php5.5-imap php5.5-xmlrpc php5.5-xsl php5.5-intl
866 if [ "$VER" = "14.04" ]; then
867 php5enmod mcrypt # missing in the package for Ubuntu 14!
868 else
869 $PACKAGE_INSTALLER php5.5-suhosin
870 fi
871 PHP_INI_PATH="/etc/php5/apache2/php.ini"
872fi
873# Setup php upload dir
874mkdir -p $PANEL_DATA/temp
875chmod 1777 $PANEL_DATA/temp/
876chown -R $HTTP_USER:$HTTP_GROUP $PANEL_DATA/temp/
877
878# Setup php session save directory
879mkdir "$PANEL_DATA/sessions"
880chown $HTTP_USER:$HTTP_GROUP "$PANEL_DATA/sessions"
881chmod 733 "$PANEL_DATA/sessions"
882chmod +t "$PANEL_DATA/sessions"
883
884if [[ "$OS" = "CentOs" ]]; then
885 # Remove session & php values from apache that cause override
886 sed -i "/php_value/d" /etc/httpd/conf.d/php.conf
887elif [[ "$OS" = "Ubuntu" ]]; then
888 sed -i "s|;session.save_path = \"/var/lib/php5\"|session.save_path = \"$PANEL_DATA/sessions\"|" $PHP_INI_PATH
889fi
890sed -i "/php_value/d" $PHP_INI_PATH
891echo "session.save_path = $PANEL_DATA/sessions;">> $PHP_INI_PATH
892
893# setup timezone and upload temp dir
894sed -i "s|;date.timezone =|date.timezone = $tz|" $PHP_INI_PATH
895sed -i "s|;upload_tmp_dir =|upload_tmp_dir = $PANEL_DATA/temp/|" $PHP_INI_PATH
896
897# Disable php signature in headers to hide it from hackers
898sed -i "s|expose_php = On|expose_php = Off|" $PHP_INI_PATH
899
900# Build suhosin for PHP 5.x which is required by Sentora.
901if [[ "$OS" = "CentOs" || ( "$OS" = "Ubuntu" && "$VER" = "14.04") ]] ; then
902 echo -e "\n# Building suhosin"
903 if [[ "$OS" = "Ubuntu" ]]; then
904 $PACKAGE_INSTALLER php5.5-dev
905 fi
906 SUHOSIN_VERSION="0.9.37.1"
907 wget -nv -O suhosin.zip https://github.com/stefanesser/suhosin/archive/$SUHOSIN_VERSION.zip
908 unzip -q suhosin.zip
909 rm -f suhosin.zip
910 cd suhosin-$SUHOSIN_VERSION
911 phpize &> /dev/null
912 ./configure &> /dev/null
913 make &> /dev/null
914 make install
915 cd ..
916 rm -rf suhosin-$SUHOSIN_VERSION
917 if [[ "$OS" = "CentOs" ]]; then
918 echo 'extension=suhosin.so' > $PHP_EXT_PATH/suhosin.ini
919 elif [[ "$OS" = "Ubuntu" ]]; then
920 sed -i 'N;/default extension directory./a\extension=suhosin.so' $PHP_INI_PATH
921 fi
922fi
923
924# Register apache(+php) service for autostart and start it
925if [[ "$OS" = "CentOs" ]]; then
926 if [[ "$VER" == "7" ]]; then
927 systemctl enable "$HTTP_SERVICE.service"
928 systemctl start "$HTTP_SERVICE.service"
929 else
930 chkconfig "$HTTP_SERVICE" on
931 "/etc/init.d/$HTTP_SERVICE" start
932 fi
933fi
934
935
936#--- ProFTPd
937echo -e "\n-- Installing ProFTPD"
938if [[ "$OS" = "CentOs" ]]; then
939 $PACKAGE_INSTALLER proftpd proftpd-mysql
940 FTP_CONF_PATH='/etc/proftpd.conf'
941 sed -i "s|nogroup|nobody|" $PANEL_CONF/proftpd/proftpd-mysql.conf
942elif [[ "$OS" = "Ubuntu" ]]; then
943 $PACKAGE_INSTALLER proftpd-mod-mysql
944 FTP_CONF_PATH='/etc/proftpd/proftpd.conf'
945fi
946
947# Create and init proftpd database
948mysql -u root -p"$mysqlpassword" < $PANEL_CONF/sentora-install/sql/sentora_proftpd.sql
949
950# Create and configure mysql password for proftpd
951proftpdpassword=$(passwordgen);
952sed -i "s|!SQL_PASSWORD!|$proftpdpassword|" $PANEL_CONF/proftpd/proftpd-mysql.conf
953mysql -u root -p"$mysqlpassword" -e "UPDATE mysql.user SET Password=PASSWORD('$proftpdpassword') WHERE User='proftpd' AND Host='localhost'";
954
955# Assign httpd user and group to all users that will be created
956HTTP_UID=$(id -u "$HTTP_USER")
957HTTP_GID=$(sed -nr "s/^$HTTP_GROUP:x:([0-9]+):.*/\1/p" /etc/group)
958mysql -u root -p"$mysqlpassword" -e "ALTER TABLE sentora_proftpd.ftpuser ALTER COLUMN uid SET DEFAULT $HTTP_UID"
959mysql -u root -p"$mysqlpassword" -e "ALTER TABLE sentora_proftpd.ftpuser ALTER COLUMN gid SET DEFAULT $HTTP_GID"
960sed -i "s|!SQL_MIN_ID!|$HTTP_UID|" $PANEL_CONF/proftpd/proftpd-mysql.conf
961
962# Setup proftpd base file to call sentora config
963rm -f "$FTP_CONF_PATH"
964#touch "$FTP_CONF_PATH"
965#echo "include $PANEL_CONF/proftpd/proftpd-mysql.conf" >> "$FTP_CONF_PATH";
966ln -s "$PANEL_CONF/proftpd/proftpd-mysql.conf" "$FTP_CONF_PATH"
967
968# setup proftpd log dir
969mkdir -p $PANEL_DATA/logs/proftpd
970chmod -R 644 $PANEL_DATA/logs/proftpd
971
972# Correct bug from package in Ubutu14.04 which screw service proftpd restart
973# see https://bugs.launchpad.net/ubuntu/+source/proftpd-dfsg/+bug/1246245
974if [[ "$OS" = "Ubuntu" && "$VER" = "14.04" ]]; then
975 sed -i 's|\([ \t]*start-stop-daemon --stop --signal $SIGNAL \)\(--quiet --pidfile "$PIDFILE"\)$|\1--retry 1 \2|' /etc/init.d/proftpd
976fi
977
978# Register proftpd service for autostart and start it
979if [[ "$OS" = "CentOs" ]]; then
980 if [[ "$VER" == "7" ]]; then
981 systemctl enable proftpd.service
982 systemctl start proftpd.service
983 else
984 chkconfig proftpd on
985 /etc/init.d/proftpd start
986 fi
987fi
988
989#--- BIND
990echo -e "\n-- Installing and configuring Bind"
991if [[ "$OS" = "CentOs" ]]; then
992 $PACKAGE_INSTALLER bind bind-utils bind-libs
993 BIND_PATH="/etc/named/"
994 BIND_FILES="/etc"
995 BIND_SERVICE="named"
996 BIND_USER="named"
997elif [[ "$OS" = "Ubuntu" ]]; then
998 $PACKAGE_INSTALLER bind9 bind9utils
999 BIND_PATH="/etc/bind/"
1000 BIND_FILES="/etc/bind"
1001 BIND_SERVICE="bind9"
1002 BIND_USER="bind"
1003 mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='' WHERE so_name_vc='bind_log'"
1004fi
1005mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$BIND_PATH' WHERE so_name_vc='bind_dir'"
1006mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$BIND_SERVICE' WHERE so_name_vc='bind_service'"
1007chmod -R 777 $PANEL_CONF/bind/zones/
1008
1009# Setup logging directory
1010mkdir $PANEL_DATA/logs/bind
1011touch $PANEL_DATA/logs/bind/bind.log $PANEL_DATA/logs/bind/debug.log
1012chown $BIND_USER $PANEL_DATA/logs/bind/bind.log $PANEL_DATA/logs/bind/debug.log
1013chmod 660 $PANEL_DATA/logs/bind/bind.log $PANEL_DATA/logs/bind/debug.log
1014
1015if [[ "$OS" = "CentOs" ]]; then
1016 chmod 751 /var/named
1017 chmod 771 /var/named/data
1018 sed -i 's|bind/zones.rfc1918|named.rfc1912.zones|' $PANEL_CONF/bind/named.conf
1019elif [[ "$OS" = "Ubuntu" ]]; then
1020 mkdir -p /var/named/dynamic
1021 touch /var/named/dynamic/managed-keys.bind
1022 chown -R bind:bind /var/named/
1023 chmod -R 777 $PANEL_CONF/bind/etc
1024
1025 chown root:root $BIND_FILES/rndc.key
1026 chmod 755 $BIND_FILES/rndc.key
1027fi
1028# Some link to enable call from path
1029ln -s /usr/sbin/named-checkconf /usr/bin/named-checkconf
1030ln -s /usr/sbin/named-checkzone /usr/bin/named-checkzone
1031ln -s /usr/sbin/named-compilezone /usr/bin/named-compilezone
1032
1033# Setup acl IP to forbid zone transfer
1034sed -i "s|!SERVER_IP!|$PUBLIC_IP|" $PANEL_CONF/bind/named.conf
1035
1036# Build key and conf files
1037rm -rf $BIND_FILES/named.conf $BIND_FILES/rndc.conf $BIND_FILES/rndc.key
1038rndc-confgen -a -r /dev/urandom
1039cat $BIND_FILES/rndc.key $PANEL_CONF/bind/named.conf > $BIND_FILES/named.conf
1040cat $BIND_FILES/rndc.key $PANEL_CONF/bind/rndc.conf > $BIND_FILES/rndc.conf
1041rm -f $BIND_FILES/rndc.key
1042
1043# Register Bind service for autostart and start it
1044if [[ "$OS" = "CentOs" ]]; then
1045 if [[ "$VER" == "7" ]]; then
1046 systemctl enable named.service
1047 systemctl start named.service
1048 else
1049 chkconfig named on
1050 /etc/init.d/named start
1051 fi
1052fi
1053
1054
1055#--- CRON and ATD
1056echo -e "\n-- Installing and configuring cron tasks"
1057if [[ "$OS" = "CentOs" ]]; then
1058 #cronie & crontabs may be missing
1059 $PACKAGE_INSTALLER crontabs
1060 CRON_DIR="/var/spool/cron"
1061 CRON_SERVICE="crond"
1062elif [[ "$OS" = "Ubuntu" ]]; then
1063 CRON_DIR="/var/spool/cron/crontabs"
1064 CRON_SERVICE="cron"
1065fi
1066CRON_USER="$HTTP_USER"
1067
1068# prepare daemon crontab
1069# sed -i "s|!USER!|$CRON_USER|" "$PANEL_CONF/cron/zdaemon" #it screw update search!#
1070sed -i "s|!USER!|root|" "$PANEL_CONF/cron/zdaemon"
1071cp "$PANEL_CONF/cron/zdaemon" /etc/cron.d/zdaemon
1072chmod 644 /etc/cron.d/zdaemon
1073
1074# prepare user crontabs
1075CRON_FILE="$CRON_DIR/$CRON_USER"
1076mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$CRON_FILE' WHERE so_name_vc='cron_file'"
1077mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$CRON_FILE' WHERE so_name_vc='cron_reload_path'"
1078mysql -u root -p"$mysqlpassword" -e "UPDATE sentora_core.x_settings SET so_value_tx='$CRON_USER' WHERE so_name_vc='cron_reload_user'"
1079{
1080 echo "SHELL=/bin/bash"
1081 echo "PATH=/sbin:/bin:/usr/sbin:/usr/bin"
1082 echo ""
1083} > mycron
1084crontab -u $HTTP_USER mycron
1085rm -f mycron
1086
1087chmod 744 "$CRON_DIR"
1088chown -R $HTTP_USER:$HTTP_USER "$CRON_DIR"
1089chmod 644 "$CRON_FILE"
1090
1091# Register cron and atd services for autostart and start them
1092if [[ "$OS" = "CentOs" ]]; then
1093 if [[ "$VER" == "7" ]]; then
1094 systemctl enable crond.service
1095 systemctl start crond.service
1096 systemctl start atd.service
1097 else
1098 chkconfig crond on
1099 /etc/init.d/crond start
1100 /etc/init.d/atd start
1101 fi
1102fi
1103
1104
1105#--- phpMyAdmin
1106echo -e "\n-- Configuring phpMyAdmin"
1107phpmyadminsecret=$(passwordgen);
1108chmod 644 $PANEL_CONF/phpmyadmin/config.inc.php
1109sed -i "s|\$cfg\['blowfish_secret'\] \= 'SENTORA';|\$cfg\['blowfish_secret'\] \= '$phpmyadminsecret';|" $PANEL_CONF/phpmyadmin/config.inc.php
1110ln -s $PANEL_CONF/phpmyadmin/config.inc.php $PANEL_PATH/panel/etc/apps/phpmyadmin/config.inc.php
1111# Remove phpMyAdmin's setup folder in case it was left behind
1112rm -rf $PANEL_PATH/panel/etc/apps/phpmyadmin/setup
1113
1114
1115#--- Roundcube
1116echo -e "\n-- Configuring Roundcube"
1117
1118# Import roundcube default table
1119mysql -u root -p"$mysqlpassword" < $PANEL_CONF/sentora-install/sql/sentora_roundcube.sql
1120
1121# Create and configure mysql password for roundcube
1122roundcubepassword=$(passwordgen);
1123sed -i "s|!ROUNDCUBE_PASSWORD!|$roundcubepassword|" $PANEL_CONF/roundcube/roundcube_config.inc.php
1124mysql -u root -p"$mysqlpassword" -e "UPDATE mysql.user SET Password=PASSWORD('$roundcubepassword') WHERE User='roundcube' AND Host='localhost'";
1125
1126# Create and configure des key
1127roundcube_des_key=$(passwordgen 24);
1128sed -i "s|!ROUNDCUBE_DESKEY!|$roundcube_des_key|" $PANEL_CONF/roundcube/roundcube_config.inc.php
1129
1130# Create and configure specials directories and rights
1131chown "$HTTP_USER:$HTTP_GROUP" "$PANEL_PATH/panel/etc/apps/webmail/temp"
1132mkdir "$PANEL_DATA/logs/roundcube"
1133chown "$HTTP_USER:$HTTP_GROUP" "$PANEL_DATA/logs/roundcube"
1134
1135# Map config file in roundcube with symbolic links
1136ln -s $PANEL_CONF/roundcube/roundcube_config.inc.php $PANEL_PATH/panel/etc/apps/webmail/config/config.inc.php
1137ln -s $PANEL_CONF/roundcube/sieve_config.inc.php $PANEL_PATH/panel/etc/apps/webmail/plugins/managesieve/config.inc.php
1138
1139
1140#--- Webalizer
1141echo -e "\n-- Configuring Webalizer"
1142$PACKAGE_INSTALLER webalizer
1143if [[ "$OS" = "CentOs" ]]; then
1144 rm -rf /etc/webalizer.conf
1145elif [[ "$OS" = "Ubuntu" ]]; then
1146 rm -rf /etc/webalizer/webalizer.conf
1147fi
1148
1149
1150#--- Set some Sentora database entries using. setso and setzadmin (require PHP)
1151echo -e "\n-- Configuring Sentora"
1152zadminpassword=$(passwordgen);
1153setzadmin --set "$zadminpassword";
1154$PANEL_PATH/panel/bin/setso --set sentora_domain "$PANEL_FQDN"
1155$PANEL_PATH/panel/bin/setso --set server_ip "$PUBLIC_IP"
1156
1157# if not release, set beta version in database
1158if [[ $(echo "$SENTORA_CORE_VERSION" | sed 's|.*-\(beta\).*$|\1|') = "beta" ]] ; then
1159 $PANEL_PATH/panel/bin/setso --set dbversion "$SENTORA_CORE_VERSION"
1160fi
1161
1162# make the daemon to build vhosts file.
1163$PANEL_PATH/panel/bin/setso --set apache_changed "true"
1164php -q $PANEL_PATH/panel/bin/daemon.php
1165
1166
1167#--- Firewall ?
1168
1169#--- Resolv.conf deprotect
1170chattr -i /etc/resolv.conf
1171
1172
1173#--- Restart all services to capture output messages, if any
1174if [[ "$OS" = "CentOs" && "$VER" == "7" ]]; then
1175 # CentOs7 does not return anything except redirection to systemctl :-(
1176 service() {
1177 echo "Restarting $1"
1178 systemctl restart "$1.service"
1179 }
1180fi
1181
1182service "$DB_SERVICE" restart
1183service "$HTTP_SERVICE" restart
1184service postfix restart
1185service dovecot restart
1186service "$CRON_SERVICE" restart
1187service "$BIND_SERVICE" restart
1188service proftpd restart
1189service atd restart
1190
1191#--- Store the passwords for user reference
1192{
1193 echo "Server IP address : $PUBLIC_IP"
1194 echo "Panel URL : http://$PANEL_FQDN"
1195 echo "zadmin Password : $zadminpassword"
1196 echo ""
1197 echo "MySQL Root Password : $mysqlpassword"
1198 echo "MySQL Postfix Password : $postfixpassword"
1199 echo "MySQL ProFTPd Password : $proftpdpassword"
1200 echo "MySQL Roundcube Password : $roundcubepassword"
1201} >> /root/passwords.txt
1202
1203#--- Advise the admin that Sentora is now installed and accessible.
1204{
1205echo "########################################################"
1206echo " Congratulations Sentora has now been installed on your"
1207echo " server. Please review the log file left in /root/ for "
1208echo " any errors encountered during installation."
1209echo ""
1210echo " Login to Sentora at http://$PANEL_FQDN"
1211echo " Sentora Username : zadmin"
1212echo " Sentora Password : $zadminpassword"
1213echo ""
1214echo " MySQL Root Password : $mysqlpassword"
1215echo " MySQL Postfix Password : $postfixpassword"
1216echo " MySQL ProFTPd Password : $proftpdpassword"
1217echo " MySQL Roundcube Password : $roundcubepassword"
1218echo " (theses passwords are saved in /root/passwords.txt)"
1219echo "########################################################"
1220echo ""
1221} &>/dev/tty
1222
1223# Wait until the user have read before restarts the server...
1224if [[ "$INSTALL" != "auto" ]] ; then
1225 while true; do
1226 read -e -p "Restart your server now to complete the install (y/n)? " rsn
1227 case $rsn in
1228 [Yy]* ) break;;
1229 [Nn]* ) exit;
1230 esac
1231 done
1232 shutdown -r now
1233fi