vst-install-debian.sh 48 KB

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