vst-install-debian.sh 41 KB

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