vst-install-ubuntu.sh 40 KB

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