vst-install-ubuntu.sh 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241
  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/mainline/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. else
  725. update-rc.d apache2 disable >/dev/null 2>&1
  726. service apache2 stop >/dev/null 2>&1
  727. fi
  728. #----------------------------------------------------------#
  729. # Configure PHP-FPM #
  730. #----------------------------------------------------------#
  731. if [ "$phpfpm" = 'yes' ]; then
  732. wget $vestacp/php5-fpm/www.conf -O /etc/php5/fpm/pool.d/www.conf
  733. update-rc.d php5-fpm defaults
  734. service php5-fpm start
  735. check_result $? "php-fpm start failed"
  736. fi
  737. #----------------------------------------------------------#
  738. # Configure PHP #
  739. #----------------------------------------------------------#
  740. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  741. if [ -z "$ZONE" ]; then
  742. ZONE='UTC'
  743. fi
  744. for pconf in $(find /etc/php* -name php.ini); do
  745. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  746. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  747. done
  748. #----------------------------------------------------------#
  749. # Configure VSFTPD #
  750. #----------------------------------------------------------#
  751. if [ "$vsftpd" = 'yes' ]; then
  752. wget $vestacp/vsftpd/vsftpd.conf -O /etc/vsftpd.conf
  753. update-rc.d vsftpd defaults
  754. service vsftpd start
  755. check_result $? "vsftpd start failed"
  756. fi
  757. #----------------------------------------------------------#
  758. # Configure ProFTPD #
  759. #----------------------------------------------------------#
  760. if [ "$proftpd" = 'yes' ]; then
  761. echo "127.0.0.1 $servername" >> /etc/hosts
  762. wget $vestacp/proftpd/proftpd.conf -O /etc/proftpd/proftpd.conf
  763. update-rc.d proftpd defaults
  764. service proftpd start
  765. check_result $? "proftpd start failed"
  766. fi
  767. #----------------------------------------------------------#
  768. # Configure MySQL/MariaDB #
  769. #----------------------------------------------------------#
  770. if [ "$mysql" = 'yes' ]; then
  771. mycnf="my-small.cnf"
  772. if [ $memory -gt 1200000 ]; then
  773. mycnf="my-medium.cnf"
  774. fi
  775. if [ $memory -gt 3900000 ]; then
  776. mycnf="my-large.cnf"
  777. fi
  778. # MySQL configuration
  779. wget $vestacp/mysql/$mycnf -O /etc/mysql/my.cnf
  780. mysql_install_db
  781. update-rc.d mysql defaults
  782. service mysql start
  783. check_result $? "mysql start failed"
  784. # Securing MySQL installation
  785. mysqladmin -u root password $vpass
  786. echo -e "[client]\npassword='$vpass'\n" > /root/.my.cnf
  787. chmod 600 /root/.my.cnf
  788. mysql -e "DELETE FROM mysql.user WHERE User=''"
  789. mysql -e "DROP DATABASE test" >/dev/null 2>&1
  790. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  791. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  792. mysql -e "FLUSH PRIVILEGES"
  793. # Configuring phpMyAdmin
  794. if [ "$apache" = 'yes' ]; then
  795. wget $vestacp/pma/apache.conf -O /etc/phpmyadmin/apache.conf
  796. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  797. fi
  798. wget $vestacp/pma/config.inc.php -O /etc/phpmyadmin/config.inc.php
  799. chmod 777 /var/lib/phpmyadmin/tmp
  800. fi
  801. #----------------------------------------------------------#
  802. # Configure PostgreSQL #
  803. #----------------------------------------------------------#
  804. if [ "$postgresql" = 'yes' ]; then
  805. wget $vestacp/postgresql/pg_hba.conf -O /etc/postgresql/*/main/pg_hba.conf
  806. service postgresql restart
  807. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$vpass'" 2>/dev/null
  808. # Configuring phpPgAdmin
  809. if [ "$apache" = 'yes' ]; then
  810. wget $vestacp/pga/phppgadmin.conf -O /etc/apache2/conf.d/phppgadmin.conf
  811. fi
  812. wget $vestacp/pga/config.inc.php -O /etc/phppgadmin/config.inc.php
  813. fi
  814. #----------------------------------------------------------#
  815. # Configure Bind #
  816. #----------------------------------------------------------#
  817. if [ "$named" = 'yes' ]; then
  818. wget $vestacp/bind/named.conf -O /etc/bind/named.conf
  819. sed -i "s%listen-on%//listen%" /etc/bind/named.conf.options
  820. chown root:bind /etc/bind/named.conf
  821. chmod 640 /etc/bind/named.conf
  822. aa-complain /usr/sbin/named 2>/dev/null
  823. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2>/dev/null
  824. service apparmor status >/dev/null 2>&1
  825. if [ $? -ne 0 ]; then
  826. service apparmor restart
  827. fi
  828. update-rc.d bind9 defaults
  829. service bind9 start
  830. check_result $? "bind9 start failed"
  831. fi
  832. #----------------------------------------------------------#
  833. # Configure Exim #
  834. #----------------------------------------------------------#
  835. if [ "$exim" = 'yes' ]; then
  836. gpasswd -a Debian-exim mail
  837. wget $vestacp/exim/exim4.conf.template -O /etc/exim4/exim4.conf.template
  838. wget $vestacp/exim/dnsbl.conf -O /etc/exim4/dnsbl.conf
  839. wget $vestacp/exim/spam-blocks.conf -O /etc/exim4/spam-blocks.conf
  840. touch /etc/exim4/white-blocks.conf
  841. if [ "$spamd" = 'yes' ]; then
  842. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  843. fi
  844. if [ "$clamd" = 'yes' ]; then
  845. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  846. fi
  847. chmod 640 /etc/exim4/exim4.conf.template
  848. rm -rf /etc/exim4/domains
  849. mkdir -p /etc/exim4/domains
  850. rm -f /etc/alternatives/mta
  851. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  852. update-rc.d -f sendmail remove > /dev/null 2>&1
  853. service sendmail stop > /dev/null 2>&1
  854. update-rc.d -f postfix remove > /dev/null 2>&1
  855. service postfix stop > /dev/null 2>&1
  856. update-rc.d exim4 defaults
  857. service exim4 start
  858. check_result $? "exim4 start failed"
  859. fi
  860. #----------------------------------------------------------#
  861. # Configure Dovecot #
  862. #----------------------------------------------------------#
  863. if [ "$dovecot" = 'yes' ]; then
  864. gpasswd -a dovecot mail
  865. wget $vestacp/dovecot.tar.gz -O /etc/dovecot.tar.gz
  866. wget $vestacp/logrotate/dovecot -O /etc/logrotate.d/dovecot
  867. cd /etc
  868. rm -rf dovecot dovecot.conf
  869. tar -xzf dovecot.tar.gz
  870. rm -f dovecot.tar.gz
  871. chown -R root:root /etc/dovecot*
  872. update-rc.d dovecot defaults
  873. service dovecot start
  874. check_result $? "dovecot start failed"
  875. fi
  876. #----------------------------------------------------------#
  877. # Configure ClamAV #
  878. #----------------------------------------------------------#
  879. if [ "$clamd" = 'yes' ]; then
  880. gpasswd -a clamav mail
  881. gpasswd -a clamav Debian-exim
  882. wget $vestacp/clamav/clamd.conf -O /etc/clamav/clamd.conf
  883. /usr/bin/freshclam
  884. update-rc.d clamav-daemon defaults
  885. service clamav-daemon start
  886. check_result $? "clamav-daeom start failed"
  887. fi
  888. #----------------------------------------------------------#
  889. # Configure SpamAssassin #
  890. #----------------------------------------------------------#
  891. if [ "$spamd" = 'yes' ]; then
  892. update-rc.d spamassassin defaults
  893. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  894. service spamassassin start
  895. check_result $? "spamassassin start failed"
  896. fi
  897. #----------------------------------------------------------#
  898. # Configure RoundCube #
  899. #----------------------------------------------------------#
  900. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  901. if [ "$apache" = 'yes' ]; then
  902. wget $vestacp/roundcube/apache.conf -O /etc/roundcube/apache.conf
  903. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  904. fi
  905. wget $vestacp/roundcube/main.inc.php -O /etc/roundcube/main.inc.php
  906. wget $vestacp/roundcube/db.inc.php -O /etc/roundcube/db.inc.php
  907. wget $vestacp/roundcube/vesta.php -O \
  908. /usr/share/roundcube/plugins/password/drivers/vesta.php
  909. wget $vestacp/roundcube/config.inc.php -O \
  910. /etc/roundcube/plugins/password/config.inc.php
  911. r="$(gen_pass)"
  912. mysql -e "CREATE DATABASE roundcube"
  913. mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
  914. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  915. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  916. php5enmod mcrypt 2>/dev/null
  917. service apache2 restart
  918. fi
  919. #----------------------------------------------------------#
  920. # Configure Fail2Ban #
  921. #----------------------------------------------------------#
  922. if [ "$fail2ban" = 'yes' ]; then
  923. cd /etc
  924. wget $vestacp/fail2ban.tar.gz -O fail2ban.tar.gz
  925. tar -xzf fail2ban.tar.gz
  926. rm -f fail2ban.tar.gz
  927. if [ "$dovecot" = 'no' ]; then
  928. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  929. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  930. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  931. fi
  932. if [ "$exim" = 'no' ]; then
  933. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  934. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  935. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  936. fi
  937. update-rc.d fail2ban defaults
  938. service fail2ban start
  939. check_result $? "fail2ban start failed"
  940. fi
  941. #----------------------------------------------------------#
  942. # Configure Admin User #
  943. #----------------------------------------------------------#
  944. # Deleting old admin user
  945. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  946. chattr -i /home/admin/conf > /dev/null 2>&1
  947. userdel -f admin >/dev/null 2>&1
  948. chattr -i /home/admin/conf >/dev/null 2>&1
  949. mv -f /home/admin $vst_backups/home/ >/dev/null 2>&1
  950. rm -f /tmp/sess_* >/dev/null 2>&1
  951. fi
  952. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  953. groupdel admin > /dev/null 2>&1
  954. fi
  955. # Adding vesta account
  956. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  957. check_result $? "can't create admin user"
  958. $VESTA/bin/v-change-user-shell admin bash
  959. $VESTA/bin/v-change-user-language admin $lang
  960. # Configuring system ips
  961. $VESTA/bin/v-update-sys-ip
  962. # Get main ip
  963. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  964. # Firewall configuration
  965. if [ "$iptables" = 'yes' ]; then
  966. $VESTA/bin/v-update-firewall
  967. fi
  968. # Get public ip
  969. pub_ip=$(curl -s vestacp.com/what-is-my-ip/)
  970. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  971. $VESTA/bin/v-change-sys-ip-nat $ip $pub_ip
  972. ip=$pub_ip
  973. fi
  974. # Configuring mysql host
  975. if [ "$mysql" = 'yes' ]; then
  976. $VESTA/bin/v-add-database-host mysql localhost root $vpass
  977. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  978. fi
  979. # Configuring pgsql host
  980. if [ "$postgresql" = 'yes' ]; then
  981. $VESTA/bin/v-add-database-host pgsql localhost postgres $vpass
  982. $VESTA/bin/v-add-database admin db db $(gen_pass) pgsql
  983. fi
  984. # Adding default domain
  985. $VESTA/bin/v-add-domain admin $servername
  986. check_result $? "can't create $servername domain"
  987. # Adding cron jobs
  988. command="sudo $VESTA/bin/v-update-sys-queue disk"
  989. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  990. command="sudo $VESTA/bin/v-update-sys-queue traffic"
  991. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  992. command="sudo $VESTA/bin/v-update-sys-queue webstats"
  993. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  994. command="sudo $VESTA/bin/v-update-sys-queue backup"
  995. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  996. command="sudo $VESTA/bin/v-backup-users"
  997. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  998. command="sudo $VESTA/bin/v-update-user-stats"
  999. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1000. command="sudo $VESTA/bin/v-update-sys-rrd"
  1001. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1002. service cron restart
  1003. # Building inititall rrd images
  1004. $VESTA/bin/v-update-sys-rrd
  1005. # Enabling file system quota
  1006. if [ "$quota" = 'yes' ]; then
  1007. $VESTA/bin/v-add-sys-quota
  1008. fi
  1009. # Starting vesta service
  1010. update-rc.d vesta defaults
  1011. service vesta start
  1012. check_result $? "vesta start failed"
  1013. chown admin:admin $VESTA/data/sessions
  1014. # Adding notifications
  1015. $VESTA/upd/add_notifications.sh
  1016. # Adding cronjob for autoupdates
  1017. $VESTA/bin/v-add-cron-vesta-autoupdate
  1018. #----------------------------------------------------------#
  1019. # Vesta Access Info #
  1020. #----------------------------------------------------------#
  1021. # Sending install notification to vestacp.com
  1022. wget vestacp.com/notify/?$codename -O /dev/null -q
  1023. # Comparing hostname and ip
  1024. host_ip=$(host $servername| head -n 1 | awk '{print $NF}')
  1025. if [ "$host_ip" = "$ip" ]; then
  1026. ip="$servername"
  1027. fi
  1028. # Sending notification to admin email
  1029. echo -e "Congratulations, you have just successfully installed \
  1030. Vesta Control Panel
  1031. https://$ip:8083
  1032. username: admin
  1033. password: $vpass
  1034. We hope that you enjoy your installation of Vesta. Please \
  1035. feel free to contact us anytime if you have any questions.
  1036. Thank you.
  1037. --
  1038. Sincerely yours
  1039. vestacp.com team
  1040. " > $tmpfile
  1041. send_mail="$VESTA/web/inc/mail-wrapper.php"
  1042. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  1043. # Congrats
  1044. echo '======================================================='
  1045. echo
  1046. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  1047. echo ' _| _| _| _| _| _| _| '
  1048. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  1049. echo ' _| _| _| _| _| _| _| '
  1050. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  1051. echo
  1052. echo
  1053. cat $tmpfile
  1054. rm -f $tmpfile
  1055. # EOF