vst-install-debian.sh 42 KB

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