vst-install-ubuntu.sh 44 KB

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