vst-install-ubuntu.sh 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378
  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="nginx 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
  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)" ] && [ -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. # Checking universe repository
  401. if [[ ${release:0:2} -gt 16 ]]; then
  402. if [ -z "$(grep universe /etc/apt/sources.list)" ]; then
  403. add-apt-repository -y universe
  404. fi
  405. fi
  406. # Installing nginx repo
  407. apt=/etc/apt/sources.list.d
  408. echo "deb http://nginx.org/packages/mainline/ubuntu/ $codename nginx" \
  409. > $apt/nginx.list
  410. wget http://nginx.org/keys/nginx_signing.key -O /tmp/nginx_signing.key
  411. apt-key add /tmp/nginx_signing.key
  412. # Installing vesta repo
  413. echo "deb http://$RHOST/$codename/ $codename vesta" > $apt/vesta.list
  414. wget $CHOST/deb_signing.key -O deb_signing.key
  415. apt-key add deb_signing.key
  416. #----------------------------------------------------------#
  417. # Backup #
  418. #----------------------------------------------------------#
  419. # Creating backup directory tree
  420. mkdir -p $vst_backups
  421. cd $vst_backups
  422. mkdir nginx apache2 php vsftpd proftpd bind exim4 dovecot clamd
  423. mkdir spamassassin mysql postgresql mongodb vesta
  424. # Backup nginx configuration
  425. service nginx stop > /dev/null 2>&1
  426. cp -r /etc/nginx/* $vst_backups/nginx >/dev/null 2>&1
  427. # Backup Apache configuration
  428. service apache2 stop > /dev/null 2>&1
  429. cp -r /etc/apache2/* $vst_backups/apache2 > /dev/null 2>&1
  430. rm -f /etc/apache2/conf.d/* > /dev/null 2>&1
  431. # Backup PHP-FPM configuration
  432. service php7.0-fpm stop > /dev/null 2>&1
  433. service php5-fpm stop > /dev/null 2>&1
  434. service php-fpm stop > /dev/null 2>&1
  435. cp -r /etc/php7.0/* $vst_backups/php/ > /dev/null 2>&1
  436. cp -r /etc/php5/* $vst_backups/php/ > /dev/null 2>&1
  437. cp -r /etc/php/* $vst_backups/php/ > /dev/null 2>&1
  438. # Backup Bind configuration
  439. service bind9 stop > /dev/null 2>&1
  440. cp -r /etc/bind/* $vst_backups/bind > /dev/null 2>&1
  441. # Backup Vsftpd configuration
  442. service vsftpd stop > /dev/null 2>&1
  443. cp /etc/vsftpd.conf $vst_backups/vsftpd > /dev/null 2>&1
  444. # Backup ProFTPD configuration
  445. service proftpd stop > /dev/null 2>&1
  446. cp /etc/proftpd.conf $vst_backups/proftpd > /dev/null 2>&1
  447. # Backup Exim configuration
  448. service exim4 stop > /dev/null 2>&1
  449. cp -r /etc/exim4/* $vst_backups/exim4 > /dev/null 2>&1
  450. # Backup ClamAV configuration
  451. service clamav-daemon stop > /dev/null 2>&1
  452. cp -r /etc/clamav/* $vst_backups/clamav > /dev/null 2>&1
  453. # Backup SpamAssassin configuration
  454. service spamassassin stop > /dev/null 2>&1
  455. cp -r /etc/spamassassin/* $vst_backups/spamassassin > /dev/null 2>&1
  456. # Backup Dovecot configuration
  457. service dovecot stop > /dev/null 2>&1
  458. cp /etc/dovecot.conf $vst_backups/dovecot > /dev/null 2>&1
  459. cp -r /etc/dovecot/* $vst_backups/dovecot > /dev/null 2>&1
  460. # Backup MySQL/MariaDB configuration and data
  461. service mysql stop > /dev/null 2>&1
  462. killall -9 mysqld > /dev/null 2>&1
  463. mv /var/lib/mysql $vst_backups/mysql/mysql_datadir > /dev/null 2>&1
  464. cp -r /etc/mysql/* $vst_backups/mysql > /dev/null 2>&1
  465. mv -f /root/.my.cnf $vst_backups/mysql > /dev/null 2>&1
  466. if [ "$release" = '16.04' ] && [ -e '/etc/init.d/mysql' ]; then
  467. mkdir -p /var/lib/mysql > /dev/null 2>&1
  468. chown mysql:mysql /var/lib/mysql
  469. mysqld --initialize-insecure
  470. fi
  471. # Backup Vesta
  472. service vesta stop > /dev/null 2>&1
  473. cp -r $VESTA/* $vst_backups/vesta > /dev/null 2>&1
  474. apt-get -y remove vesta vesta-nginx vesta-php > /dev/null 2>&1
  475. apt-get -y purge vesta vesta-nginx vesta-php > /dev/null 2>&1
  476. rm -rf $VESTA > /dev/null 2>&1
  477. #----------------------------------------------------------#
  478. # Package Excludes #
  479. #----------------------------------------------------------#
  480. # Excluding packages
  481. if [ "$release" != "15.04" ] && [ "$release" != "15.04" ]; then
  482. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  483. fi
  484. if [ "$nginx" = 'no' ]; then
  485. software=$(echo "$software" | sed -e "s/^nginx//")
  486. fi
  487. if [ "$apache" = 'no' ]; then
  488. software=$(echo "$software" | sed -e "s/apache2 //")
  489. software=$(echo "$software" | sed -e "s/apache2-utils//")
  490. software=$(echo "$software" | sed -e "s/apache2-suexec-custom//")
  491. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  492. software=$(echo "$software" | sed -e "s/libapache2-mod-ruid2//")
  493. software=$(echo "$software" | sed -e "s/libapache2-mod-rpaf//")
  494. software=$(echo "$software" | sed -e "s/libapache2-mod-fcgid//")
  495. software=$(echo "$software" | sed -e "s/libapache2-mod-php7.0//")
  496. software=$(echo "$software" | sed -e "s/libapache2-mod-php5//")
  497. software=$(echo "$software" | sed -e "s/libapache2-mod-php//")
  498. fi
  499. if [ "$phpfpm" = 'no' ]; then
  500. software=$(echo "$software" | sed -e "s/php7.0-fpm//")
  501. software=$(echo "$software" | sed -e "s/php5-fpm//")
  502. software=$(echo "$software" | sed -e "s/php-fpm//")
  503. fi
  504. if [ "$vsftpd" = 'no' ]; then
  505. software=$(echo "$software" | sed -e "s/vsftpd//")
  506. fi
  507. if [ "$proftpd" = 'no' ]; then
  508. software=$(echo "$software" | sed -e "s/proftpd-basic//")
  509. software=$(echo "$software" | sed -e "s/proftpd-mod-vroot//")
  510. fi
  511. if [ "$named" = 'no' ]; then
  512. software=$(echo "$software" | sed -e "s/bind9//")
  513. fi
  514. if [ "$exim" = 'no' ]; then
  515. software=$(echo "$software" | sed -e "s/exim4 //")
  516. software=$(echo "$software" | sed -e "s/exim4-daemon-heavy//")
  517. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  518. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  519. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  520. software=$(echo "$software" | sed -e "s/spamassassin//")
  521. fi
  522. if [ "$clamd" = 'no' ]; then
  523. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  524. fi
  525. if [ "$spamd" = 'no' ]; then
  526. software=$(echo "$software" | sed -e "s/spamassassin//")
  527. fi
  528. if [ "$dovecot" = 'no' ]; then
  529. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  530. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  531. fi
  532. if [ "$mysql" = 'no' ]; then
  533. software=$(echo "$software" | sed -e 's/mysql-server//')
  534. software=$(echo "$software" | sed -e 's/mysql-client//')
  535. software=$(echo "$software" | sed -e 's/mysql-common//')
  536. software=$(echo "$software" | sed -e 's/php7.0-mysql//')
  537. software=$(echo "$software" | sed -e 's/php5-mysql//')
  538. software=$(echo "$software" | sed -e 's/php-mysql//')
  539. software=$(echo "$software" | sed -e 's/phpMyAdmin//')
  540. software=$(echo "$software" | sed -e 's/phpmyadmin//')
  541. fi
  542. if [ "$postgresql" = 'no' ]; then
  543. software=$(echo "$software" | sed -e 's/postgresql-contrib//')
  544. software=$(echo "$software" | sed -e 's/postgresql//')
  545. software=$(echo "$software" | sed -e 's/php7.0-pgsql//')
  546. software=$(echo "$software" | sed -e 's/php5-pgsql//')
  547. software=$(echo "$software" | sed -e 's/php-pgsql//')
  548. software=$(echo "$software" | sed -e 's/phppgadmin//')
  549. fi
  550. if [ "$softaculous" = 'no' ]; then
  551. software=$(echo "$software" | sed -e 's/vesta-softaculous//')
  552. fi
  553. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  554. software=$(echo "$software" | sed -e 's/fail2ban//')
  555. fi
  556. #----------------------------------------------------------#
  557. # Install packages #
  558. #----------------------------------------------------------#
  559. # Updating system
  560. apt-get update
  561. # Disabling daemon autostart on apt-get install
  562. echo -e '#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d
  563. chmod a+x /usr/sbin/policy-rc.d
  564. # Installing apt packages
  565. apt-get -y install $software
  566. check_result $? "apt-get install failed"
  567. # Restoring autostart policy
  568. rm -f /usr/sbin/policy-rc.d
  569. #----------------------------------------------------------#
  570. # Configure system #
  571. #----------------------------------------------------------#
  572. # Enabling SSH password auth
  573. sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
  574. service ssh restart
  575. # Disabling AWStats cron
  576. rm -f /etc/cron.d/awstats
  577. # Set directory color
  578. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  579. # Registering /usr/sbin/nologin
  580. if [ -z "$(grep nologin /etc/shells)" ]; then
  581. echo "/usr/sbin/nologin" >> /etc/shells
  582. fi
  583. # Configuring NTP
  584. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  585. echo "$(which ntpdate) -s ntp.ubuntu.com" >> /etc/cron.daily/ntpdate
  586. chmod 775 /etc/cron.daily/ntpdate
  587. ntpdate -s ntp.ubuntu.com
  588. # Adding rssh
  589. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  590. echo /usr/bin/rssh >> /etc/shells
  591. fi
  592. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  593. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  594. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  595. chmod 755 /usr/bin/rssh
  596. #----------------------------------------------------------#
  597. # Configure Vesta #
  598. #----------------------------------------------------------#
  599. # Installing sudo configuration
  600. mkdir -p /etc/sudoers.d
  601. cp -f $vestacp/sudo/admin /etc/sudoers.d/
  602. chmod 440 /etc/sudoers.d/admin
  603. # Configuring system env
  604. echo "export VESTA='$VESTA'" > /etc/profile.d/vesta.sh
  605. chmod 755 /etc/profile.d/vesta.sh
  606. source /etc/profile.d/vesta.sh
  607. echo 'PATH=$PATH:'$VESTA'/bin' >> /root/.bash_profile
  608. echo 'export PATH' >> /root/.bash_profile
  609. source /root/.bash_profile
  610. # Configuring logrotate for Vesta logs
  611. cp -f $vestacp/logrotate/vesta /etc/logrotate.d/
  612. # Building directory tree and creating some blank files for Vesta
  613. mkdir -p $VESTA/conf $VESTA/log $VESTA/ssl $VESTA/data/ips \
  614. $VESTA/data/queue $VESTA/data/users $VESTA/data/firewall \
  615. $VESTA/data/sessions
  616. touch $VESTA/data/queue/backup.pipe $VESTA/data/queue/disk.pipe \
  617. $VESTA/data/queue/webstats.pipe $VESTA/data/queue/restart.pipe \
  618. $VESTA/data/queue/traffic.pipe $VESTA/log/system.log \
  619. $VESTA/log/nginx-error.log $VESTA/log/auth.log
  620. chmod 750 $VESTA/conf $VESTA/data/users $VESTA/data/ips $VESTA/log
  621. chmod -R 750 $VESTA/data/queue
  622. chmod 660 $VESTA/log/*
  623. rm -f /var/log/vesta
  624. ln -s $VESTA/log /var/log/vesta
  625. chmod 770 $VESTA/data/sessions
  626. # Generating Vesta configuration
  627. rm -f $VESTA/conf/vesta.conf 2>/dev/null
  628. touch $VESTA/conf/vesta.conf
  629. chmod 660 $VESTA/conf/vesta.conf
  630. # Web stack
  631. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  632. echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  633. echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  634. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  635. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  636. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  637. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  638. fi
  639. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  640. echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  641. echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  642. echo "WEB_PORT='8080'" >> $VESTA/conf/vesta.conf
  643. echo "WEB_SSL_PORT='8443'" >> $VESTA/conf/vesta.conf
  644. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  645. echo "PROXY_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  646. echo "PROXY_PORT='80'" >> $VESTA/conf/vesta.conf
  647. echo "PROXY_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  648. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  649. fi
  650. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  651. echo "WEB_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  652. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  653. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  654. echo "WEB_SSL='openssl'" >> $VESTA/conf/vesta.conf
  655. if [ "$phpfpm" = 'yes' ]; then
  656. echo "WEB_BACKEND='php-fpm'" >> $VESTA/conf/vesta.conf
  657. fi
  658. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  659. fi
  660. # FTP stack
  661. if [ "$vsftpd" = 'yes' ]; then
  662. echo "FTP_SYSTEM='vsftpd'" >> $VESTA/conf/vesta.conf
  663. fi
  664. if [ "$proftpd" = 'yes' ]; then
  665. echo "FTP_SYSTEM='proftpd'" >> $VESTA/conf/vesta.conf
  666. fi
  667. # DNS stack
  668. if [ "$named" = 'yes' ]; then
  669. echo "DNS_SYSTEM='bind9'" >> $VESTA/conf/vesta.conf
  670. fi
  671. # Mail stack
  672. if [ "$exim" = 'yes' ]; then
  673. echo "MAIL_SYSTEM='exim4'" >> $VESTA/conf/vesta.conf
  674. if [ "$clamd" = 'yes' ]; then
  675. echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $VESTA/conf/vesta.conf
  676. fi
  677. if [ "$spamd" = 'yes' ]; then
  678. echo "ANTISPAM_SYSTEM='spamassassin'" >> $VESTA/conf/vesta.conf
  679. fi
  680. if [ "$dovecot" = 'yes' ]; then
  681. echo "IMAP_SYSTEM='dovecot'" >> $VESTA/conf/vesta.conf
  682. fi
  683. fi
  684. # Cron daemon
  685. echo "CRON_SYSTEM='cron'" >> $VESTA/conf/vesta.conf
  686. # Firewall stack
  687. if [ "$iptables" = 'yes' ]; then
  688. echo "FIREWALL_SYSTEM='iptables'" >> $VESTA/conf/vesta.conf
  689. fi
  690. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  691. echo "FIREWALL_EXTENSION='fail2ban'" >> $VESTA/conf/vesta.conf
  692. fi
  693. # Disk quota
  694. if [ "$quota" = 'yes' ]; then
  695. echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
  696. fi
  697. # Backups
  698. echo "BACKUP_SYSTEM='local'" >> $VESTA/conf/vesta.conf
  699. # Language
  700. echo "LANGUAGE='$lang'" >> $VESTA/conf/vesta.conf
  701. # Version
  702. echo "VERSION='0.9.8'" >> $VESTA/conf/vesta.conf
  703. # Installing hosting packages
  704. cp -rf $vestacp/packages $VESTA/data/
  705. # Installing templates
  706. cp -rf $vestacp/templates $VESTA/data/
  707. # Copying index.html to default documentroot
  708. cp $VESTA/data/templates/web/skel/public_html/index.html /var/www/
  709. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  710. # Installing firewall rules
  711. cp -rf $vestacp/firewall $VESTA/data/
  712. # Configuring server hostname
  713. $VESTA/bin/v-change-sys-hostname $servername 2>/dev/null
  714. # Generating SSL certificate
  715. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  716. 'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  717. # Parsing certificate file
  718. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  719. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  720. key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  721. # Adding SSL certificate
  722. cd $VESTA/ssl
  723. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  724. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  725. chown root:mail $VESTA/ssl/*
  726. chmod 660 $VESTA/ssl/*
  727. rm /tmp/vst.pem
  728. # Adding nologin as a valid system shell
  729. if [ -z "$(grep nologin /etc/shells)" ]; then
  730. echo "/usr/sbin/nologin" >> /etc/shells
  731. fi
  732. #----------------------------------------------------------#
  733. # Configure Nginx #
  734. #----------------------------------------------------------#
  735. if [ "$nginx" = 'yes' ]; then
  736. rm -f /etc/nginx/conf.d/*.conf
  737. cp -f $vestacp/nginx/nginx.conf /etc/nginx/
  738. cp -f $vestacp/nginx/status.conf /etc/nginx/conf.d/
  739. cp -f $vestacp/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  740. cp -f $vestacp/nginx/phppgadmin.inc /etc/nginx/conf.d/
  741. cp -f $vestacp/nginx/webmail.inc /etc/nginx/conf.d/
  742. cp -f $vestacp/logrotate/nginx /etc/logrotate.d/
  743. echo > /etc/nginx/conf.d/vesta.conf
  744. mkdir -p /var/log/nginx/domains
  745. update-rc.d nginx defaults
  746. service nginx start
  747. check_result $? "nginx start failed"
  748. fi
  749. #----------------------------------------------------------#
  750. # Configure Apache #
  751. #----------------------------------------------------------#
  752. if [ "$apache" = 'yes' ]; then
  753. cp -f $vestacp/apache2/apache2.conf /etc/apache2/
  754. cp -f $vestacp/apache2/status.conf /etc/apache2/mods-enabled/
  755. cp -f $vestacp/logrotate/apache2 /etc/logrotate.d/
  756. a2enmod rewrite
  757. a2enmod suexec
  758. a2enmod ssl
  759. a2enmod actions
  760. a2enmod ruid2
  761. mkdir -p /etc/apache2/conf.d
  762. echo > /etc/apache2/conf.d/vesta.conf
  763. echo "# Powered by vesta" > /etc/apache2/sites-available/default
  764. echo "# Powered by vesta" > /etc/apache2/sites-available/default-ssl
  765. echo "# Powered by vesta" > /etc/apache2/ports.conf
  766. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  767. touch /var/log/apache2/access.log /var/log/apache2/error.log
  768. mkdir -p /var/log/apache2/domains
  769. chmod a+x /var/log/apache2
  770. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  771. chmod 751 /var/log/apache2/domains
  772. update-rc.d apache2 defaults
  773. service apache2 start
  774. check_result $? "apache2 start failed"
  775. else
  776. update-rc.d apache2 disable >/dev/null 2>&1
  777. service apache2 stop >/dev/null 2>&1
  778. fi
  779. #----------------------------------------------------------#
  780. # Configure PHP-FPM #
  781. #----------------------------------------------------------#
  782. if [ "$phpfpm" = 'yes' ]; then
  783. pool=$(find /etc/php* -type d \( -name "pool.d" -o -name "*fpm.d" \))
  784. cp -f $vestacp/php-fpm/www.conf $pool/
  785. php_fpm=$(ls /etc/init.d/php*-fpm* |cut -f 4 -d /)
  786. ln -s /etc/init.d/$php_fpm /etc/init.d/php-fpm > /dev/null 2>&1
  787. update-rc.d $php_fpm defaults
  788. service $php_fpm start
  789. check_result $? "php-fpm start failed"
  790. fi
  791. #----------------------------------------------------------#
  792. # Configure PHP #
  793. #----------------------------------------------------------#
  794. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  795. if [ -z "$ZONE" ]; then
  796. ZONE='UTC'
  797. fi
  798. for pconf in $(find /etc/php* -name php.ini); do
  799. sed -i "s%;date.timezone =%date.timezone = $ZONE%g" $pconf
  800. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  801. done
  802. #----------------------------------------------------------#
  803. # Configure Vsftpd #
  804. #----------------------------------------------------------#
  805. if [ "$vsftpd" = 'yes' ]; then
  806. cp -f $vestacp/vsftpd/vsftpd.conf /etc/
  807. touch /var/log/vsftpd.log
  808. chown root:adm /var/log/vsftpd.log
  809. chmod 640 /var/log/vsftpd.log
  810. touch /var/log/xferlog
  811. chown root:adm /var/log/xferlog
  812. chmod 640 /var/log/xferlog
  813. update-rc.d vsftpd defaults
  814. service vsftpd start
  815. check_result $? "vsftpd start failed"
  816. fi
  817. #----------------------------------------------------------#
  818. # Configure ProFTPD #
  819. #----------------------------------------------------------#
  820. if [ "$proftpd" = 'yes' ]; then
  821. echo "127.0.0.1 $servername" >> /etc/hosts
  822. cp -f $vestacp/proftpd/proftpd.conf /etc/proftpd/
  823. update-rc.d proftpd defaults
  824. service proftpd start
  825. check_result $? "proftpd start failed"
  826. fi
  827. #----------------------------------------------------------#
  828. # Configure MySQL/MariaDB #
  829. #----------------------------------------------------------#
  830. if [ "$mysql" = 'yes' ]; then
  831. mycnf="my-small.cnf"
  832. if [ $memory -gt 1200000 ]; then
  833. mycnf="my-medium.cnf"
  834. fi
  835. if [ $memory -gt 3900000 ]; then
  836. mycnf="my-large.cnf"
  837. fi
  838. # Configuring MySQL/MariaDB
  839. cp -f $vestacp/mysql/$mycnf /etc/mysql/my.cnf
  840. if [ "$release" != '16.04' ]; then
  841. mysql_install_db
  842. fi
  843. if [ "$release" == '18.04' ]; then
  844. mkdir /var/lib/mysql
  845. chown mysql:mysql /var/lib/mysql
  846. mysqld --initialize-insecure
  847. fi
  848. update-rc.d mysql defaults
  849. service mysql start
  850. check_result $? "mysql start failed"
  851. # Securing MySQL/MariaDB installation
  852. mpass=$(gen_pass)
  853. mysqladmin -u root password $mpass
  854. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  855. chmod 600 /root/.my.cnf
  856. mysql -e "DELETE FROM mysql.user WHERE User=''"
  857. mysql -e "DROP DATABASE test" >/dev/null 2>&1
  858. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  859. mysql -e "DELETE FROM mysql.user WHERE user='' OR password='';"
  860. mysql -e "FLUSH PRIVILEGES"
  861. # Configuring phpMyAdmin
  862. if [ "$apache" = 'yes' ]; then
  863. cp -f $vestacp/pma/apache.conf /etc/phpmyadmin/
  864. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  865. fi
  866. if [[ ${release:0:2} -ge 18 ]]; then
  867. mysql < /usr/share/phpmyadmin/sql/create_tables.sql
  868. p=$(grep dbpass /etc/phpmyadmin/config-db.php |cut -f 2 -d "'")
  869. mysql -e "GRANT ALL ON phpmyadmin.*
  870. TO phpmyadmin@localhost IDENTIFIED BY '$p'"
  871. else
  872. cp -f $vestacp/pma/config.inc.php /etc/phpmyadmin/
  873. fi
  874. chmod 777 /var/lib/phpmyadmin/tmp
  875. fi
  876. #----------------------------------------------------------#
  877. # Configure PostgreSQL #
  878. #----------------------------------------------------------#
  879. if [ "$postgresql" = 'yes' ]; then
  880. ppass=$(gen_pass)
  881. cp -f $vestacp/postgresql/pg_hba.conf /etc/postgresql/*/main/
  882. service postgresql restart
  883. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  884. # Configuring phpPgAdmin
  885. if [ "$apache" = 'yes' ]; then
  886. cp -f $vestacp/pga/phppgadmin.conf /etc/apache2/conf.d/
  887. fi
  888. cp -f $vestacp/pga/config.inc.php /etc/phppgadmin/
  889. fi
  890. #----------------------------------------------------------#
  891. # Configure Bind #
  892. #----------------------------------------------------------#
  893. if [ "$named" = 'yes' ]; then
  894. cp -f $vestacp/bind/named.conf /etc/bind/
  895. sed -i "s%listen-on%//listen%" /etc/bind/named.conf.options
  896. chown root:bind /etc/bind/named.conf
  897. chmod 640 /etc/bind/named.conf
  898. aa-complain /usr/sbin/named 2>/dev/null
  899. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2>/dev/null
  900. service apparmor status >/dev/null 2>&1
  901. if [ $? -ne 0 ]; then
  902. service apparmor restart
  903. fi
  904. update-rc.d bind9 defaults
  905. service bind9 start
  906. check_result $? "bind9 start failed"
  907. # Workaround for OpenVZ/Virtuozzo
  908. if [ -e "/proc/vz/veinfo" ]; then
  909. sed -i "s/^exit 0/service bind9 restart\nexit 0/" /etc/rc.local
  910. fi
  911. fi
  912. #----------------------------------------------------------#
  913. # Configure Exim #
  914. #----------------------------------------------------------#
  915. if [ "$exim" = 'yes' ]; then
  916. gpasswd -a Debian-exim mail
  917. cp -f $vestacp/exim/exim4.conf.template /etc/exim4/
  918. cp -f $vestacp/exim/dnsbl.conf /etc/exim4/
  919. cp -f $vestacp/exim/spam-blocks.conf /etc/exim4/
  920. touch /etc/exim4/white-blocks.conf
  921. if [ "$spamd" = 'yes' ]; then
  922. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  923. fi
  924. if [ "$clamd" = 'yes' ]; then
  925. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  926. fi
  927. chmod 640 /etc/exim4/exim4.conf.template
  928. rm -rf /etc/exim4/domains
  929. mkdir -p /etc/exim4/domains
  930. rm -f /etc/alternatives/mta
  931. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  932. update-rc.d -f sendmail remove > /dev/null 2>&1
  933. service sendmail stop > /dev/null 2>&1
  934. update-rc.d -f postfix remove > /dev/null 2>&1
  935. service postfix stop > /dev/null 2>&1
  936. update-rc.d exim4 defaults
  937. service exim4 start
  938. check_result $? "exim4 start failed"
  939. fi
  940. #----------------------------------------------------------#
  941. # Configure Dovecot #
  942. #----------------------------------------------------------#
  943. if [ "$dovecot" = 'yes' ]; then
  944. gpasswd -a dovecot mail
  945. if [[ ${release:0:2} -ge 18 ]]; then
  946. cp -r /usr/local/vesta/install/debian/9/dovecot /etc/
  947. if [ -z "$(grep yes /etc/dovecot/conf.d/10-mail.conf)" ]; then
  948. echo "namespace inbox {" >> /etc/dovecot/conf.d/10-mail.conf
  949. echo " inbox = yes" >> /etc/dovecot/conf.d/10-mail.conf
  950. echo "}" >> /etc/dovecot/conf.d/10-mail.conf
  951. echo "first_valid_uid = 1000" >> /etc/dovecot/conf.d/10-mail.conf
  952. echo "mbox_write_locks = fcntl" >> /etc/dovecot/conf.d/10-mail.conf
  953. fi
  954. else
  955. cp -rf $vestacp/dovecot /etc/
  956. fi
  957. cp -f $vestacp/logrotate/dovecot /etc/logrotate.d/
  958. chown -R root:root /etc/dovecot*
  959. update-rc.d dovecot defaults
  960. service dovecot start
  961. check_result $? "dovecot start failed"
  962. fi
  963. #----------------------------------------------------------#
  964. # Configure ClamAV #
  965. #----------------------------------------------------------#
  966. if [ "$clamd" = 'yes' ]; then
  967. gpasswd -a clamav mail
  968. gpasswd -a clamav Debian-exim
  969. cp -f $vestacp/clamav/clamd.conf /etc/clamav/
  970. /usr/bin/freshclam
  971. update-rc.d clamav-daemon defaults
  972. service clamav-daemon start
  973. check_result $? "clamav-daemon start failed"
  974. fi
  975. #----------------------------------------------------------#
  976. # Configure SpamAssassin #
  977. #----------------------------------------------------------#
  978. if [ "$spamd" = 'yes' ]; then
  979. update-rc.d spamassassin defaults
  980. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  981. service spamassassin start
  982. check_result $? "spamassassin start failed"
  983. unit_files="$(systemctl list-unit-files |grep spamassassin)"
  984. if [[ "$unit_files" =~ "disabled" ]]; then
  985. systemctl enable spamassassin
  986. fi
  987. fi
  988. #----------------------------------------------------------#
  989. # Configure Roundcube #
  990. #----------------------------------------------------------#
  991. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  992. if [ "$apache" = 'yes' ]; then
  993. cp -f $vestacp/roundcube/apache.conf /etc/roundcube/
  994. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  995. fi
  996. if [[ ${release:0:2} -ge 18 ]]; then
  997. r=$(grep dbpass= /etc/roundcube/debian-db.php |cut -f 2 -d "'")
  998. sed -i "s/default_host.*/default_host'] = 'localhost';/" \
  999. /etc/roundcube/config.inc.php
  1000. sed -i "s/^);/'password');/" /etc/roundcube/config.inc.php
  1001. else
  1002. r="$(gen_pass)"
  1003. cp -f $vestacp/roundcube/main.inc.php /etc/roundcube/
  1004. cp -f $vestacp/roundcube/db.inc.php /etc/roundcube/
  1005. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  1006. fi
  1007. if [ "$release" = '16.04' ]; then
  1008. # TBD: should be fixed in config repo
  1009. mv /etc/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  1010. mv /etc/roundcube/main.inc.php /etc/roundcube/config.inc.php
  1011. chmod 640 /etc/roundcube/debian-db-roundcube.php
  1012. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1013. fi
  1014. cp -f $vestacp/roundcube/vesta.php \
  1015. /usr/share/roundcube/plugins/password/drivers/
  1016. cp -f $vestacp/roundcube/config.inc.php /etc/roundcube/plugins/password/
  1017. mysql -e "CREATE DATABASE roundcube"
  1018. mysql -e "GRANT ALL ON roundcube.*
  1019. TO roundcube@localhost IDENTIFIED BY '$r'"
  1020. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  1021. chmod 640 /etc/roundcube/debian-db*
  1022. chown root:www-data /etc/roundcube/debian-db*
  1023. touch /var/log/roundcube/errors
  1024. chmod 640 /var/log/roundcube/errors
  1025. chown www-data:adm /var/log/roundcube/errors
  1026. php5enmod mcrypt 2>/dev/null
  1027. phpenmod mcrypt 2>/dev/null
  1028. if [ "$apache" = 'yes' ]; then
  1029. service apache2 restart
  1030. fi
  1031. if [ "$nginx" = 'yes' ]; then
  1032. service nginx restart
  1033. fi
  1034. fi
  1035. #----------------------------------------------------------#
  1036. # Configure Fail2Ban #
  1037. #----------------------------------------------------------#
  1038. if [ "$fail2ban" = 'yes' ]; then
  1039. cp -rf $vestacp/fail2ban /etc/
  1040. if [ "$dovecot" = 'no' ]; then
  1041. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1042. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1043. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1044. fi
  1045. if [ "$exim" = 'no' ]; then
  1046. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1047. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1048. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1049. fi
  1050. if [ "$vsftpd" = 'yes' ]; then
  1051. #Create vsftpd Log File
  1052. if [ ! -f "/var/log/vsftpd.log" ]; then
  1053. touch /var/log/vsftpd.log
  1054. fi
  1055. fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1056. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1057. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1058. fi
  1059. update-rc.d fail2ban defaults
  1060. service fail2ban start
  1061. check_result $? "fail2ban start failed"
  1062. fi
  1063. #----------------------------------------------------------#
  1064. # Configure Admin User #
  1065. #----------------------------------------------------------#
  1066. # Deleting old admin user
  1067. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1068. chattr -i /home/admin/conf > /dev/null 2>&1
  1069. userdel -f admin >/dev/null 2>&1
  1070. chattr -i /home/admin/conf >/dev/null 2>&1
  1071. mv -f /home/admin $vst_backups/home/ >/dev/null 2>&1
  1072. rm -f /tmp/sess_* >/dev/null 2>&1
  1073. fi
  1074. if [ ! -z "$(grep ^admin: /etc/group)" ]; then
  1075. groupdel admin > /dev/null 2>&1
  1076. fi
  1077. # Adding Vesta admin account
  1078. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  1079. check_result $? "can't create admin user"
  1080. $VESTA/bin/v-change-user-shell admin bash
  1081. $VESTA/bin/v-change-user-language admin $lang
  1082. # Configuring system IPs
  1083. $VESTA/bin/v-update-sys-ip
  1084. # Get main IP
  1085. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1086. # Configuring firewall
  1087. if [ "$iptables" = 'yes' ]; then
  1088. $VESTA/bin/v-update-firewall
  1089. fi
  1090. # Get public IP
  1091. pub_ip=$(curl -s vestacp.com/what-is-my-ip/)
  1092. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1093. echo "$VESTA/bin/v-update-sys-ip" >> /etc/rc.local
  1094. $VESTA/bin/v-change-sys-ip-nat $ip $pub_ip
  1095. ip=$pub_ip
  1096. fi
  1097. # Configuring MySQL/MariaDB host
  1098. if [ "$mysql" = 'yes' ]; then
  1099. $VESTA/bin/v-add-database-host mysql localhost root $mpass
  1100. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  1101. fi
  1102. # Configuring PostgreSQL host
  1103. if [ "$postgresql" = 'yes' ]; then
  1104. $VESTA/bin/v-add-database-host pgsql localhost postgres $ppass
  1105. $VESTA/bin/v-add-database admin db db $(gen_pass) pgsql
  1106. fi
  1107. # Adding default domain
  1108. $VESTA/bin/v-add-domain admin $servername
  1109. # Adding cron jobs
  1110. command="sudo $VESTA/bin/v-update-sys-queue disk"
  1111. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1112. command="sudo $VESTA/bin/v-update-sys-queue traffic"
  1113. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1114. command="sudo $VESTA/bin/v-update-sys-queue webstats"
  1115. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1116. command="sudo $VESTA/bin/v-update-sys-queue backup"
  1117. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1118. command="sudo $VESTA/bin/v-backup-users"
  1119. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1120. command="sudo $VESTA/bin/v-update-user-stats"
  1121. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1122. command="sudo $VESTA/bin/v-update-sys-rrd"
  1123. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1124. service cron restart
  1125. # Building initital rrd images
  1126. $VESTA/bin/v-update-sys-rrd
  1127. # Enabling file system quota
  1128. if [ "$quota" = 'yes' ]; then
  1129. $VESTA/bin/v-add-sys-quota
  1130. fi
  1131. # Enabling softaculous plugin
  1132. if [ "$softaculous" = 'yes' ]; then
  1133. $VESTA/bin/v-add-vesta-softaculous
  1134. fi
  1135. # Starting Vesta service
  1136. update-rc.d vesta defaults
  1137. service vesta start
  1138. check_result $? "vesta start failed"
  1139. chown admin:admin $VESTA/data/sessions
  1140. # Adding notifications
  1141. $VESTA/upd/add_notifications.sh
  1142. # Adding cronjob for autoupdates
  1143. $VESTA/bin/v-add-cron-vesta-autoupdate
  1144. #----------------------------------------------------------#
  1145. # Vesta Access Info #
  1146. #----------------------------------------------------------#
  1147. # Comparing hostname and IP
  1148. host_ip=$(host $servername| head -n 1 |awk '{print $NF}')
  1149. if [ "$host_ip" = "$ip" ]; then
  1150. ip="$servername"
  1151. fi
  1152. # Sending notification to admin email
  1153. echo -e "Congratulations, you have just successfully installed \
  1154. Vesta Control Panel
  1155. https://$ip:8083
  1156. username: admin
  1157. password: $vpass
  1158. We hope that you enjoy your installation of Vesta. Please \
  1159. feel free to contact us anytime if you have any questions.
  1160. Thank you.
  1161. --
  1162. Sincerely yours
  1163. vestacp.com team
  1164. " > $tmpfile
  1165. send_mail="$VESTA/web/inc/mail-wrapper.php"
  1166. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  1167. # Congrats
  1168. echo '======================================================='
  1169. echo
  1170. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  1171. echo ' _| _| _| _| _| _| _| '
  1172. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  1173. echo ' _| _| _| _| _| _| _| '
  1174. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  1175. echo
  1176. echo
  1177. cat $tmpfile
  1178. rm -f $tmpfile
  1179. # EOF