vst-install-ubuntu.sh 43 KB

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