vst-install-ubuntu.sh 44 KB

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