vst-install-debian.sh 48 KB

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