Advertisement
Guest User

Untitled

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