vst-install-debian.sh 49 KB

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