Advertisement
k3rn3lp4n1c

vesta

May 27th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 49.43 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Vesta Debian installer v.05
  4.  
  5. #----------------------------------------------------------#
  6. #                  Variables&Functions                     #
  7. #----------------------------------------------------------#
  8. export PATH=$PATH:/sbin
  9. export DEBIAN_FRONTEND=noninteractive
  10. RHOST='apt.vestacp.com'
  11. CHOST='c.vestacp.com'
  12. VERSION='debian'
  13. VESTA='/usr/local/vesta'
  14. memory=$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])
  15. arch=$(uname -i)
  16. os='debian'
  17. release=$(cat /etc/debian_version|grep -o [0-9]|head -n1)
  18. codename="$(cat /etc/os-release |grep VERSION= |cut -f 2 -d \(|cut -f 1 -d \))"
  19. vestacp="$VESTA/install/$VERSION/$release"
  20.  
  21. if [ "$release" -eq 9 ]; then
  22.     software="nginx apache2 apache2-utils apache2-suexec-custom
  23.        libapache2-mod-ruid2 libapache2-mod-fcgid libapache2-mod-php php
  24.        php-common php-cgi php-mysql php-curl php-fpm php-pgsql awstats
  25.        webalizer vsftpd proftpd-basic bind9 exim4 exim4-daemon-heavy
  26.        clamav-daemon spamassassin dovecot-imapd dovecot-pop3d roundcube-core
  27.        roundcube-mysql roundcube-plugins mysql-server mysql-common
  28.        mysql-client postgresql postgresql-contrib phppgadmin phpmyadmin mc
  29.        flex whois rssh git idn zip sudo bc ftp lsof ntpdate rrdtool quota
  30.        e2fslibs bsdutils e2fsprogs curl imagemagick fail2ban dnsutils
  31.        bsdmainutils cron vesta vesta-nginx vesta-php expect libmail-dkim-perl
  32.        unrar-free vim-common vesta-ioncube vesta-softaculous net-tools unzip"
  33. elif [ "$release" -eq 8 ]; then
  34.     software="nginx apache2 apache2-utils apache2.2-common
  35.        apache2-suexec-custom libapache2-mod-ruid2
  36.        libapache2-mod-fcgid libapache2-mod-php5 php5 php5-common php5-cgi
  37.        php5-mysql php5-curl php5-fpm php5-pgsql awstats webalizer vsftpd
  38.        proftpd-basic bind9 exim4 exim4-daemon-heavy clamav-daemon
  39.        spamassassin dovecot-imapd dovecot-pop3d roundcube-core
  40.        roundcube-mysql roundcube-plugins mysql-server mysql-common
  41.        mysql-client postgresql postgresql-contrib phppgadmin phpMyAdmin mc
  42.        flex whois rssh git idn zip sudo bc ftp lsof ntpdate rrdtool quota
  43.        e2fslibs bsdutils e2fsprogs curl imagemagick fail2ban dnsutils
  44.        bsdmainutils cron vesta vesta-nginx vesta-php expect libmail-dkim-perl
  45.        unrar-free vim-common vesta-ioncube vesta-softaculous net-tools unzip"
  46. else
  47.     software="nginx apache2 apache2-utils apache2.2-common
  48.        apache2-suexec-custom libapache2-mod-ruid2
  49.        libapache2-mod-fcgid libapache2-mod-php5 php5 php5-common php5-cgi
  50.        php5-mysql php5-curl php5-fpm php5-pgsql awstats webalizer vsftpd
  51.        proftpd-basic proftpd-mod-vroot bind9 exim4 exim4-daemon-heavy
  52.        clamav-daemon spamassassin dovecot-imapd dovecot-pop3d roundcube-core
  53.        roundcube-mysql roundcube-plugins mysql-server mysql-common
  54.        mysql-client postgresql postgresql-contrib phppgadmin phpMyAdmin mc
  55.        flex whois rssh git idn zip sudo bc ftp lsof ntpdate rrdtool quota
  56.        e2fslibs bsdutils e2fsprogs curl imagemagick fail2ban dnsutils
  57.        bsdmainutils cron vesta vesta-nginx vesta-php expect unrar-free
  58.        vim-common vesta-ioncube vesta-softaculous net-tools unzip"
  59. fi
  60.  
  61. # Defining help function
  62. help() {
  63.     echo "Usage: $0 [OPTIONS]
  64.  -a, --apache            Install Apache        [yes|no]  default: yes
  65.  -n, --nginx             Install Nginx         [yes|no]  default: yes
  66.  -w, --phpfpm            Install PHP-FPM       [yes|no]  default: no
  67.  -v, --vsftpd            Install Vsftpd        [yes|no]  default: yes
  68.  -j, --proftpd           Install ProFTPD       [yes|no]  default: no
  69.  -k, --named             Install Bind          [yes|no]  default: yes
  70.  -m, --mysql             Install MySQL         [yes|no]  default: yes
  71.  -g, --postgresql        Install PostgreSQL    [yes|no]  default: no
  72.  -d, --mongodb           Install MongoDB       [yes|no]  unsupported
  73.  -x, --exim              Install Exim          [yes|no]  default: yes
  74.  -z, --dovecot           Install Dovecot       [yes|no]  default: yes
  75.  -c, --clamav            Install ClamAV        [yes|no]  default: yes
  76.  -t, --spamassassin      Install SpamAssassin  [yes|no]  default: yes
  77.  -i, --iptables          Install Iptables      [yes|no]  default: yes
  78.  -b, --fail2ban          Install Fail2ban      [yes|no]  default: yes
  79.  -o, --softaculous       Install Softaculous   [yes|no]  default: yes
  80.  -q, --quota             Filesystem Quota      [yes|no]  default: no
  81.  -l, --lang              Default language                default: en
  82.  -y, --interactive       Interactive install   [yes|no]  default: yes
  83.  -s, --hostname          Set hostname
  84.  -e, --email             Set admin email
  85.  -p, --password          Set admin password
  86.  -f, --force             Force installation
  87.  -h, --help              Print this help
  88.  
  89.  Example: bash $0 -e demo@vestacp.com -p p4ssw0rd --apache no --phpfpm yes"
  90.     exit 1
  91. }
  92.  
  93.  
  94. # Defining password-gen function
  95. gen_pass() {
  96.     MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  97.     LENGTH=10
  98.     while [ ${n:=1} -le $LENGTH ]; do
  99.         PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  100.         let n+=1
  101.     done
  102.     echo "$PASS"
  103. }
  104.  
  105. # Defning return code check function
  106. check_result() {
  107.     if [ $1 -ne 0 ]; then
  108.         echo "Error: $2"
  109.         exit $1
  110.     fi
  111. }
  112.  
  113. # Defining function to set default value
  114. set_default_value() {
  115.     eval variable=\$$1
  116.     if [ -z "$variable" ]; then
  117.         eval $1=$2
  118.     fi
  119.     if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then
  120.         eval $1=$2
  121.     fi
  122. }
  123.  
  124. # Define function to set default language value
  125. set_default_lang() {
  126.     if [ -z "$lang" ]; then
  127.         eval lang=$1
  128.     fi
  129.     lang_list="
  130.        ar cz el fa hu ja no pt se ua
  131.        bs da en fi id ka pl ro tr vi
  132.        cn de es fr it nl pt-BR ru tw
  133.        bg ko sr th ur"
  134.     if !(echo $lang_list |grep -w $lang 1>&2>/dev/null); then
  135.         eval lang=$1
  136.     fi
  137. }
  138.  
  139.  
  140. #----------------------------------------------------------#
  141. #                    Verifications                         #
  142. #----------------------------------------------------------#
  143.  
  144. # Creating temporary file
  145. tmpfile=$(mktemp -p /tmp)
  146.  
  147. # Translating argument to --gnu-long-options
  148. for arg; do
  149.     delim=""
  150.     case "$arg" in
  151.         --apache)               args="${args}-a " ;;
  152.         --nginx)                args="${args}-n " ;;
  153.         --phpfpm)               args="${args}-w " ;;
  154.         --vsftpd)               args="${args}-v " ;;
  155.         --proftpd)              args="${args}-j " ;;
  156.         --named)                args="${args}-k " ;;
  157.         --mysql)                args="${args}-m " ;;
  158.         --postgresql)           args="${args}-g " ;;
  159.         --mongodb)              args="${args}-d " ;;
  160.         --exim)                 args="${args}-x " ;;
  161.         --dovecot)              args="${args}-z " ;;
  162.         --clamav)               args="${args}-c " ;;
  163.         --spamassassin)         args="${args}-t " ;;
  164.         --iptables)             args="${args}-i " ;;
  165.         --fail2ban)             args="${args}-b " ;;
  166.         --remi)                 args="${args}-r " ;;
  167.         --softaculous)          args="${args}-o " ;;
  168.         --quota)                args="${args}-q " ;;
  169.         --lang)                 args="${args}-l " ;;
  170.         --interactive)          args="${args}-y " ;;
  171.         --hostname)             args="${args}-s " ;;
  172.         --email)                args="${args}-e " ;;
  173.         --password)             args="${args}-p " ;;
  174.         --force)                args="${args}-f " ;;
  175.         --help)                 args="${args}-h " ;;
  176.         *)                      [[ "${arg:0:1}" == "-" ]] || delim="\""
  177.                                 args="${args}${delim}${arg}${delim} ";;
  178.     esac
  179. done
  180. eval set -- "$args"
  181.  
  182. # Parsing arguments
  183. while getopts "a:n:w:v:j:k:m:g:d:x:z:c:t:i:b:r:o:q:l:y:s:e:p:fh" Option; do
  184.     case $Option in
  185.         a) apache=$OPTARG ;;            # Apache
  186.         n) nginx=$OPTARG ;;             # Nginx
  187.         w) phpfpm=$OPTARG ;;            # PHP-FPM
  188.         v) vsftpd=$OPTARG ;;            # Vsftpd
  189.         j) proftpd=$OPTARG ;;           # Proftpd
  190.         k) named=$OPTARG ;;             # Named
  191.         m) mysql=$OPTARG ;;             # MySQL
  192.         g) postgresql=$OPTARG ;;        # PostgreSQL
  193.         d) mongodb=$OPTARG ;;           # MongoDB (unsupported)
  194.         x) exim=$OPTARG ;;              # Exim
  195.         z) dovecot=$OPTARG ;;           # Dovecot
  196.         c) clamd=$OPTARG ;;             # ClamAV
  197.         t) spamd=$OPTARG ;;             # SpamAssassin
  198.         i) iptables=$OPTARG ;;          # Iptables
  199.         b) fail2ban=$OPTARG ;;          # Fail2ban
  200.         r) remi=$OPTARG ;;              # Remi repo
  201.         o) softaculous=$OPTARG ;;       # Softaculous plugin
  202.         q) quota=$OPTARG ;;             # FS Quota
  203.         l) lang=$OPTARG ;;              # Language
  204.         y) interactive=$OPTARG ;;       # Interactive install
  205.         s) servername=$OPTARG ;;        # Hostname
  206.         e) email=$OPTARG ;;             # Admin email
  207.         p) vpass=$OPTARG ;;             # Admin password
  208.         f) force='yes' ;;               # Force install
  209.         h) help ;;                      # Help
  210.         *) help ;;                      # Print help (default)
  211.     esac
  212. done
  213.  
  214. # Defining default software stack
  215. set_default_value 'nginx' 'yes'
  216. set_default_value 'apache' 'yes'
  217. set_default_value 'phpfpm' 'no'
  218. set_default_value 'vsftpd' 'yes'
  219. set_default_value 'proftpd' 'no'
  220. set_default_value 'named' 'yes'
  221. set_default_value 'mysql' 'yes'
  222. set_default_value 'postgresql' 'no'
  223. set_default_value 'mongodb' 'no'
  224. set_default_value 'exim' 'yes'
  225. set_default_value 'dovecot' 'yes'
  226. if [ $memory -lt 1500000 ]; then
  227.     set_default_value 'clamd' 'no'
  228.     set_default_value 'spamd' 'no'
  229. else
  230.     set_default_value 'clamd' 'yes'
  231.     set_default_value 'spamd' 'yes'
  232. fi
  233. set_default_value 'iptables' 'yes'
  234. set_default_value 'fail2ban' 'yes'
  235. set_default_value 'softaculous' 'yes'
  236. set_default_value 'quota' 'no'
  237. set_default_value 'interactive' 'yes'
  238. set_default_lang 'en'
  239.  
  240. # Checking software conflicts
  241. if [ "$phpfpm" = 'yes' ]; then
  242.     apache='no'
  243.     nginx='yes'
  244. fi
  245. if [ "$proftpd" = 'yes' ]; then
  246.     vsftpd='no'
  247. fi
  248. if [ "$exim" = 'no' ]; then
  249.     clamd='no'
  250.     spamd='no'
  251.     dovecot='no'
  252. fi
  253. if [ "$iptables" = 'no' ]; then
  254.     fail2ban='no'
  255. fi
  256.  
  257. # Checking root permissions
  258. if [ "x$(id -u)" != 'x0' ]; then
  259.     check_error 1 "Script can be run executed only by root"
  260. fi
  261.  
  262. # Checking admin user account
  263. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ -z "$force" ]; then
  264.     echo 'Please remove admin user account before proceeding.'
  265.     echo 'If you want to do it automatically run installer with -f option:'
  266.     echo -e "Example: bash $0 --force\n"
  267.     check_result 1 "User admin exists"
  268. fi
  269.  
  270. # Checking wget
  271. if [ ! -e '/usr/bin/wget' ]; then
  272.     apt-get -y install wget
  273.     check_result $? "Can't install wget"
  274. fi
  275.  
  276. # Checking repository availability
  277. wget -q "c.vestacp.com/deb_signing.key" -O /dev/null
  278. check_result $? "No access to Vesta repository"
  279.  
  280. # Check installed packages
  281. tmpfile=$(mktemp -p /tmp)
  282. dpkg --get-selections > $tmpfile
  283. for pkg in exim4 mysql-server apache2 nginx vesta; do
  284.     if [ ! -z "$(grep $pkg $tmpfile)" ]; then
  285.         conflicts="$pkg $conflicts"
  286.     fi
  287. done
  288. rm -f $tmpfile
  289. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  290.     echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  291.     echo
  292.     echo 'Following packages are already installed:'
  293.     echo "$conflicts"
  294.     echo
  295.     echo 'It is highly recommended to remove them before proceeding.'
  296.     echo 'If you want to force installation run this script with -f option:'
  297.     echo "Example: bash $0 --force"
  298.     echo
  299.     echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  300.     echo
  301.     check_result 1 "Control Panel should be installed on clean server."
  302. fi
  303.  
  304.  
  305. #----------------------------------------------------------#
  306. #                       Brief Info                         #
  307. #----------------------------------------------------------#
  308.  
  309. # Printing nice ascii aslogo
  310. clear
  311. echo
  312. echo ' _|      _|  _|_|_|_|    _|_|_|  _|_|_|_|_|    _|_|'
  313. echo ' _|      _|  _|        _|            _|      _|    _|'
  314. echo ' _|      _|  _|_|_|      _|_|        _|      _|_|_|_|'
  315. echo '   _|  _|    _|              _|      _|      _|    _|'
  316. echo '     _|      _|_|_|_|  _|_|_|        _|      _|    _|'
  317. echo
  318. echo '                                  Vesta Control Panel'
  319. echo -e "\n\n"
  320.  
  321. echo 'Following software will be installed on your system:'
  322.  
  323. # Web stack
  324. if [ "$nginx" = 'yes' ]; then
  325.     echo '   - Nginx Web Server'
  326. fi
  327. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  328.     echo '   - Apache Web Server'
  329. fi
  330. if [ "$apache" = 'yes' ] && [ "$nginx"  = 'yes' ] ; then
  331.     echo '   - Apache Web Server (as backend)'
  332. fi
  333. if [ "$phpfpm"  = 'yes' ]; then
  334.     echo '   - PHP-FPM Application Server'
  335. fi
  336.  
  337. # DNS stack
  338. if [ "$named" = 'yes' ]; then
  339.     echo '   - Bind DNS Server'
  340. fi
  341.  
  342. # Mail Stack
  343. if [ "$exim" = 'yes' ]; then
  344.     echo -n '   - Exim mail server'
  345.     if [ "$clamd" = 'yes'  ] ||  [ "$spamd" = 'yes' ] ; then
  346.         echo -n ' + '
  347.         if [ "$clamd" = 'yes' ]; then
  348.             echo -n 'Antivirus '
  349.         fi
  350.         if [ "$spamd" = 'yes' ]; then
  351.             echo -n 'Antispam'
  352.         fi
  353.     fi
  354.     echo
  355.     if [ "$dovecot" = 'yes' ]; then
  356.         echo '   - Dovecot POP3/IMAP Server'
  357.     fi
  358. fi
  359.  
  360. # DB stack
  361. if [ "$mysql" = 'yes' ]; then
  362.     echo '   - MySQL Database Server'
  363. fi
  364. if [ "$postgresql" = 'yes' ]; then
  365.     echo '   - PostgreSQL Database Server'
  366. fi
  367. if [ "$mongodb" = 'yes' ]; then
  368.     echo '   - MongoDB Database Server'
  369. fi
  370.  
  371. # FTP stack
  372. if [ "$vsftpd" = 'yes' ]; then
  373.     echo '   - Vsftpd FTP Server'
  374. fi
  375. if [ "$proftpd" = 'yes' ]; then
  376.     echo '   - ProFTPD FTP Server'
  377. fi
  378.  
  379. # Softaculous
  380. if [ "$softaculous" = 'yes' ]; then
  381.     echo '   - Softaculous Plugin'
  382. fi
  383.  
  384. # Firewall stack
  385. if [ "$iptables" = 'yes' ]; then
  386.     echo -n '   - Iptables Firewall'
  387. fi
  388. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  389.     echo -n ' + Fail2Ban'
  390. fi
  391. echo -e "\n\n"
  392.  
  393. # Asking for confirmation to proceed
  394. if [ "$interactive" = 'yes' ]; then
  395.     read -p 'Would you like to continue [y/n]: ' answer
  396.     if [ "$answer" != 'y' ] && [ "$answer" != 'Y'  ]; then
  397.         echo 'Goodbye'
  398.         exit 1
  399.     fi
  400.  
  401.     # Asking for contact email
  402.     if [ -z "$email" ]; then
  403.         read -p 'Please enter admin email address: ' email
  404.     fi
  405.  
  406.     # Asking to set FQDN hostname
  407.     if [ -z "$servername" ]; then
  408.         read -p "Please enter FQDN hostname [$(hostname)]: " servername
  409.     fi
  410. fi
  411.  
  412. # Generating admin password if it wasn't set
  413. if [ -z "$vpass" ]; then
  414.     vpass=$(gen_pass)
  415. fi
  416.  
  417. # Set hostname if it wasn't set
  418. if [ -z "$servername" ]; then
  419.     servername=$(hostname -f)
  420. fi
  421.  
  422. # Set FQDN if it wasn't set
  423. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  424. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  425. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  426.     if [ ! -z "$servername" ]; then
  427.         servername="$servername.example.com"
  428.     else
  429.         servername="example.com"
  430.     fi
  431.     echo "127.0.0.1 $servername" >> /etc/hosts
  432. fi
  433.  
  434. # Set email if it wasn't set
  435. if [ -z "$email" ]; then
  436.     email="admin@$servername"
  437. fi
  438.  
  439. # Defining backup directory
  440. vst_backups="/root/vst_install_backups/$(date +%s)"
  441. echo "Installation backup directory: $vst_backups"
  442.  
  443. # Printing start message and sleeping for 5 seconds
  444. echo -e "\n\n\n\nInstallation will take about 15 minutes ...\n"
  445. sleep 5
  446.  
  447.  
  448. #----------------------------------------------------------#
  449. #                      Checking swap                       #
  450. #----------------------------------------------------------#
  451.  
  452. # Checking swap on small instances
  453. if [ -z "$(swapon -s)" ] && [ $memory -lt 1000000 ]; then
  454.     fallocate -l 1G /swapfile
  455.     chmod 600 /swapfile
  456.     mkswap /swapfile
  457.     swapon /swapfile
  458.     echo "/swapfile   none    swap    sw    0   0" >> /etc/fstab
  459. fi
  460.  
  461.  
  462. #----------------------------------------------------------#
  463. #                   Install repository                     #
  464. #----------------------------------------------------------#
  465.  
  466. # Updating system
  467. apt-get -y upgrade
  468. check_result $? 'apt-get upgrade failed'
  469.  
  470. # Installing nginx repo
  471. apt=/etc/apt/sources.list.d
  472. echo "deb http://nginx.org/packages/debian/ $codename nginx" > $apt/nginx.list
  473. wget http://nginx.org/keys/nginx_signing.key -O /tmp/nginx_signing.key
  474. apt-key add /tmp/nginx_signing.key
  475.  
  476. # Installing vesta repo
  477. echo "deb http://$RHOST/$codename/ $codename vesta" > $apt/vesta.list
  478. wget $CHOST/deb_signing.key -O deb_signing.key
  479. apt-key add deb_signing.key
  480.  
  481. # Installing jessie backports
  482. if [ "$release" -eq 8 ]; then
  483.     if [ ! -e /etc/apt/apt.conf ]; then
  484.         echo 'Acquire::Check-Valid-Until "false";' >> /etc/apt/apt.conf
  485.     fi
  486.     if [ ! -e /etc/apt/sources.list.d/backports.list ]; then
  487.         echo "deb http://archive.debian.org/debian jessie-backports main" >\
  488.             /etc/apt/sources.list.d/backports.list
  489.     fi
  490. fi
  491.  
  492.  
  493. #----------------------------------------------------------#
  494. #                         Backup                           #
  495. #----------------------------------------------------------#
  496.  
  497. # Creating backup directory tree
  498. mkdir -p $vst_backups
  499. cd $vst_backups
  500. mkdir nginx apache2 php php5 php5-fpm vsftpd proftpd bind exim4 dovecot clamd
  501. mkdir spamassassin mysql postgresql mongodb vesta
  502.  
  503. # Backing up Nginx configuration
  504. service nginx stop > /dev/null 2>&1
  505. cp -r /etc/nginx/* $vst_backups/nginx >/dev/null 2>&1
  506.  
  507. # Backing up Apache configuration
  508. service apache2 stop > /dev/null 2>&1
  509. cp -r /etc/apache2/* $vst_backups/apache2 > /dev/null 2>&1
  510. rm -f /etc/apache2/conf.d/* > /dev/null 2>&1
  511.  
  512. # Backing up PHP configuration
  513. cp /etc/php.ini $vst_backups/php > /dev/null 2>&1
  514. cp -r /etc/php.d  $vst_backups/php > /dev/null 2>&1
  515.  
  516. # Backing up PHP configuration
  517. service php5-fpm stop >/dev/null 2>&1
  518. cp /etc/php5/* $vst_backups/php5 > /dev/null 2>&1
  519. rm -f /etc/php5/fpm/pool.d/* >/dev/null 2>&1
  520.  
  521. # Backing up Bind configuration
  522. service bind9 stop > /dev/null 2>&1
  523. cp -r /etc/bind/* $vst_backups/bind > /dev/null 2>&1
  524.  
  525. # Backing up Vsftpd configuration
  526. service vsftpd stop > /dev/null 2>&1
  527. cp /etc/vsftpd.conf $vst_backups/vsftpd > /dev/null 2>&1
  528.  
  529. # Backing up ProFTPD configuration
  530. service proftpd stop > /dev/null 2>&1
  531. cp /etc/proftpd.conf $vst_backups/proftpd >/dev/null 2>&1
  532.  
  533. # Backing up Exim configuration
  534. service exim4 stop > /dev/null 2>&1
  535. cp -r /etc/exim4/* $vst_backups/exim4 > /dev/null 2>&1
  536.  
  537. # Backing up ClamAV configuration
  538. service clamav-daemon stop > /dev/null 2>&1
  539. cp -r /etc/clamav/* $vst_backups/clamav > /dev/null 2>&1
  540.  
  541. # Backing up SpamAssassin configuration
  542. service spamassassin stop > /dev/null 2>&1
  543. cp -r /etc/spamassassin/* $vst_backups/spamassassin > /dev/null 2>&1
  544.  
  545. # Backing up Dovecot configuration
  546. service dovecot stop > /dev/null 2>&1
  547. cp /etc/dovecot.conf $vst_backups/dovecot > /dev/null 2>&1
  548. cp -r /etc/dovecot/* $vst_backups/dovecot > /dev/null 2>&1
  549.  
  550. # Backing up MySQL/MariaDB configuration and data
  551. service mysql stop > /dev/null 2>&1
  552. killall -9 mysqld > /dev/null 2>&1
  553. mv /var/lib/mysql $vst_backups/mysql/mysql_datadir > /dev/null 2>&1
  554. cp -r /etc/mysql/* $vst_backups/mysql > /dev/null 2>&1
  555. mv -f /root/.my.cnf $vst_backups/mysql > /dev/null 2>&1
  556.  
  557. # Backup vesta
  558. service vesta stop > /dev/null 2>&1
  559. cp -r $VESTA/* $vst_backups/vesta > /dev/null 2>&1
  560. apt-get -y remove vesta vesta-nginx vesta-php > /dev/null 2>&1
  561. apt-get -y purge vesta vesta-nginx vesta-php > /dev/null 2>&1
  562. rm -rf $VESTA > /dev/null 2>&1
  563.  
  564.  
  565. #----------------------------------------------------------#
  566. #                     Package Excludes                     #
  567. #----------------------------------------------------------#
  568.  
  569. # Excluding packages
  570. if [ "$nginx" = 'no'  ]; then
  571.     software=$(echo "$software" | sed -e "s/^nginx//")
  572. fi
  573. if [ "$apache" = 'no' ]; then
  574.     software=$(echo "$software" | sed -e "s/apache2 //")
  575.     software=$(echo "$software" | sed -e "s/apache2-utils//")
  576.     software=$(echo "$software" | sed -e "s/apache2-suexec-custom//")
  577.     software=$(echo "$software" | sed -e "s/apache2.2-common//")
  578.     software=$(echo "$software" | sed -e "s/libapache2-mod-ruid2//")
  579.     software=$(echo "$software" | sed -e "s/libapache2-mod-fcgid//")
  580.     software=$(echo "$software" | sed -e "s/libapache2-mod-php5//")
  581.     software=$(echo "$software" | sed -e "s/libapache2-mod-php//")
  582. fi
  583. if [ "$phpfpm" = 'no' ]; then
  584.     software=$(echo "$software" | sed -e "s/php5-fpm//")
  585.     software=$(echo "$software" | sed -e "s/php-fpm//")
  586. fi
  587. if [ "$vsftpd" = 'no' ]; then
  588.     software=$(echo "$software" | sed -e "s/vsftpd//")
  589. fi
  590. if [ "$proftpd" = 'no' ]; then
  591.     software=$(echo "$software" | sed -e "s/proftpd-basic//")
  592.     software=$(echo "$software" | sed -e "s/proftpd-mod-vroot//")
  593. fi
  594. if [ "$named" = 'no' ]; then
  595.     software=$(echo "$software" | sed -e "s/bind9//")
  596. fi
  597. if [ "$exim" = 'no' ]; then
  598.     software=$(echo "$software" | sed -e "s/exim4 //")
  599.     software=$(echo "$software" | sed -e "s/exim4-daemon-heavy//")
  600.     software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  601.     software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  602.     software=$(echo "$software" | sed -e "s/clamav-daemon//")
  603.     software=$(echo "$software" | sed -e "s/spamassassin//")
  604. fi
  605. if [ "$clamd" = 'no' ]; then
  606.     software=$(echo "$software" | sed -e "s/clamav-daemon//")
  607. fi
  608. if [ "$spamd" = 'no' ]; then
  609.     software=$(echo "$software" | sed -e "s/spamassassin//")
  610.     software=$(echo "$software" | sed -e "s/libmail-dkim-perl//")
  611. fi
  612. if [ "$dovecot" = 'no' ]; then
  613.     software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  614.     software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  615. fi
  616. if [ "$mysql" = 'no' ]; then
  617.     software=$(echo "$software" | sed -e 's/mysql-server//')
  618.     software=$(echo "$software" | sed -e 's/mysql-client//')
  619.     software=$(echo "$software" | sed -e 's/mysql-common//')
  620.     software=$(echo "$software" | sed -e 's/php5-mysql//')
  621.     software=$(echo "$software" | sed -e 's/php-mysql//')
  622.     software=$(echo "$software" | sed -e 's/phpMyAdmin//')
  623. fi
  624. if [ "$postgresql" = 'no' ]; then
  625.     software=$(echo "$software" | sed -e 's/postgresql-contrib//')
  626.     software=$(echo "$software" | sed -e 's/postgresql//')
  627.     software=$(echo "$software" | sed -e 's/php5-pgsql//')
  628.     software=$(echo "$software" | sed -e 's/php-pgsql//')
  629.     software=$(echo "$software" | sed -e 's/phppgadmin//')
  630. fi
  631. if [ "$softaculous" = 'no' ]; then
  632.     software=$(echo "$software" | sed -e 's/vesta-softaculous//')
  633. fi
  634. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  635.     software=$(echo "$software" | sed -e 's/fail2ban//')
  636. fi
  637.  
  638.  
  639. #----------------------------------------------------------#
  640. #                     Install packages                     #
  641. #----------------------------------------------------------#
  642.  
  643. # Update system packages
  644. apt-get update
  645.  
  646. # Disable daemon autostart /usr/share/doc/sysv-rc/README.policy-rc.d.gz
  647. echo -e '#!/bin/sh \nexit 101' > /usr/sbin/policy-rc.d
  648. chmod a+x /usr/sbin/policy-rc.d
  649.  
  650. # Install apt packages
  651. apt-get -y install $software
  652. check_result $? "apt-get install failed"
  653.  
  654. # Restore  policy
  655. rm -f /usr/sbin/policy-rc.d
  656.  
  657.  
  658. #----------------------------------------------------------#
  659. #                     Configure system                     #
  660. #----------------------------------------------------------#
  661.  
  662. # Enable SSH password auth
  663. sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
  664. service ssh restart
  665.  
  666. # Disable awstats cron
  667. rm -f /etc/cron.d/awstats
  668.  
  669. # Set directory color
  670. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  671.  
  672. # Register /sbin/nologin and /usr/sbin/nologin
  673. echo "/sbin/nologin" >> /etc/shells
  674. echo "/usr/sbin/nologin" >> /etc/shells
  675.  
  676. # NTP Synchronization
  677. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  678. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  679. chmod 775 /etc/cron.daily/ntpdate
  680. ntpdate -s pool.ntp.org
  681.  
  682. # Setup rssh
  683. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  684.     echo /usr/bin/rssh >> /etc/shells
  685. fi
  686. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  687. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  688. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  689. chmod 755 /usr/bin/rssh
  690.  
  691.  
  692. #----------------------------------------------------------#
  693. #                     Configure VESTA                      #
  694. #----------------------------------------------------------#
  695.  
  696. # Installing sudo configuration
  697. mkdir -p /etc/sudoers.d
  698. cp -f $vestacp/sudo/admin /etc/sudoers.d/
  699. chmod 440 /etc/sudoers.d/admin
  700.  
  701. # Configuring system env
  702. echo "export VESTA='$VESTA'" > /etc/profile.d/vesta.sh
  703. chmod 755 /etc/profile.d/vesta.sh
  704. source /etc/profile.d/vesta.sh
  705. echo 'PATH=$PATH:'$VESTA'/bin' >> /root/.bash_profile
  706. echo 'export PATH' >> /root/.bash_profile
  707. source /root/.bash_profile
  708.  
  709. # Configuring logrotate for Vesta logs
  710. cp -f $vestacp/logrotate/vesta /etc/logrotate.d/
  711.  
  712. # Building directory tree and creating some blank files for vesta
  713. mkdir -p $VESTA/conf $VESTA/log $VESTA/ssl $VESTA/data/ips \
  714.     $VESTA/data/queue $VESTA/data/users $VESTA/data/firewall \
  715.     $VESTA/data/sessions
  716. touch $VESTA/data/queue/backup.pipe $VESTA/data/queue/disk.pipe \
  717.     $VESTA/data/queue/webstats.pipe $VESTA/data/queue/restart.pipe \
  718.     $VESTA/data/queue/traffic.pipe $VESTA/log/system.log \
  719.     $VESTA/log/nginx-error.log $VESTA/log/auth.log
  720. chmod 750 $VESTA/conf $VESTA/data/users $VESTA/data/ips $VESTA/log
  721. chmod -R 750 $VESTA/data/queue
  722. chmod 660 $VESTA/log/*
  723. rm -f /var/log/vesta
  724. ln -s $VESTA/log /var/log/vesta
  725. chown admin:admin $VESTA/data/sessions
  726. chmod 770 $VESTA/data/sessions
  727.  
  728. # Generating vesta configuration
  729. rm -f $VESTA/conf/vesta.conf 2>/dev/null
  730. touch $VESTA/conf/vesta.conf
  731. chmod 660 $VESTA/conf/vesta.conf
  732.  
  733. # WEB stack
  734. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  735.     echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  736.     echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  737.     echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  738.     echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  739.     echo "WEB_SSL='mod_ssl'"  >> $VESTA/conf/vesta.conf
  740.     echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  741. fi
  742. if [ "$apache" = 'yes' ] && [ "$nginx"  = 'yes' ] ; then
  743.     echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  744.     echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  745.     echo "WEB_PORT='8080'" >> $VESTA/conf/vesta.conf
  746.     echo "WEB_SSL_PORT='8443'" >> $VESTA/conf/vesta.conf
  747.     echo "WEB_SSL='mod_ssl'"  >> $VESTA/conf/vesta.conf
  748.     echo "PROXY_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  749.     echo "PROXY_PORT='80'" >> $VESTA/conf/vesta.conf
  750.     echo "PROXY_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  751.     echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  752. fi
  753. if [ "$apache" = 'no' ] && [ "$nginx"  = 'yes' ]; then
  754.     echo "WEB_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  755.     echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  756.     echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  757.     echo "WEB_SSL='openssl'"  >> $VESTA/conf/vesta.conf
  758.     if [ "$release" -eq 9 ]; then
  759.         if [ "$phpfpm" = 'yes' ]; then
  760.             echo "WEB_BACKEND='php-fpm'" >> $VESTA/conf/vesta.conf
  761.         fi
  762.     else
  763.         if [ "$phpfpm" = 'yes' ]; then
  764.             echo "WEB_BACKEND='php5-fpm'" >> $VESTA/conf/vesta.conf
  765.         fi
  766.     fi
  767.     echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  768. fi
  769.  
  770. # FTP stack
  771. if [ "$vsftpd" = 'yes' ]; then
  772.     echo "FTP_SYSTEM='vsftpd'" >> $VESTA/conf/vesta.conf
  773. fi
  774. if [ "$proftpd" = 'yes' ]; then
  775.     echo "FTP_SYSTEM='proftpd'" >> $VESTA/conf/vesta.conf
  776. fi
  777.  
  778. # DNS stack
  779. if [ "$named" = 'yes' ]; then
  780.     echo "DNS_SYSTEM='bind9'" >> $VESTA/conf/vesta.conf
  781. fi
  782.  
  783. # Mail stack
  784. if [ "$exim" = 'yes' ]; then
  785.     echo "MAIL_SYSTEM='exim4'" >> $VESTA/conf/vesta.conf
  786.     if [ "$clamd" = 'yes'  ]; then
  787.         echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $VESTA/conf/vesta.conf
  788.     fi
  789.     if [ "$spamd" = 'yes' ]; then
  790.         echo "ANTISPAM_SYSTEM='spamassassin'" >> $VESTA/conf/vesta.conf
  791.     fi
  792.     if [ "$dovecot" = 'yes' ]; then
  793.         echo "IMAP_SYSTEM='dovecot'" >> $VESTA/conf/vesta.conf
  794.     fi
  795. fi
  796.  
  797. # CRON daemon
  798. echo "CRON_SYSTEM='cron'" >> $VESTA/conf/vesta.conf
  799.  
  800. # Firewall stack
  801. if [ "$iptables" = 'yes' ]; then
  802.     echo "FIREWALL_SYSTEM='iptables'" >> $VESTA/conf/vesta.conf
  803. fi
  804. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  805.     echo "FIREWALL_EXTENSION='fail2ban'" >> $VESTA/conf/vesta.conf
  806. fi
  807.  
  808. # Disk quota
  809. if [ "$quota" = 'yes' ]; then
  810.     echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
  811. fi
  812.  
  813. # Backups
  814. echo "BACKUP_SYSTEM='local'" >> $VESTA/conf/vesta.conf
  815.  
  816. # Language
  817. echo "LANGUAGE='$lang'" >> $VESTA/conf/vesta.conf
  818.  
  819. # Version
  820. echo "VERSION='0.9.8'" >> $VESTA/conf/vesta.conf
  821.  
  822. # Installing hosting packages
  823. cp -rf $vestacp/packages $VESTA/data/
  824.  
  825. # Installing templates
  826. cp -rf $vestacp/templates $VESTA/data/
  827.  
  828. # Copying index.html to default documentroot
  829. cp $VESTA/data/templates/web/skel/public_html/index.html /var/www/
  830. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  831.  
  832. # Installing firewall rules
  833. cp -rf $vestacp/firewall $VESTA/data/
  834.  
  835. # Configuring server hostname
  836. $VESTA/bin/v-change-sys-hostname $servername 2>/dev/null
  837.  
  838. # Generating SSL certificate
  839. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  840.      'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  841.  
  842. # Parsing certificate file
  843. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  844. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  845. key_end=$(grep -n  "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  846.  
  847. # Adding SSL certificate
  848. cd $VESTA/ssl
  849. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  850. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  851. chown root:mail $VESTA/ssl/*
  852. chmod 660 $VESTA/ssl/*
  853. rm /tmp/vst.pem
  854.  
  855.  
  856. #----------------------------------------------------------#
  857. #                     Configure Nginx                      #
  858. #----------------------------------------------------------#
  859.  
  860. if [ "$nginx" = 'yes' ]; then
  861.     rm -f /etc/nginx/conf.d/*.conf
  862.     cp -f $vestacp/nginx/nginx.conf /etc/nginx/
  863.     cp -f $vestacp/nginx/status.conf /etc/nginx/conf.d/
  864.     cp -f $vestacp/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  865.     cp -f $vestacp/nginx/phppgadmin.inc /etc/nginx/conf.d/
  866.     cp -f $vestacp/nginx/webmail.inc /etc/nginx/conf.d/
  867.     cp -f $vestacp/logrotate/nginx /etc/logrotate.d/
  868.     echo > /etc/nginx/conf.d/vesta.conf
  869.     mkdir -p /var/log/nginx/domains
  870.     update-rc.d nginx defaults
  871.     service nginx start
  872.     check_result $? "nginx start failed"
  873. fi
  874.  
  875.  
  876. #----------------------------------------------------------#
  877. #                    Configure Apache                      #
  878. #----------------------------------------------------------#
  879.  
  880. if [ "$apache" = 'yes'  ]; then
  881.     cp -f $vestacp/apache2/apache2.conf /etc/apache2/
  882.     cp -f $vestacp/apache2/status.conf /etc/apache2/mods-enabled/
  883.     cp -f  $vestacp/logrotate/apache2 /etc/logrotate.d/
  884.     a2enmod rewrite
  885.     a2enmod suexec
  886.     a2enmod ssl
  887.     a2enmod actions
  888.     a2enmod ruid2
  889.     a2enmod headers
  890.     mkdir -p /etc/apache2/conf.d
  891.     echo > /etc/apache2/conf.d/vesta.conf
  892.     echo "# Powered by vesta" > /etc/apache2/sites-available/default
  893.     echo "# Powered by vesta" > /etc/apache2/sites-available/default-ssl
  894.     echo "# Powered by vesta" > /etc/apache2/ports.conf
  895.     echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  896.     touch /var/log/apache2/access.log /var/log/apache2/error.log
  897.     mkdir -p /var/log/apache2/domains
  898.     chmod a+x /var/log/apache2
  899.     chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  900.     chmod 751 /var/log/apache2/domains
  901.     update-rc.d apache2 defaults
  902.     service apache2 start
  903.     check_result $? "apache2 start failed"
  904. else
  905.     update-rc.d apache2 disable >/dev/null 2>&1
  906.     service apache2 stop >/dev/null 2>&1
  907. fi
  908.  
  909.  
  910. #----------------------------------------------------------#
  911. #                     Configure PHP-FPM                    #
  912. #----------------------------------------------------------#
  913.  
  914. if [ "$phpfpm" = 'yes' ]; then
  915.     if [ "$release" -eq 9 ]; then
  916.         cp -f $vestacp/php-fpm/www.conf /etc/php/7.0/fpm/pool.d/www.conf
  917.         update-rc.d php7.0-fpm defaults
  918.         service php7.0-fpm start
  919.         check_result $? "php-fpm start failed"
  920.     else
  921.         cp -f $vestacp/php5-fpm/www.conf /etc/php5/fpm/pool.d/www.conf
  922.         update-rc.d php5-fpm defaults
  923.         service php5-fpm start
  924.         check_result $? "php-fpm start failed"
  925.     fi
  926. fi
  927.  
  928.  
  929. #----------------------------------------------------------#
  930. #                     Configure PHP                        #
  931. #----------------------------------------------------------#
  932.  
  933. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  934. if [ -z "$ZONE" ]; then
  935.     ZONE='UTC'
  936. fi
  937. for pconf in $(find /etc/php* -name php.ini); do
  938.     sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  939.     sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  940. done
  941.  
  942.  
  943. #----------------------------------------------------------#
  944. #                    Configure VSFTPD                      #
  945. #----------------------------------------------------------#
  946.  
  947. if [ "$vsftpd" = 'yes' ]; then
  948.     cp -f $vestacp/vsftpd/vsftpd.conf /etc/
  949.     update-rc.d vsftpd defaults
  950.     service vsftpd start
  951.     check_result $? "vsftpd start failed"
  952.  
  953.     # To be deleted after release 0.9.8-18
  954.     echo "/sbin/nologin" >> /etc/shells
  955. fi
  956.  
  957.  
  958. #----------------------------------------------------------#
  959. #                    Configure ProFTPD                     #
  960. #----------------------------------------------------------#
  961.  
  962. if [ "$proftpd" = 'yes' ]; then
  963.     echo "127.0.0.1 $servername" >> /etc/hosts
  964.     cp -f $vestacp/proftpd/proftpd.conf /etc/proftpd/
  965.     update-rc.d proftpd defaults
  966.     service proftpd start
  967.     check_result $? "proftpd start failed"
  968. fi
  969.  
  970.  
  971. #----------------------------------------------------------#
  972. #                  Configure MySQL/MariaDB                 #
  973. #----------------------------------------------------------#
  974.  
  975. if [ "$mysql" = 'yes' ]; then
  976.     mycnf="my-small.cnf"
  977.     if [ $memory -gt 1200000 ]; then
  978.         mycnf="my-medium.cnf"
  979.     fi
  980.     if [ $memory -gt 3900000 ]; then
  981.         mycnf="my-large.cnf"
  982.     fi
  983.  
  984.     # MySQL configuration
  985.     cp -f $vestacp/mysql/$mycnf /etc/mysql/my.cnf
  986.     mysql_install_db
  987.     update-rc.d mysql defaults
  988.     service mysql start
  989.     check_result $? "mysql start failed"
  990.  
  991.     # Securing MySQL installation
  992.     mpass=$(gen_pass)
  993.     mysqladmin -u root password $mpass
  994.     echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  995.     chmod 600 /root/.my.cnf
  996.     mysql -e "DELETE FROM mysql.user WHERE User=''"
  997.     mysql -e "DROP DATABASE test" >/dev/null 2>&1
  998.     mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  999.     mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  1000.     mysql -e "FLUSH PRIVILEGES"
  1001.  
  1002.     # Configuring phpMyAdmin
  1003.     if [ "$apache" = 'yes' ]; then
  1004.         cp -f $vestacp/pma/apache.conf /etc/phpmyadmin/
  1005.         ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  1006.     fi
  1007.     cp -f $vestacp/pma/config.inc.php /etc/phpmyadmin/
  1008.     chmod 777 /var/lib/phpmyadmin/tmp
  1009. fi
  1010.  
  1011. #----------------------------------------------------------#
  1012. #                   Configure PostgreSQL                   #
  1013. #----------------------------------------------------------#
  1014.  
  1015. if [ "$postgresql" = 'yes' ]; then
  1016.     ppass=$(gen_pass)
  1017.     cp -f $vestacp/postgresql/pg_hba.conf /etc/postgresql/*/main/
  1018.     service postgresql restart
  1019.     sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  1020.  
  1021.     # Configuring phpPgAdmin
  1022.     if [ "$apache" = 'yes' ]; then
  1023.         cp -f $vestacp/pga/phppgadmin.conf /etc/apache2/conf.d/
  1024.     fi
  1025.     cp -f $vestacp/pga/config.inc.php /etc/phppgadmin/
  1026. fi
  1027.  
  1028.  
  1029. #----------------------------------------------------------#
  1030. #                      Configure Bind                      #
  1031. #----------------------------------------------------------#
  1032.  
  1033. if [ "$named" = 'yes' ]; then
  1034.     cp -f $vestacp/bind/named.conf /etc/bind/
  1035.     sed -i "s%listen-on%//listen%" /etc/bind/named.conf.options
  1036.     chown root:bind /etc/bind/named.conf
  1037.     chmod 640 /etc/bind/named.conf
  1038.     aa-complain /usr/sbin/named 2>/dev/null
  1039.     echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2>/dev/null
  1040.     service apparmor status >/dev/null 2>&1
  1041.     if [ $? -ne 0 ]; then
  1042.         service apparmor restart
  1043.     fi
  1044.     update-rc.d bind9 defaults
  1045.     service bind9 start
  1046.     check_result $? "bind9 start failed"
  1047. fi
  1048.  
  1049. #----------------------------------------------------------#
  1050. #                      Configure Exim                      #
  1051. #----------------------------------------------------------#
  1052.  
  1053. if [ "$exim" = 'yes' ]; then
  1054.     gpasswd -a Debian-exim mail
  1055.     cp -f $vestacp/exim/exim4.conf.template /etc/exim4/
  1056.     cp -f $vestacp/exim/dnsbl.conf /etc/exim4/
  1057.     cp -f $vestacp/exim/spam-blocks.conf /etc/exim4/
  1058.     touch /etc/exim4/white-blocks.conf
  1059.  
  1060.     if [ "$spamd" = 'yes' ]; then
  1061.         sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  1062.     fi
  1063.     if [ "$clamd" = 'yes' ]; then
  1064.         sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  1065.     fi
  1066.  
  1067.     chmod 640 /etc/exim4/exim4.conf.template
  1068.     rm -rf /etc/exim4/domains
  1069.     mkdir -p /etc/exim4/domains
  1070.  
  1071.     rm -f /etc/alternatives/mta
  1072.     ln -s /usr/sbin/exim4 /etc/alternatives/mta
  1073.     update-rc.d -f sendmail remove > /dev/null 2>&1
  1074.     service sendmail stop > /dev/null 2>&1
  1075.     update-rc.d -f postfix remove > /dev/null 2>&1
  1076.     service postfix stop > /dev/null 2>&1
  1077.  
  1078.     update-rc.d exim4 defaults
  1079.     service exim4 start
  1080.     check_result $? "exim4 start failed"
  1081. fi
  1082.  
  1083.  
  1084. #----------------------------------------------------------#
  1085. #                     Configure Dovecot                    #
  1086. #----------------------------------------------------------#
  1087.  
  1088. if [ "$dovecot" = 'yes' ]; then
  1089.     gpasswd -a dovecot mail
  1090.     cp -rf $vestacp/dovecot /etc/
  1091.     cp -f $vestacp/logrotate/dovecot /etc/logrotate.d/
  1092.     chown -R root:root /etc/dovecot*
  1093.     if [ "$release" -eq 9 ]; then
  1094.         sed -i "s#namespace inbox {#namespace inbox {\n  inbox = yes#" /etc/dovecot/conf.d/15-mailboxes.conf
  1095.     fi
  1096.     update-rc.d dovecot defaults
  1097.     service dovecot start
  1098.     check_result $? "dovecot start failed"
  1099. fi
  1100.  
  1101.  
  1102. #----------------------------------------------------------#
  1103. #                     Configure ClamAV                     #
  1104. #----------------------------------------------------------#
  1105.  
  1106. if [ "$clamd" = 'yes' ]; then
  1107.     gpasswd -a clamav mail
  1108.     gpasswd -a clamav Debian-exim
  1109.     cp -f $vestacp/clamav/clamd.conf /etc/clamav/
  1110.     /usr/bin/freshclam
  1111.     update-rc.d clamav-daemon defaults
  1112.     if [ ! -d "/var/run/clamav" ]; then
  1113.         mkdir /var/run/clamav
  1114.     fi
  1115.     chown -R clamav:clamav /var/run/clamav
  1116.     if [ -e "/lib/systemd/system/clamav-daemon.service" ]; then
  1117.         exec_pre1='ExecStartPre=-/bin/mkdir -p /var/run/clamav'
  1118.         exec_pre2='ExecStartPre=-/bin/chown -R clamav:clamav /var/run/clamav'
  1119.         sed -i "s|\[Service\]/|[Service]\n$exec_pre1\n$exec_pre2|g" \
  1120.             /lib/systemd/system/clamav-daemon.service
  1121.         systemctl daemon-reload
  1122.     fi
  1123.     service clamav-daemon start
  1124.     check_result $? "clamav-daeom start failed"
  1125. fi
  1126.  
  1127.  
  1128. #----------------------------------------------------------#
  1129. #                  Configure SpamAssassin                  #
  1130. #----------------------------------------------------------#
  1131.  
  1132. if [ "$spamd" = 'yes' ]; then
  1133.     update-rc.d spamassassin defaults
  1134.     sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  1135.     service spamassassin start
  1136.     check_result $? "spamassassin start failed"
  1137.     unit_files="$(systemctl list-unit-files |grep spamassassin)"
  1138.     if [[ "$unit_files" =~ "disabled" ]]; then
  1139.         systemctl enable spamassassin
  1140.     fi
  1141. fi
  1142.  
  1143.  
  1144. #----------------------------------------------------------#
  1145. #                   Configure RoundCube                    #
  1146. #----------------------------------------------------------#
  1147.  
  1148. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1149.     if [ "$apache" = 'yes' ]; then
  1150.         cp -f $vestacp/roundcube/apache.conf /etc/roundcube/
  1151.         ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  1152.     fi
  1153.     cp -f $vestacp/roundcube/main.inc.php /etc/roundcube/
  1154.     cp -f  $vestacp/roundcube/db.inc.php /etc/roundcube/
  1155.     chmod 640 /etc/roundcube/debian-db-roundcube.php
  1156.     chmod 640 /etc/roundcube/config.inc.php
  1157.     chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1158.     chown root:www-data /etc/roundcube/config.inc.php
  1159.     cp -f $vestacp/roundcube/vesta.php \
  1160.         /usr/share/roundcube/plugins/password/drivers/
  1161.     cp -f $vestacp/roundcube/config.inc.php /etc/roundcube/plugins/password/
  1162.     r="$(gen_pass)"
  1163.     mysql -e "CREATE DATABASE roundcube"
  1164.     mysql -e "GRANT ALL ON roundcube.*
  1165.        TO roundcube@localhost IDENTIFIED BY '$r'"
  1166.     sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  1167.     sed -i "s/localhost/$servername/g" \
  1168.         /etc/roundcube/plugins/password/config.inc.php
  1169.     mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  1170.     chmod a+r /etc/roundcube/main.inc.php
  1171.     if [ "$release" -eq 8 ] || [ "$release" -eq 9 ]; then
  1172.         mv -f /etc/roundcube/main.inc.php /etc/roundcube/config.inc.php
  1173.         mv -f /etc/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  1174.         chmod 640 /etc/roundcube/debian-db-roundcube.php
  1175.         chmod 640 /etc/roundcube/config.inc.php
  1176.         chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1177.         chown root:www-data /etc/roundcube/config.inc.php
  1178.     fi
  1179.     if [ "$release" -eq 8 ]; then
  1180.         # RoundCube tinyMCE fix
  1181.         tinymceFixArchiveURL=$vestacp/roundcube/roundcube-tinymce.tar.gz
  1182.         tinymceParentFolder=/usr/share/roundcube/program/js
  1183.         tinymceFolder=$tinymceParentFolder/tinymce
  1184.         tinymceBadJS=$tinymceFolder/tiny_mce.js
  1185.         tinymceFixArchive=$tinymceParentFolder/roundcube-tinymce.tar.gz
  1186.         if [[ -L "$tinymceFolder" && -d "$tinymceFolder" ]]; then
  1187.             if [ -f "$tinymceBadJS" ]; then
  1188.                 wget $tinymceFixArchiveURL -O $tinymceFixArchive
  1189.                 if [[ -f "$tinymceFixArchive" && -s "$tinymceFixArchive" ]]
  1190.                 then
  1191.                     rm $tinymceFolder
  1192.                     tar -xzf $tinymceFixArchive -C $tinymceParentFolder
  1193.                     rm $tinymceFixArchive
  1194.                     chown -R root:root $tinymceFolder
  1195.                 else
  1196.                     echo -n "File roundcube-tinymce.tar.gz is not downloaded,"
  1197.                     echo "RoundCube tinyMCE fix is not applied"
  1198.                     rm $tinymceFixArchive
  1199.                 fi
  1200.             fi
  1201.         fi
  1202.  
  1203.     fi
  1204. fi
  1205.  
  1206.  
  1207. #----------------------------------------------------------#
  1208. #                    Configure Fail2Ban                    #
  1209. #----------------------------------------------------------#
  1210.  
  1211. if [ "$fail2ban" = 'yes' ]; then
  1212.     cp -rf $vestacp/fail2ban /etc/
  1213.     if [ "$dovecot" = 'no' ]; then
  1214.         fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1215.         fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1216.         sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1217.     fi
  1218.     if [ "$exim" = 'no' ]; then
  1219.         fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1220.         fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1221.         sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1222.     fi
  1223.     if [ "$vsftpd" = 'yes' ]; then
  1224.         #Create vsftpd Log File
  1225.         if [ ! -f "/var/log/vsftpd.log" ]; then
  1226.             touch /var/log/vsftpd.log
  1227.         fi
  1228.         fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1229.         fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1230.         sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1231.     fi
  1232.     update-rc.d fail2ban defaults
  1233.     service fail2ban start
  1234.     check_result $? "fail2ban start failed"
  1235. fi
  1236.  
  1237.  
  1238. #----------------------------------------------------------#
  1239. #                   Configure Admin User                   #
  1240. #----------------------------------------------------------#
  1241.  
  1242. # Deleting old admin user
  1243. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1244.     chattr -i /home/admin/conf > /dev/null 2>&1
  1245.     userdel -f admin >/dev/null 2>&1
  1246.     chattr -i /home/admin/conf >/dev/null 2>&1
  1247.     mv -f /home/admin  $vst_backups/home/ >/dev/null 2>&1
  1248.     rm -f /tmp/sess_* >/dev/null 2>&1
  1249. fi
  1250. if [ ! -z "$(grep ^admin: /etc/group)" ]; then
  1251.     groupdel admin > /dev/null 2>&1
  1252. fi
  1253.  
  1254. # Adding vesta account
  1255. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  1256. check_result $? "can't create admin user"
  1257. $VESTA/bin/v-change-user-shell admin bash
  1258. $VESTA/bin/v-change-user-language admin $lang
  1259.  
  1260. # RoundCube permissions fix
  1261. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1262.     if [ ! -d "/var/log/roundcube" ]; then
  1263.         mkdir /var/log/roundcube
  1264.     fi
  1265.     chown admin:admin /var/log/roundcube
  1266. fi
  1267.  
  1268. # Configuring system ips
  1269. $VESTA/bin/v-update-sys-ip
  1270.  
  1271. # Get main ip
  1272. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1273. local_ip=$ip
  1274.  
  1275. # Firewall configuration
  1276. if [ "$iptables" = 'yes' ]; then
  1277.     $VESTA/bin/v-update-firewall
  1278. fi
  1279.  
  1280. # Get public ip
  1281. pub_ip=$(curl -s vestacp.com/what-is-my-ip/)
  1282.  
  1283. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1284.     $VESTA/bin/v-change-sys-ip-nat $ip $pub_ip
  1285.     ip=$pub_ip
  1286. fi
  1287.  
  1288. # Configuring libapache2-mod-remoteip
  1289. if [ "$apache" = 'yes' ] && [ "$nginx"  = 'yes' ] ; then
  1290.     cd /etc/apache2/mods-available
  1291.     echo "<IfModule mod_remoteip.c>" > remoteip.conf
  1292.     echo "  RemoteIPHeader X-Real-IP" >> remoteip.conf
  1293.     if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ip" != "127.0.0.1" ]; then
  1294.         echo "  RemoteIPInternalProxy 127.0.0.1" >> remoteip.conf
  1295.     fi
  1296.     if [ ! -z "$local_ip" ] && [ "$local_ip" != "$pub_ip" ]; then
  1297.         echo "  RemoteIPInternalProxy $local_ip" >> remoteip.conf
  1298.     fi
  1299.     if [ ! -z "$pub_ip" ]; then
  1300.         echo "  RemoteIPInternalProxy $pub_ip" >> remoteip.conf
  1301.     fi
  1302.     echo "</IfModule>" >> remoteip.conf
  1303.     sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  1304.     a2enmod remoteip
  1305.     service apache2 restart
  1306. fi
  1307.  
  1308. # Configuring mysql host
  1309. if [ "$mysql" = 'yes' ]; then
  1310.     $VESTA/bin/v-add-database-host mysql localhost root $mpass
  1311.     $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  1312. fi
  1313.  
  1314. # Configuring pgsql host
  1315. if [ "$postgresql" = 'yes' ]; then
  1316.     $VESTA/bin/v-add-database-host pgsql localhost postgres $ppass
  1317.     $VESTA/bin/v-add-database admin db db $(gen_pass) pgsql
  1318. fi
  1319.  
  1320. # Adding default domain
  1321. $VESTA/bin/v-add-domain admin $servername
  1322. check_result $? "can't create $servername domain"
  1323.  
  1324. # Adding cron jobs
  1325. command="sudo $VESTA/bin/v-update-sys-queue disk"
  1326. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1327. command="sudo $VESTA/bin/v-update-sys-queue traffic"
  1328. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1329. command="sudo $VESTA/bin/v-update-sys-queue webstats"
  1330. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1331. command="sudo $VESTA/bin/v-update-sys-queue backup"
  1332. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1333. command="sudo $VESTA/bin/v-backup-users"
  1334. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1335. command="sudo $VESTA/bin/v-update-user-stats"
  1336. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1337. command="sudo $VESTA/bin/v-update-sys-rrd"
  1338. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1339. service cron restart
  1340.  
  1341. # Building inititall rrd images
  1342. $VESTA/bin/v-update-sys-rrd
  1343.  
  1344. # Enabling file system quota
  1345. if [ "$quota" = 'yes' ]; then
  1346.     $VESTA/bin/v-add-sys-quota
  1347. fi
  1348.  
  1349. # Enabling softaculous plugin
  1350. if [ "$softaculous" = 'yes' ]; then
  1351.     $VESTA/bin/v-add-vesta-softaculous
  1352. fi
  1353.  
  1354. # Starting vesta service
  1355. update-rc.d vesta defaults
  1356. service vesta start
  1357. check_result $? "vesta start failed"
  1358. chown admin:admin $VESTA/data/sessions
  1359.  
  1360. # Adding notifications
  1361. $VESTA/upd/add_notifications.sh
  1362.  
  1363. # Adding cronjob for autoupdates
  1364. $VESTA/bin/v-add-cron-vesta-autoupdate
  1365.  
  1366.  
  1367. #----------------------------------------------------------#
  1368. #                   Vesta Access Info                      #
  1369. #----------------------------------------------------------#
  1370.  
  1371. # Comparing hostname and ip
  1372. host_ip=$(host $servername| head -n 1 | awk '{print $NF}')
  1373. if [ "$host_ip" = "$ip" ]; then
  1374.     ip="$servername"
  1375. fi
  1376.  
  1377. # Sending notification to admin email
  1378. echo -e "Congratulations, you have just successfully installed \
  1379. Vesta Control Panel
  1380.  
  1381.    https://$ip:8083
  1382.    username: admin
  1383.    password: $vpass
  1384.  
  1385. We hope that you enjoy your installation of Vesta. Please \
  1386. feel free to contact us anytime if you have any questions.
  1387. Thank you.
  1388.  
  1389. --
  1390. Sincerely yours
  1391. vestacp.com team
  1392. " > $tmpfile
  1393.  
  1394. send_mail="$VESTA/web/inc/mail-wrapper.php"
  1395. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  1396.  
  1397. # Congrats
  1398. echo '======================================================='
  1399. echo
  1400. echo ' _|      _|  _|_|_|_|    _|_|_|  _|_|_|_|_|    _|_|   '
  1401. echo ' _|      _|  _|        _|            _|      _|    _| '
  1402. echo ' _|      _|  _|_|_|      _|_|        _|      _|_|_|_| '
  1403. echo '   _|  _|    _|              _|      _|      _|    _| '
  1404. echo '     _|      _|_|_|_|  _|_|_|        _|      _|    _| '
  1405. echo
  1406. echo
  1407. cat $tmpfile
  1408. rm -f $tmpfile
  1409.  
  1410. # EOF
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement