vst-install-debian.sh 51 KB

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