vst-install-ubuntu.sh 41 KB

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