vst-install-debian.sh 49 KB

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