vst-install-debian.sh 41 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232
  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/debian_version|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 cron 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 cron 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 Excludes #
  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. # Downloading 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. # Building 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. $VESTA/data/sessions
  562. touch $VESTA/data/queue/backup.pipe $VESTA/data/queue/disk.pipe \
  563. $VESTA/data/queue/webstats.pipe $VESTA/data/queue/restart.pipe \
  564. $VESTA/data/queue/traffic.pipe $VESTA/log/system.log \
  565. $VESTA/log/nginx-error.log $VESTA/log/auth.log
  566. chmod 750 $VESTA/conf $VESTA/data/users $VESTA/data/ips $VESTA/log
  567. chmod -R 750 $VESTA/data/queue
  568. chmod 660 $VESTA/log/*
  569. rm -f /var/log/vesta
  570. ln -s /usr/local/vesta/log /var/log/vesta
  571. chown admin:admin $VESTA/data/sessions
  572. chmod 770 $VESTA/data/sessions
  573. # Generating vesta configuration
  574. rm -f $VESTA/conf/vesta.conf 2>/dev/null
  575. touch $VESTA/conf/vesta.conf
  576. chmod 660 $VESTA/conf/vesta.conf
  577. # WEB stack
  578. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  579. echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  580. echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  581. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  582. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  583. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  584. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  585. fi
  586. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  587. echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  588. echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  589. echo "WEB_PORT='8080'" >> $VESTA/conf/vesta.conf
  590. echo "WEB_SSL_PORT='8443'" >> $VESTA/conf/vesta.conf
  591. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  592. echo "PROXY_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  593. echo "PROXY_PORT='80'" >> $VESTA/conf/vesta.conf
  594. echo "PROXY_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  595. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  596. fi
  597. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  598. echo "WEB_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  599. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  600. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  601. echo "WEB_SSL='openssl'" >> $VESTA/conf/vesta.conf
  602. if [ "$phpfpm" = 'yes' ]; then
  603. echo "WEB_BACKEND='php5-fpm'" >> $VESTA/conf/vesta.conf
  604. fi
  605. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  606. fi
  607. # FTP stack
  608. if [ "$vsftpd" = 'yes' ]; then
  609. echo "FTP_SYSTEM='vsftpd'" >> $VESTA/conf/vesta.conf
  610. fi
  611. if [ "$proftpd" = 'yes' ]; then
  612. echo "FTP_SYSTEM='proftpd'" >> $VESTA/conf/vesta.conf
  613. fi
  614. # DNS stack
  615. if [ "$named" = 'yes' ]; then
  616. echo "DNS_SYSTEM='bind9'" >> $VESTA/conf/vesta.conf
  617. fi
  618. # Mail stack
  619. if [ "$exim" = 'yes' ]; then
  620. echo "MAIL_SYSTEM='exim4'" >> $VESTA/conf/vesta.conf
  621. if [ "$clamd" = 'yes' ]; then
  622. echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $VESTA/conf/vesta.conf
  623. fi
  624. if [ "$spamd" = 'yes' ]; then
  625. echo "ANTISPAM_SYSTEM='spamassassin'" >> $VESTA/conf/vesta.conf
  626. fi
  627. if [ "$dovecot" = 'yes' ]; then
  628. echo "IMAP_SYSTEM='dovecot'" >> $VESTA/conf/vesta.conf
  629. fi
  630. fi
  631. # CRON daemon
  632. echo "CRON_SYSTEM='cron'" >> $VESTA/conf/vesta.conf
  633. # Firewall stack
  634. if [ "$iptables" = 'yes' ]; then
  635. echo "FIREWALL_SYSTEM='iptables'" >> $VESTA/conf/vesta.conf
  636. fi
  637. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  638. echo "FIREWALL_EXTENSION='fail2ban'" >> $VESTA/conf/vesta.conf
  639. fi
  640. # Disk quota
  641. if [ "$quota" = 'yes' ]; then
  642. echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
  643. fi
  644. # Backups
  645. echo "BACKUP_SYSTEM='local'" >> $VESTA/conf/vesta.conf
  646. # Language
  647. echo "LANGUAGE='$lang'" >> $VESTA/conf/vesta.conf
  648. # Version
  649. echo "VERSION='0.9.8'" >> $VESTA/conf/vesta.conf
  650. # Downloading hosting packages
  651. cd $VESTA/data
  652. wget $vestacp/packages.tar.gz -O packages.tar.gz
  653. tar -xzf packages.tar.gz
  654. rm -f packages.tar.gz
  655. # Downloading templates
  656. wget $vestacp/templates.tar.gz -O templates.tar.gz
  657. tar -xzf templates.tar.gz
  658. rm -f templates.tar.gz
  659. # Copying index.html to default documentroot
  660. cp templates/web/skel/public_html/index.html /var/www/
  661. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  662. # Downloading firewall rules
  663. wget $vestacp/firewall.tar.gz -O firewall.tar.gz
  664. tar -xzf firewall.tar.gz
  665. rm -f firewall.tar.gz
  666. # Configuring server hostname
  667. $VESTA/bin/v-change-sys-hostname $servername 2>/dev/null
  668. # Generating SSL certificate
  669. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  670. 'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  671. # Parsing certificate file
  672. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  673. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  674. key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  675. # Adding SSL certificate
  676. cd $VESTA/ssl
  677. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  678. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  679. chown root:mail $VESTA/ssl/*
  680. chmod 660 $VESTA/ssl/*
  681. rm /tmp/vst.pem
  682. #----------------------------------------------------------#
  683. # Configure Nginx #
  684. #----------------------------------------------------------#
  685. if [ "$nginx" = 'yes' ]; then
  686. rm -f /etc/nginx/conf.d/*.conf
  687. wget $vestacp/nginx/nginx.conf -O /etc/nginx/nginx.conf
  688. wget $vestacp/nginx/status.conf -O /etc/nginx/conf.d/status.conf
  689. wget $vestacp/nginx/phpmyadmin.inc -O /etc/nginx/conf.d/phpmyadmin.inc
  690. wget $vestacp/nginx/phppgadmin.inc -O /etc/nginx/conf.d/phppgadmin.inc
  691. wget $vestacp/nginx/webmail.inc -O /etc/nginx/conf.d/webmail.inc
  692. wget $vestacp/logrotate/nginx -O /etc/logrotate.d/nginx
  693. echo > /etc/nginx/conf.d/vesta.conf
  694. mkdir -p /var/log/nginx/domains
  695. update-rc.d nginx defaults
  696. service nginx start
  697. check_result $? "nginx start failed"
  698. fi
  699. #----------------------------------------------------------#
  700. # Configure Apache #
  701. #----------------------------------------------------------#
  702. if [ "$apache" = 'yes' ]; then
  703. wget $vestacp/apache2/apache2.conf -O /etc/apache2/apache2.conf
  704. wget $vestacp/apache2/status.conf -O /etc/apache2/mods-enabled/status.conf
  705. wget $vestacp/logrotate/apache2 -O /etc/logrotate.d/apache2
  706. a2enmod rewrite
  707. a2enmod suexec
  708. a2enmod ssl
  709. a2enmod actions
  710. a2enmod ruid2
  711. mkdir -p /etc/apache2/conf.d
  712. echo > /etc/apache2/conf.d/vesta.conf
  713. echo "# Powered by vesta" > /etc/apache2/sites-available/default
  714. echo "# Powered by vesta" > /etc/apache2/sites-available/default-ssl
  715. echo "# Powered by vesta" > /etc/apache2/ports.conf
  716. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  717. touch /var/log/apache2/access.log /var/log/apache2/error.log
  718. mkdir -p /var/log/apache2/domains
  719. chmod a+x /var/log/apache2
  720. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  721. chmod 751 /var/log/apache2/domains
  722. update-rc.d apache2 defaults
  723. service apache2 start
  724. check_result $? "apache2 start failed"
  725. fi
  726. #----------------------------------------------------------#
  727. # Configure PHP-FPM #
  728. #----------------------------------------------------------#
  729. if [ "$phpfpm" = 'yes' ]; then
  730. wget $vestacp/php5-fpm/www.conf -O /etc/php5/fpm/pool.d/www.conf
  731. update-rc.d php5-fpm defaults
  732. service php5-fpm start
  733. check_result $? "php-fpm start failed"
  734. fi
  735. #----------------------------------------------------------#
  736. # Configure PHP #
  737. #----------------------------------------------------------#
  738. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  739. if [ -z "$ZONE" ]; then
  740. ZONE='UTC'
  741. fi
  742. for pconf in $(find /etc/php* -name php.ini); do
  743. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  744. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  745. done
  746. #----------------------------------------------------------#
  747. # Configure VSFTPD #
  748. #----------------------------------------------------------#
  749. if [ "$vsftpd" = 'yes' ]; then
  750. wget $vestacp/vsftpd/vsftpd.conf -O /etc/vsftpd.conf
  751. update-rc.d vsftpd defaults
  752. service vsftpd start
  753. check_result $? "vsftpd start failed"
  754. fi
  755. #----------------------------------------------------------#
  756. # Configure ProFTPD #
  757. #----------------------------------------------------------#
  758. if [ "$proftpd" = 'yes' ]; then
  759. echo "127.0.0.1 $servername" >> /etc/hosts
  760. wget $vestacp/proftpd/proftpd.conf -O /etc/proftpd/proftpd.conf
  761. update-rc.d proftpd defaults
  762. service proftpd start
  763. check_result $? "proftpd start failed"
  764. fi
  765. #----------------------------------------------------------#
  766. # Configure MySQL/MariaDB #
  767. #----------------------------------------------------------#
  768. if [ "$mysql" = 'yes' ]; then
  769. mycnf="my-small.cnf"
  770. if [ $memory -gt 1200000 ]; then
  771. mycnf="my-medium.cnf"
  772. fi
  773. if [ $memory -gt 3900000 ]; then
  774. mycnf="my-large.cnf"
  775. fi
  776. # MySQL configuration
  777. wget $vestacp/mysql/$mycnf -O /etc/mysql/my.cnf
  778. mysql_install_db
  779. update-rc.d mysql defaults
  780. service mysql start
  781. check_result $? "mysql start failed"
  782. # Securing MySQL installation
  783. mysqladmin -u root password $vpass
  784. echo -e "[client]\npassword='$vpass'\n" > /root/.my.cnf
  785. chmod 600 /root/.my.cnf
  786. mysql -e "DELETE FROM mysql.user WHERE User=''"
  787. mysql -e "DROP DATABASE test" >/dev/null 2>&1
  788. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  789. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  790. mysql -e "FLUSH PRIVILEGES"
  791. # Configuring phpMyAdmin
  792. if [ "$apache" = 'yes' ]; then
  793. wget $vestacp/pma/apache.conf -O /etc/phpmyadmin/apache.conf
  794. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  795. fi
  796. wget $vestacp/pma/config.inc.php -O /etc/phpmyadmin/config.inc.php
  797. chmod 777 /var/lib/phpmyadmin/tmp
  798. fi
  799. #----------------------------------------------------------#
  800. # Configure PostgreSQL #
  801. #----------------------------------------------------------#
  802. if [ "$postgresql" = 'yes' ]; then
  803. wget $vestacp/postgresql/pg_hba.conf -O /etc/postgresql/*/main/pg_hba.conf
  804. service postgresql restart
  805. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$vpass'" 2>/dev/null
  806. # Configuring phpPgAdmin
  807. if [ "$apache" = 'yes' ]; then
  808. wget $vestacp/pga/phppgadmin.conf -O /etc/apache2/conf.d/phppgadmin.conf
  809. fi
  810. wget $vestacp/pga/config.inc.php -O /etc/phppgadmin/config.inc.php
  811. fi
  812. #----------------------------------------------------------#
  813. # Configure Bind #
  814. #----------------------------------------------------------#
  815. if [ "$named" = 'yes' ]; then
  816. wget $vestacp/bind/named.conf -O /etc/bind/named.conf
  817. sed -i "s%listen-on%//listen%" /etc/bind/named.conf.options
  818. chown root:bind /etc/bind/named.conf
  819. chmod 640 /etc/bind/named.conf
  820. update-rc.d bind9 defaults
  821. service bind9 start
  822. check_result $? "bind9 start failed"
  823. fi
  824. #----------------------------------------------------------#
  825. # Configure Exim #
  826. #----------------------------------------------------------#
  827. if [ "$exim" = 'yes' ]; then
  828. gpasswd -a Debian-exim mail
  829. wget $vestacp/exim/exim4.conf.template -O /etc/exim4/exim4.conf.template
  830. wget $vestacp/exim/dnsbl.conf -O /etc/exim4/dnsbl.conf
  831. wget $vestacp/exim/spam-blocks.conf -O /etc/exim4/spam-blocks.conf
  832. touch /etc/exim4/white-blocks.conf
  833. if [ "$spamd" = 'yes' ]; then
  834. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  835. fi
  836. if [ "$clamd" = 'yes' ]; then
  837. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  838. fi
  839. chmod 640 /etc/exim4/exim4.conf.template
  840. rm -rf /etc/exim4/domains
  841. mkdir -p /etc/exim4/domains
  842. rm -f /etc/alternatives/mta
  843. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  844. update-rc.d -f sendmail remove > /dev/null 2>&1
  845. service sendmail stop > /dev/null 2>&1
  846. update-rc.d -f postfix remove > /dev/null 2>&1
  847. service postfix stop > /dev/null 2>&1
  848. update-rc.d exim4 defaults
  849. service exim4 start
  850. check_result $? "exim4 start failed"
  851. fi
  852. #----------------------------------------------------------#
  853. # Configure Dovecot #
  854. #----------------------------------------------------------#
  855. if [ "$dovecot" = 'yes' ]; then
  856. gpasswd -a dovecot mail
  857. wget $vestacp/dovecot.tar.gz -O /etc/dovecot.tar.gz
  858. cd /etc
  859. rm -rf dovecot dovecot.conf
  860. tar -xzf dovecot.tar.gz
  861. rm -f dovecot.tar.gz
  862. chown -R root:root /etc/dovecot*
  863. update-rc.d dovecot defaults
  864. service dovecot start
  865. check_result $? "dovecot start failed"
  866. fi
  867. #----------------------------------------------------------#
  868. # Configure ClamAV #
  869. #----------------------------------------------------------#
  870. if [ "$clamd" = 'yes' ]; then
  871. gpasswd -a clamav mail
  872. gpasswd -a clamav Debian-exim
  873. wget $vestacp/clamav/clamd.conf -O /etc/clamav/clamd.conf
  874. /usr/bin/freshclam
  875. update-rc.d clamav-daemon defaults
  876. service clamav-daemon start
  877. check_result $? "clamav-daeom start failed"
  878. fi
  879. #----------------------------------------------------------#
  880. # Configure SpamAssassin #
  881. #----------------------------------------------------------#
  882. if [ "$spamd" = 'yes' ]; then
  883. update-rc.d spamassassin defaults
  884. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  885. service spamassassin start
  886. check_result $? "spamassassin start failed"
  887. fi
  888. #----------------------------------------------------------#
  889. # Configure RoundCube #
  890. #----------------------------------------------------------#
  891. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  892. if [ "$apache" = 'yes' ]; then
  893. wget $vestacp/roundcube/apache.conf -O /etc/roundcube/apache.conf
  894. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  895. fi
  896. wget $vestacp/roundcube/main.inc.php -O /etc/roundcube/main.inc.php
  897. wget $vestacp/roundcube/db.inc.php -O /etc/roundcube/db.inc.php
  898. wget $vestacp/roundcube/vesta.php -O \
  899. /usr/share/roundcube/plugins/password/drivers/vesta.php
  900. wget $vestacp/roundcube/config.inc.php -O \
  901. /etc/roundcube/plugins/password/config.inc.php
  902. r="$(gen_pass)"
  903. mysql -e "CREATE DATABASE roundcube"
  904. mysql -e "GRANT ALL ON roundcube.* TO roundcube@localhost IDENTIFIED BY '$r'"
  905. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  906. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  907. chmod a+r /etc/roundcube/main.inc.php
  908. if [ "$release" -eq 8 ]; then
  909. mv -f /etc/roundcube/main.inc.php /etc/roundcube/config.inc.php
  910. mv -f /etc/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  911. fi
  912. fi
  913. #----------------------------------------------------------#
  914. # Configure Fail2Ban #
  915. #----------------------------------------------------------#
  916. if [ "$fail2ban" = 'yes' ]; then
  917. cd /etc
  918. wget $vestacp/fail2ban.tar.gz -O fail2ban.tar.gz
  919. tar -xzf fail2ban.tar.gz
  920. rm -f fail2ban.tar.gz
  921. if [ "$dovecot" = 'no' ]; then
  922. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  923. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  924. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  925. fi
  926. if [ "$exim" = 'no' ]; then
  927. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  928. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  929. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  930. fi
  931. update-rc.d fail2ban defaults
  932. service fail2ban start
  933. check_result $? "fail2ban start failed"
  934. fi
  935. #----------------------------------------------------------#
  936. # Configure Admin User #
  937. #----------------------------------------------------------#
  938. # Deleting old admin user
  939. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  940. chattr -i /home/admin/conf > /dev/null 2>&1
  941. userdel -f admin >/dev/null 2>&1
  942. chattr -i /home/admin/conf >/dev/null 2>&1
  943. mv -f /home/admin $vst_backups/home/ >/dev/null 2>&1
  944. rm -f /tmp/sess_* >/dev/null 2>&1
  945. fi
  946. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  947. groupdel admin > /dev/null 2>&1
  948. fi
  949. # Adding vesta account
  950. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  951. check_result $? "can't create admin user"
  952. $VESTA/bin/v-change-user-shell admin bash
  953. $VESTA/bin/v-change-user-language admin $lang
  954. # Configuring system ips
  955. $VESTA/bin/v-update-sys-ip
  956. # Get main ip
  957. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  958. # Get public ip
  959. pub_ip=$(wget vestacp.com/what-is-my-ip/ -O - 2>/dev/null)
  960. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  961. $VESTA/bin/v-change-sys-ip-nat $ip $pub_ip
  962. fi
  963. if [ -z "$pub_ip" ]; then
  964. ip=$main_ip
  965. fi
  966. # Firewall configuration
  967. if [ "$iptables" = 'yes' ]; then
  968. $VESTA/bin/v-update-firewall
  969. fi
  970. # Configuring mysql host
  971. if [ "$mysql" = 'yes' ]; then
  972. $VESTA/bin/v-add-database-host mysql localhost root $vpass
  973. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  974. fi
  975. # Configuring pgsql host
  976. if [ "$postgresql" = 'yes' ]; then
  977. $VESTA/bin/v-add-database-host pgsql localhost postgres $vpass
  978. $VESTA/bin/v-add-database admin db db $(gen_pass) pgsql
  979. fi
  980. # Adding default domain
  981. $VESTA/bin/v-add-domain admin $servername
  982. check_result $? "can't create $servername domain"
  983. # Adding cron jobs
  984. command='sudo /usr/local/vesta/bin/v-update-sys-queue disk'
  985. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  986. command='sudo /usr/local/vesta/bin/v-update-sys-queue traffic'
  987. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  988. command='sudo /usr/local/vesta/bin/v-update-sys-queue webstats'
  989. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  990. command='sudo /usr/local/vesta/bin/v-update-sys-queue backup'
  991. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  992. command='sudo /usr/local/vesta/bin/v-backup-users'
  993. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  994. command='sudo /usr/local/vesta/bin/v-update-user-stats'
  995. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  996. command='sudo /usr/local/vesta/bin/v-update-sys-rrd'
  997. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  998. service cron restart
  999. # Building inititall rrd images
  1000. $VESTA/bin/v-update-sys-rrd
  1001. # Enabling file system quota
  1002. if [ "$quota" = 'yes' ]; then
  1003. $VESTA/bin/v-add-sys-quota
  1004. fi
  1005. # Starting vesta service
  1006. update-rc.d vesta defaults
  1007. service vesta start
  1008. check_result $? "vesta start failed"
  1009. # Adding notifications
  1010. $VESTA/upd/add_notifications.sh
  1011. #----------------------------------------------------------#
  1012. # Vesta Access Info #
  1013. #----------------------------------------------------------#
  1014. # Sending install notification to vestacp.com
  1015. wget vestacp.com/notify/?$codename -O /dev/null -q
  1016. # Comparing hostname and ip
  1017. host_ip=$(host $servername| head -n 1 | awk '{print $NF}')
  1018. if [ "$host_ip" = "$ip" ]; then
  1019. ip="$servername"
  1020. fi
  1021. # Sending notification to admin email
  1022. echo -e "Congratulations, you have just successfully installed \
  1023. Vesta Control Panel
  1024. https://$ip:8083
  1025. username: admin
  1026. password: $vpass
  1027. We hope that you enjoy your installation of Vesta. Please \
  1028. feel free to contact us anytime if you have any questions.
  1029. Thank you.
  1030. --
  1031. Sincerely yours
  1032. vestacp.com team
  1033. " > $tmpfile
  1034. send_mail="$VESTA/web/inc/mail-wrapper.php"
  1035. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  1036. # Congrats
  1037. echo '======================================================='
  1038. echo
  1039. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  1040. echo ' _| _| _| _| _| _| _| '
  1041. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  1042. echo ' _| _| _| _| _| _| _| '
  1043. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  1044. echo
  1045. echo
  1046. cat $tmpfile
  1047. rm -f $tmpfile
  1048. # EOF