vst-install-ubuntu.sh 45 KB

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