vst-install-debian.sh 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404
  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="http://$CHOST/$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 "$vestacp/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. # Downloading sudo configuration
  600. mkdir -p /etc/sudoers.d
  601. wget $vestacp/sudo/admin -O /etc/sudoers.d/admin
  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. wget $vestacp/logrotate/vesta -O /etc/logrotate.d/vesta
  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. # Downloading hosting packages
  711. cd $VESTA/data
  712. wget $vestacp/packages.tar.gz -O packages.tar.gz
  713. tar -xzf packages.tar.gz
  714. rm -f packages.tar.gz
  715. # Downloading templates
  716. wget $vestacp/templates.tar.gz -O templates.tar.gz
  717. tar -xzf templates.tar.gz
  718. rm -f templates.tar.gz
  719. # Copying index.html to default documentroot
  720. cp templates/web/skel/public_html/index.html /var/www/
  721. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  722. # Downloading firewall rules
  723. wget $vestacp/firewall.tar.gz -O firewall.tar.gz
  724. tar -xzf firewall.tar.gz
  725. rm -f firewall.tar.gz
  726. # Configuring server hostname
  727. $VESTA/bin/v-change-sys-hostname $servername 2>/dev/null
  728. # Generating SSL certificate
  729. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  730. 'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  731. # Parsing certificate file
  732. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  733. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  734. key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  735. # Adding SSL certificate
  736. cd $VESTA/ssl
  737. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  738. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  739. chown root:mail $VESTA/ssl/*
  740. chmod 660 $VESTA/ssl/*
  741. rm /tmp/vst.pem
  742. #----------------------------------------------------------#
  743. # Configure Nginx #
  744. #----------------------------------------------------------#
  745. if [ "$nginx" = 'yes' ]; then
  746. rm -f /etc/nginx/conf.d/*.conf
  747. wget $vestacp/nginx/nginx.conf -O /etc/nginx/nginx.conf
  748. wget $vestacp/nginx/status.conf -O /etc/nginx/conf.d/status.conf
  749. wget $vestacp/nginx/phpmyadmin.inc -O /etc/nginx/conf.d/phpmyadmin.inc
  750. wget $vestacp/nginx/phppgadmin.inc -O /etc/nginx/conf.d/phppgadmin.inc
  751. wget $vestacp/nginx/webmail.inc -O /etc/nginx/conf.d/webmail.inc
  752. wget $vestacp/logrotate/nginx -O /etc/logrotate.d/nginx
  753. echo > /etc/nginx/conf.d/vesta.conf
  754. mkdir -p /var/log/nginx/domains
  755. update-rc.d nginx defaults
  756. service nginx start
  757. check_result $? "nginx start failed"
  758. fi
  759. #----------------------------------------------------------#
  760. # Configure Apache #
  761. #----------------------------------------------------------#
  762. if [ "$apache" = 'yes' ]; then
  763. wget $vestacp/apache2/apache2.conf -O /etc/apache2/apache2.conf
  764. wget $vestacp/apache2/status.conf -O /etc/apache2/mods-enabled/status.conf
  765. wget $vestacp/logrotate/apache2 -O /etc/logrotate.d/apache2
  766. a2enmod rewrite
  767. a2enmod suexec
  768. a2enmod ssl
  769. a2enmod actions
  770. a2enmod ruid2
  771. a2enmod headers
  772. mkdir -p /etc/apache2/conf.d
  773. echo > /etc/apache2/conf.d/vesta.conf
  774. echo "# Powered by vesta" > /etc/apache2/sites-available/default
  775. echo "# Powered by vesta" > /etc/apache2/sites-available/default-ssl
  776. echo "# Powered by vesta" > /etc/apache2/ports.conf
  777. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  778. touch /var/log/apache2/access.log /var/log/apache2/error.log
  779. mkdir -p /var/log/apache2/domains
  780. chmod a+x /var/log/apache2
  781. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  782. chmod 751 /var/log/apache2/domains
  783. update-rc.d apache2 defaults
  784. service apache2 start
  785. check_result $? "apache2 start failed"
  786. else
  787. update-rc.d apache2 disable >/dev/null 2>&1
  788. service apache2 stop >/dev/null 2>&1
  789. fi
  790. #----------------------------------------------------------#
  791. # Configure PHP-FPM #
  792. #----------------------------------------------------------#
  793. if [ "$phpfpm" = 'yes' ]; then
  794. if [ "$release" -eq 9 ]; then
  795. wget $vestacp/php-fpm/www.conf -O /etc/php/7.0/fpm/pool.d/www.conf
  796. update-rc.d php7.0-fpm defaults
  797. service php7.0-fpm start
  798. check_result $? "php-fpm start failed"
  799. else
  800. wget $vestacp/php5-fpm/www.conf -O /etc/php5/fpm/pool.d/www.conf
  801. update-rc.d php5-fpm defaults
  802. service php5-fpm start
  803. check_result $? "php-fpm start failed"
  804. fi
  805. fi
  806. #----------------------------------------------------------#
  807. # Configure PHP #
  808. #----------------------------------------------------------#
  809. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  810. if [ -z "$ZONE" ]; then
  811. ZONE='UTC'
  812. fi
  813. for pconf in $(find /etc/php* -name php.ini); do
  814. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  815. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  816. done
  817. #----------------------------------------------------------#
  818. # Configure VSFTPD #
  819. #----------------------------------------------------------#
  820. if [ "$vsftpd" = 'yes' ]; then
  821. wget $vestacp/vsftpd/vsftpd.conf -O /etc/vsftpd.conf
  822. update-rc.d vsftpd defaults
  823. service vsftpd start
  824. check_result $? "vsftpd start failed"
  825. # To be deleted after release 0.9.8-18
  826. echo "/sbin/nologin" >> /etc/shells
  827. fi
  828. #----------------------------------------------------------#
  829. # Configure ProFTPD #
  830. #----------------------------------------------------------#
  831. if [ "$proftpd" = 'yes' ]; then
  832. echo "127.0.0.1 $servername" >> /etc/hosts
  833. wget $vestacp/proftpd/proftpd.conf -O /etc/proftpd/proftpd.conf
  834. update-rc.d proftpd defaults
  835. service proftpd start
  836. check_result $? "proftpd start failed"
  837. fi
  838. #----------------------------------------------------------#
  839. # Configure MySQL/MariaDB #
  840. #----------------------------------------------------------#
  841. if [ "$mysql" = 'yes' ]; then
  842. mycnf="my-small.cnf"
  843. if [ $memory -gt 1200000 ]; then
  844. mycnf="my-medium.cnf"
  845. fi
  846. if [ $memory -gt 3900000 ]; then
  847. mycnf="my-large.cnf"
  848. fi
  849. # MySQL configuration
  850. wget $vestacp/mysql/$mycnf -O /etc/mysql/my.cnf
  851. mysql_install_db
  852. update-rc.d mysql defaults
  853. service mysql start
  854. check_result $? "mysql start failed"
  855. # Securing MySQL installation
  856. mysqladmin -u root password $vpass
  857. echo -e "[client]\npassword='$vpass'\n" > /root/.my.cnf
  858. chmod 600 /root/.my.cnf
  859. mysql -e "DELETE FROM mysql.user WHERE User=''"
  860. mysql -e "DROP DATABASE test" >/dev/null 2>&1
  861. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  862. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  863. mysql -e "FLUSH PRIVILEGES"
  864. # Configuring phpMyAdmin
  865. if [ "$apache" = 'yes' ]; then
  866. wget $vestacp/pma/apache.conf -O /etc/phpmyadmin/apache.conf
  867. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  868. fi
  869. wget $vestacp/pma/config.inc.php -O /etc/phpmyadmin/config.inc.php
  870. chmod 777 /var/lib/phpmyadmin/tmp
  871. fi
  872. #----------------------------------------------------------#
  873. # Configure PostgreSQL #
  874. #----------------------------------------------------------#
  875. if [ "$postgresql" = 'yes' ]; then
  876. wget $vestacp/postgresql/pg_hba.conf -O /etc/postgresql/*/main/pg_hba.conf
  877. service postgresql restart
  878. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$vpass'"
  879. # Configuring phpPgAdmin
  880. if [ "$apache" = 'yes' ]; then
  881. wget $vestacp/pga/phppgadmin.conf \
  882. -O /etc/apache2/conf.d/phppgadmin.conf
  883. fi
  884. wget $vestacp/pga/config.inc.php -O /etc/phppgadmin/config.inc.php
  885. fi
  886. #----------------------------------------------------------#
  887. # Configure Bind #
  888. #----------------------------------------------------------#
  889. if [ "$named" = 'yes' ]; then
  890. wget $vestacp/bind/named.conf -O /etc/bind/named.conf
  891. sed -i "s%listen-on%//listen%" /etc/bind/named.conf.options
  892. chown root:bind /etc/bind/named.conf
  893. chmod 640 /etc/bind/named.conf
  894. aa-complain /usr/sbin/named 2>/dev/null
  895. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2>/dev/null
  896. service apparmor status >/dev/null 2>&1
  897. if [ $? -ne 0 ]; then
  898. service apparmor restart
  899. fi
  900. update-rc.d bind9 defaults
  901. service bind9 start
  902. check_result $? "bind9 start failed"
  903. fi
  904. #----------------------------------------------------------#
  905. # Configure Exim #
  906. #----------------------------------------------------------#
  907. if [ "$exim" = 'yes' ]; then
  908. gpasswd -a Debian-exim mail
  909. wget $vestacp/exim/exim4.conf.template -O /etc/exim4/exim4.conf.template
  910. wget $vestacp/exim/dnsbl.conf -O /etc/exim4/dnsbl.conf
  911. wget $vestacp/exim/spam-blocks.conf -O /etc/exim4/spam-blocks.conf
  912. touch /etc/exim4/white-blocks.conf
  913. if [ "$spamd" = 'yes' ]; then
  914. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  915. fi
  916. if [ "$clamd" = 'yes' ]; then
  917. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  918. fi
  919. chmod 640 /etc/exim4/exim4.conf.template
  920. rm -rf /etc/exim4/domains
  921. mkdir -p /etc/exim4/domains
  922. rm -f /etc/alternatives/mta
  923. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  924. update-rc.d -f sendmail remove > /dev/null 2>&1
  925. service sendmail stop > /dev/null 2>&1
  926. update-rc.d -f postfix remove > /dev/null 2>&1
  927. service postfix stop > /dev/null 2>&1
  928. update-rc.d exim4 defaults
  929. service exim4 start
  930. check_result $? "exim4 start failed"
  931. fi
  932. #----------------------------------------------------------#
  933. # Configure Dovecot #
  934. #----------------------------------------------------------#
  935. if [ "$dovecot" = 'yes' ]; then
  936. gpasswd -a dovecot mail
  937. wget $vestacp/dovecot.tar.gz -O /etc/dovecot.tar.gz
  938. wget $vestacp/logrotate/dovecot -O /etc/logrotate.d/dovecot
  939. cd /etc
  940. rm -rf dovecot dovecot.conf
  941. tar -xzf dovecot.tar.gz
  942. rm -f dovecot.tar.gz
  943. chown -R root:root /etc/dovecot*
  944. update-rc.d dovecot defaults
  945. service dovecot start
  946. check_result $? "dovecot start failed"
  947. fi
  948. #----------------------------------------------------------#
  949. # Configure ClamAV #
  950. #----------------------------------------------------------#
  951. if [ "$clamd" = 'yes' ]; then
  952. gpasswd -a clamav mail
  953. gpasswd -a clamav Debian-exim
  954. wget $vestacp/clamav/clamd.conf -O /etc/clamav/clamd.conf
  955. /usr/bin/freshclam
  956. update-rc.d clamav-daemon defaults
  957. if [ ! -d "/var/run/clamav" ]; then
  958. mkdir /var/run/clamav
  959. fi
  960. chown -R clamav:clamav /var/run/clamav
  961. if [ -e "/lib/systemd/system/clamav-daemon.service" ]; then
  962. exec_pre1='ExecStartPre=/bin/mkdir -p /var/run/clamav'
  963. exec_pre2='ExecStartPre=/bin/chown -R clamav:clamav /var/run/clamav'
  964. sed -i "s|\[Service\]/|[Service]\n$exec_pre1\n$exec_pre2|g" \
  965. /lib/systemd/system/clamav-daemon.service
  966. systemctl daemon-reload
  967. fi
  968. service clamav-daemon start
  969. check_result $? "clamav-daeom start failed"
  970. fi
  971. #----------------------------------------------------------#
  972. # Configure SpamAssassin #
  973. #----------------------------------------------------------#
  974. if [ "$spamd" = 'yes' ]; then
  975. update-rc.d spamassassin defaults
  976. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  977. service spamassassin start
  978. check_result $? "spamassassin start failed"
  979. unit_files="$(systemctl list-unit-files |grep spamassassin)"
  980. if [[ "$unit_files" =~ "disabled" ]]; then
  981. systemctl enable spamassassin
  982. fi
  983. fi
  984. #----------------------------------------------------------#
  985. # Configure RoundCube #
  986. #----------------------------------------------------------#
  987. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  988. if [ "$apache" = 'yes' ]; then
  989. wget $vestacp/roundcube/apache.conf -O /etc/roundcube/apache.conf
  990. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  991. fi
  992. wget $vestacp/roundcube/main.inc.php -O /etc/roundcube/main.inc.php
  993. wget $vestacp/roundcube/db.inc.php -O /etc/roundcube/db.inc.php
  994. chmod 640 /etc/roundcube/debian-db-roundcube.php
  995. chmod 640 /etc/roundcube/config.inc.php
  996. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  997. chown root:www-data /etc/roundcube/config.inc.php
  998. wget $vestacp/roundcube/vesta.php -O \
  999. /usr/share/roundcube/plugins/password/drivers/vesta.php
  1000. wget $vestacp/roundcube/config.inc.php -O \
  1001. /etc/roundcube/plugins/password/config.inc.php
  1002. r="$(gen_pass)"
  1003. mysql -e "CREATE DATABASE roundcube"
  1004. mysql -e "GRANT ALL ON roundcube.*
  1005. TO roundcube@localhost IDENTIFIED BY '$r'"
  1006. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  1007. sed -i "s/localhost/$servername/g" \
  1008. /etc/roundcube/plugins/password/config.inc.php
  1009. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  1010. chmod a+r /etc/roundcube/main.inc.php
  1011. if [ "$release" -eq 8 ] || [ "$release" -eq 9 ]; then
  1012. mv -f /etc/roundcube/main.inc.php /etc/roundcube/config.inc.php
  1013. mv -f /etc/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  1014. chmod 640 /etc/roundcube/debian-db-roundcube.php
  1015. chmod 640 /etc/roundcube/config.inc.php
  1016. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1017. chown root:www-data /etc/roundcube/config.inc.php
  1018. fi
  1019. if [ "$release" -eq 8 ]; then
  1020. # RoundCube tinyMCE fix
  1021. tinymceFixArchiveURL=$vestacp/roundcube/roundcube-tinymce.tar.gz
  1022. tinymceParentFolder=/usr/share/roundcube/program/js
  1023. tinymceFolder=$tinymceParentFolder/tinymce
  1024. tinymceBadJS=$tinymceFolder/tiny_mce.js
  1025. tinymceFixArchive=$tinymceParentFolder/roundcube-tinymce.tar.gz
  1026. if [[ -L "$tinymceFolder" && -d "$tinymceFolder" ]]; then
  1027. if [ -f "$tinymceBadJS" ]; then
  1028. wget $tinymceFixArchiveURL -O $tinymceFixArchive
  1029. if [[ -f "$tinymceFixArchive" && -s "$tinymceFixArchive" ]]
  1030. then
  1031. rm $tinymceFolder
  1032. tar -xzf $tinymceFixArchive -C $tinymceParentFolder
  1033. rm $tinymceFixArchive
  1034. chown -R root:root $tinymceFolder
  1035. else
  1036. echo -n "File roundcube-tinymce.tar.gz is not downloaded,"
  1037. echo "RoundCube tinyMCE fix is not applied"
  1038. rm $tinymceFixArchive
  1039. fi
  1040. fi
  1041. fi
  1042. fi
  1043. fi
  1044. #----------------------------------------------------------#
  1045. # Configure Fail2Ban #
  1046. #----------------------------------------------------------#
  1047. if [ "$fail2ban" = 'yes' ]; then
  1048. cd /etc
  1049. wget $vestacp/fail2ban.tar.gz -O fail2ban.tar.gz
  1050. tar -xzf fail2ban.tar.gz
  1051. rm -f fail2ban.tar.gz
  1052. if [ "$dovecot" = 'no' ]; then
  1053. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1054. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1055. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1056. fi
  1057. if [ "$exim" = 'no' ]; then
  1058. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1059. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1060. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1061. fi
  1062. update-rc.d fail2ban defaults
  1063. service fail2ban start
  1064. check_result $? "fail2ban start failed"
  1065. fi
  1066. #----------------------------------------------------------#
  1067. # Configure Admin User #
  1068. #----------------------------------------------------------#
  1069. # Deleting old admin user
  1070. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1071. chattr -i /home/admin/conf > /dev/null 2>&1
  1072. userdel -f admin >/dev/null 2>&1
  1073. chattr -i /home/admin/conf >/dev/null 2>&1
  1074. mv -f /home/admin $vst_backups/home/ >/dev/null 2>&1
  1075. rm -f /tmp/sess_* >/dev/null 2>&1
  1076. fi
  1077. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  1078. groupdel admin > /dev/null 2>&1
  1079. fi
  1080. # Adding vesta account
  1081. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  1082. check_result $? "can't create admin user"
  1083. $VESTA/bin/v-change-user-shell admin bash
  1084. $VESTA/bin/v-change-user-language admin $lang
  1085. # RoundCube permissions fix
  1086. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1087. if [ ! -d "/var/log/roundcube" ]; then
  1088. mkdir /var/log/roundcube
  1089. fi
  1090. chown admin:admin /var/log/roundcube
  1091. fi
  1092. # Configuring system ips
  1093. $VESTA/bin/v-update-sys-ip
  1094. # Get main ip
  1095. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1096. local_ip=$ip
  1097. # Firewall configuration
  1098. if [ "$iptables" = 'yes' ]; then
  1099. $VESTA/bin/v-update-firewall
  1100. fi
  1101. # Get public ip
  1102. pub_ip=$(curl -s vestacp.com/what-is-my-ip/)
  1103. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1104. $VESTA/bin/v-change-sys-ip-nat $ip $pub_ip
  1105. ip=$pub_ip
  1106. fi
  1107. # Configuring libapache2-mod-remoteip
  1108. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  1109. cd /etc/apache2/mods-available
  1110. echo "<IfModule mod_remoteip.c>" > remoteip.conf
  1111. echo " RemoteIPHeader X-Real-IP" >> remoteip.conf
  1112. if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ip" != "127.0.0.1" ]; then
  1113. echo " RemoteIPInternalProxy 127.0.0.1" >> remoteip.conf
  1114. fi
  1115. if [ ! -z "$local_ip" ] && [ "$local_ip" != "$pub_ip" ]; then
  1116. echo " RemoteIPInternalProxy $local_ip" >> remoteip.conf
  1117. fi
  1118. if [ ! -z "$pub_ip" ]; then
  1119. echo " RemoteIPInternalProxy $pub_ip" >> remoteip.conf
  1120. fi
  1121. echo "</IfModule>" >> remoteip.conf
  1122. sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  1123. a2enmod remoteip
  1124. service apache2 restart
  1125. fi
  1126. # Configuring mysql host
  1127. if [ "$mysql" = 'yes' ]; then
  1128. $VESTA/bin/v-add-database-host mysql localhost root $vpass
  1129. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  1130. fi
  1131. # Configuring pgsql host
  1132. if [ "$postgresql" = 'yes' ]; then
  1133. $VESTA/bin/v-add-database-host pgsql localhost postgres $vpass
  1134. $VESTA/bin/v-add-database admin db db $(gen_pass) pgsql
  1135. fi
  1136. # Adding default domain
  1137. $VESTA/bin/v-add-domain admin $servername
  1138. check_result $? "can't create $servername domain"
  1139. # Adding cron jobs
  1140. command="sudo $VESTA/bin/v-update-sys-queue disk"
  1141. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1142. command="sudo $VESTA/bin/v-update-sys-queue traffic"
  1143. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1144. command="sudo $VESTA/bin/v-update-sys-queue webstats"
  1145. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1146. command="sudo $VESTA/bin/v-update-sys-queue backup"
  1147. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1148. command="sudo $VESTA/bin/v-backup-users"
  1149. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1150. command="sudo $VESTA/bin/v-update-user-stats"
  1151. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1152. command="sudo $VESTA/bin/v-update-sys-rrd"
  1153. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1154. service cron restart
  1155. # Building inititall rrd images
  1156. $VESTA/bin/v-update-sys-rrd
  1157. # Enabling file system quota
  1158. if [ "$quota" = 'yes' ]; then
  1159. $VESTA/bin/v-add-sys-quota
  1160. fi
  1161. # Enabling softaculous plugin
  1162. if [ "$softaculous" = 'yes' ]; then
  1163. $VESTA/bin/v-add-vesta-softaculous
  1164. fi
  1165. # Starting vesta service
  1166. update-rc.d vesta defaults
  1167. service vesta start
  1168. check_result $? "vesta start failed"
  1169. chown admin:admin $VESTA/data/sessions
  1170. # Adding notifications
  1171. $VESTA/upd/add_notifications.sh
  1172. # Adding cronjob for autoupdates
  1173. $VESTA/bin/v-add-cron-vesta-autoupdate
  1174. #----------------------------------------------------------#
  1175. # Vesta Access Info #
  1176. #----------------------------------------------------------#
  1177. # Sending install notification to vestacp.com
  1178. wget vestacp.com/notify/?$codename -O /dev/null -q
  1179. # Comparing hostname and ip
  1180. host_ip=$(host $servername| head -n 1 | awk '{print $NF}')
  1181. if [ "$host_ip" = "$ip" ]; then
  1182. ip="$servername"
  1183. fi
  1184. # Sending notification to admin email
  1185. echo -e "Congratulations, you have just successfully installed \
  1186. Vesta Control Panel
  1187. https://$ip:8083
  1188. username: admin
  1189. password: $vpass
  1190. We hope that you enjoy your installation of Vesta. Please \
  1191. feel free to contact us anytime if you have any questions.
  1192. Thank you.
  1193. --
  1194. Sincerely yours
  1195. vestacp.com team
  1196. " > $tmpfile
  1197. send_mail="$VESTA/web/inc/mail-wrapper.php"
  1198. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  1199. # Congrats
  1200. echo '======================================================='
  1201. echo
  1202. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  1203. echo ' _| _| _| _| _| _| _| '
  1204. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  1205. echo ' _| _| _| _| _| _| _| '
  1206. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  1207. echo
  1208. echo
  1209. cat $tmpfile
  1210. rm -f $tmpfile
  1211. # EOF