vst-install-debian.sh 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409
  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. fi
  535. if [ "$clamd" = 'no' ]; then
  536. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  537. fi
  538. if [ "$spamd" = 'no' ]; then
  539. software=$(echo "$software" | sed -e "s/spamassassin//")
  540. software=$(echo "$software" | sed -e "s/libmail-dkim-perl//")
  541. fi
  542. if [ "$dovecot" = 'no' ]; then
  543. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  544. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  545. fi
  546. if [ "$mysql" = 'no' ]; then
  547. software=$(echo "$software" | sed -e 's/mysql-server//')
  548. software=$(echo "$software" | sed -e 's/mysql-client//')
  549. software=$(echo "$software" | sed -e 's/mysql-common//')
  550. software=$(echo "$software" | sed -e 's/php5-mysql//')
  551. software=$(echo "$software" | sed -e 's/php-mysql//')
  552. software=$(echo "$software" | sed -e 's/phpMyAdmin//')
  553. fi
  554. if [ "$postgresql" = 'no' ]; then
  555. software=$(echo "$software" | sed -e 's/postgresql-contrib//')
  556. software=$(echo "$software" | sed -e 's/postgresql//')
  557. software=$(echo "$software" | sed -e 's/php5-pgsql//')
  558. software=$(echo "$software" | sed -e 's/php-pgsql//')
  559. software=$(echo "$software" | sed -e 's/phppgadmin//')
  560. fi
  561. if [ "$softaculous" = 'no' ]; then
  562. software=$(echo "$software" | sed -e 's/vesta-softaculous//')
  563. fi
  564. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  565. software=$(echo "$software" | sed -e 's/fail2ban//')
  566. fi
  567. #----------------------------------------------------------#
  568. # Install packages #
  569. #----------------------------------------------------------#
  570. # Update system packages
  571. apt-get update
  572. # Disable daemon autostart /usr/share/doc/sysv-rc/README.policy-rc.d.gz
  573. echo -e '#!/bin/sh \nexit 101' > /usr/sbin/policy-rc.d
  574. chmod a+x /usr/sbin/policy-rc.d
  575. # Install apt packages
  576. apt-get -y install $software
  577. check_result $? "apt-get install failed"
  578. # Restore policy
  579. rm -f /usr/sbin/policy-rc.d
  580. #----------------------------------------------------------#
  581. # Configure system #
  582. #----------------------------------------------------------#
  583. # Enable SSH password auth
  584. sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
  585. service ssh restart
  586. # Disable awstats cron
  587. rm -f /etc/cron.d/awstats
  588. # Set directory color
  589. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  590. # Register /sbin/nologin and /usr/sbin/nologin
  591. echo "/sbin/nologin" >> /etc/shells
  592. echo "/usr/sbin/nologin" >> /etc/shells
  593. # NTP Synchronization
  594. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  595. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  596. chmod 775 /etc/cron.daily/ntpdate
  597. ntpdate -s pool.ntp.org
  598. # Setup rssh
  599. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  600. echo /usr/bin/rssh >> /etc/shells
  601. fi
  602. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  603. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  604. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  605. chmod 755 /usr/bin/rssh
  606. #----------------------------------------------------------#
  607. # Configure VESTA #
  608. #----------------------------------------------------------#
  609. # Installing sudo configuration
  610. mkdir -p /etc/sudoers.d
  611. cp -f $vestacp/sudo/admin /etc/sudoers.d/
  612. chmod 440 /etc/sudoers.d/admin
  613. # Configuring system env
  614. echo "export VESTA='$VESTA'" > /etc/profile.d/vesta.sh
  615. chmod 755 /etc/profile.d/vesta.sh
  616. source /etc/profile.d/vesta.sh
  617. echo 'PATH=$PATH:'$VESTA'/bin' >> /root/.bash_profile
  618. echo 'export PATH' >> /root/.bash_profile
  619. source /root/.bash_profile
  620. # Configuring logrotate for Vesta logs
  621. cp -f $vestacp/logrotate/vesta /etc/logrotate.d/
  622. # Building directory tree and creating some blank files for vesta
  623. mkdir -p $VESTA/conf $VESTA/log $VESTA/ssl $VESTA/data/ips \
  624. $VESTA/data/queue $VESTA/data/users $VESTA/data/firewall \
  625. $VESTA/data/sessions
  626. touch $VESTA/data/queue/backup.pipe $VESTA/data/queue/disk.pipe \
  627. $VESTA/data/queue/webstats.pipe $VESTA/data/queue/restart.pipe \
  628. $VESTA/data/queue/traffic.pipe $VESTA/log/system.log \
  629. $VESTA/log/nginx-error.log $VESTA/log/auth.log
  630. chmod 750 $VESTA/conf $VESTA/data/users $VESTA/data/ips $VESTA/log
  631. chmod -R 750 $VESTA/data/queue
  632. chmod 660 $VESTA/log/*
  633. rm -f /var/log/vesta
  634. ln -s $VESTA/log /var/log/vesta
  635. chmod 770 $VESTA/data/sessions
  636. # Generating vesta configuration
  637. rm -f $VESTA/conf/vesta.conf 2>/dev/null
  638. touch $VESTA/conf/vesta.conf
  639. chmod 660 $VESTA/conf/vesta.conf
  640. # WEB stack
  641. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  642. echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  643. echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  644. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  645. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  646. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  647. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  648. fi
  649. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  650. echo "WEB_SYSTEM='apache2'" >> $VESTA/conf/vesta.conf
  651. echo "WEB_RGROUPS='www-data'" >> $VESTA/conf/vesta.conf
  652. echo "WEB_PORT='8080'" >> $VESTA/conf/vesta.conf
  653. echo "WEB_SSL_PORT='8443'" >> $VESTA/conf/vesta.conf
  654. echo "WEB_SSL='mod_ssl'" >> $VESTA/conf/vesta.conf
  655. echo "PROXY_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  656. echo "PROXY_PORT='80'" >> $VESTA/conf/vesta.conf
  657. echo "PROXY_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  658. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  659. fi
  660. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  661. echo "WEB_SYSTEM='nginx'" >> $VESTA/conf/vesta.conf
  662. echo "WEB_PORT='80'" >> $VESTA/conf/vesta.conf
  663. echo "WEB_SSL_PORT='443'" >> $VESTA/conf/vesta.conf
  664. echo "WEB_SSL='openssl'" >> $VESTA/conf/vesta.conf
  665. if [ "$release" -eq 9 ]; then
  666. if [ "$phpfpm" = 'yes' ]; then
  667. echo "WEB_BACKEND='php-fpm'" >> $VESTA/conf/vesta.conf
  668. fi
  669. else
  670. if [ "$phpfpm" = 'yes' ]; then
  671. echo "WEB_BACKEND='php5-fpm'" >> $VESTA/conf/vesta.conf
  672. fi
  673. fi
  674. echo "STATS_SYSTEM='webalizer,awstats'" >> $VESTA/conf/vesta.conf
  675. fi
  676. # FTP stack
  677. if [ "$vsftpd" = 'yes' ]; then
  678. echo "FTP_SYSTEM='vsftpd'" >> $VESTA/conf/vesta.conf
  679. fi
  680. if [ "$proftpd" = 'yes' ]; then
  681. echo "FTP_SYSTEM='proftpd'" >> $VESTA/conf/vesta.conf
  682. fi
  683. # DNS stack
  684. if [ "$named" = 'yes' ]; then
  685. echo "DNS_SYSTEM='bind9'" >> $VESTA/conf/vesta.conf
  686. fi
  687. # Mail stack
  688. if [ "$exim" = 'yes' ]; then
  689. echo "MAIL_SYSTEM='exim4'" >> $VESTA/conf/vesta.conf
  690. if [ "$clamd" = 'yes' ]; then
  691. echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $VESTA/conf/vesta.conf
  692. fi
  693. if [ "$spamd" = 'yes' ]; then
  694. echo "ANTISPAM_SYSTEM='spamassassin'" >> $VESTA/conf/vesta.conf
  695. fi
  696. if [ "$dovecot" = 'yes' ]; then
  697. echo "IMAP_SYSTEM='dovecot'" >> $VESTA/conf/vesta.conf
  698. fi
  699. fi
  700. # CRON daemon
  701. echo "CRON_SYSTEM='cron'" >> $VESTA/conf/vesta.conf
  702. # Firewall stack
  703. if [ "$iptables" = 'yes' ]; then
  704. echo "FIREWALL_SYSTEM='iptables'" >> $VESTA/conf/vesta.conf
  705. fi
  706. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  707. echo "FIREWALL_EXTENSION='fail2ban'" >> $VESTA/conf/vesta.conf
  708. fi
  709. # Disk quota
  710. if [ "$quota" = 'yes' ]; then
  711. echo "DISK_QUOTA='yes'" >> $VESTA/conf/vesta.conf
  712. fi
  713. # Backups
  714. echo "BACKUP_SYSTEM='local'" >> $VESTA/conf/vesta.conf
  715. # Language
  716. echo "LANGUAGE='$lang'" >> $VESTA/conf/vesta.conf
  717. # Version
  718. echo "VERSION='0.9.8'" >> $VESTA/conf/vesta.conf
  719. # Installing hosting packages
  720. cp -rf $vestacp/packages $VESTA/data/
  721. # Installing templates
  722. cp -rf $vestacp/templates $VESTA/data/
  723. # Copying index.html to default documentroot
  724. cp $VESTA/data/templates/web/skel/public_html/index.html /var/www/
  725. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  726. # Installing firewall rules
  727. cp -rf $vestacp/firewall $VESTA/data/
  728. # Configuring server hostname
  729. $VESTA/bin/v-change-sys-hostname $servername 2>/dev/null
  730. # Generating SSL certificate
  731. $VESTA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  732. 'San Francisco' 'Vesta Control Panel' 'IT' > /tmp/vst.pem
  733. # Parsing certificate file
  734. crt_end=$(grep -n "END CERTIFICATE-" /tmp/vst.pem |cut -f 1 -d:)
  735. key_start=$(grep -n "BEGIN RSA" /tmp/vst.pem |cut -f 1 -d:)
  736. key_end=$(grep -n "END RSA" /tmp/vst.pem |cut -f 1 -d:)
  737. # Adding SSL certificate
  738. cd $VESTA/ssl
  739. sed -n "1,${crt_end}p" /tmp/vst.pem > certificate.crt
  740. sed -n "$key_start,${key_end}p" /tmp/vst.pem > certificate.key
  741. chown root:mail $VESTA/ssl/*
  742. chmod 660 $VESTA/ssl/*
  743. rm /tmp/vst.pem
  744. #----------------------------------------------------------#
  745. # Configure Nginx #
  746. #----------------------------------------------------------#
  747. if [ "$nginx" = 'yes' ]; then
  748. rm -f /etc/nginx/conf.d/*.conf
  749. cp -f $vestacp/nginx/nginx.conf /etc/nginx/
  750. cp -f $vestacp/nginx/status.conf /etc/nginx/conf.d/
  751. cp -f $vestacp/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  752. cp -f $vestacp/nginx/phppgadmin.inc /etc/nginx/conf.d/
  753. cp -f $vestacp/nginx/webmail.inc /etc/nginx/conf.d/
  754. cp -f $vestacp/logrotate/nginx /etc/logrotate.d/
  755. echo > /etc/nginx/conf.d/vesta.conf
  756. mkdir -p /var/log/nginx/domains
  757. update-rc.d nginx defaults
  758. service nginx start
  759. check_result $? "nginx start failed"
  760. fi
  761. #----------------------------------------------------------#
  762. # Configure Apache #
  763. #----------------------------------------------------------#
  764. if [ "$apache" = 'yes' ]; then
  765. cp -f $vestacp/apache2/apache2.conf /etc/apache2/
  766. cp -f $vestacp/apache2/status.conf /etc/apache2/mods-enabled/
  767. cp -f $vestacp/logrotate/apache2 /etc/logrotate.d/
  768. a2enmod rewrite
  769. a2enmod suexec
  770. a2enmod ssl
  771. a2enmod actions
  772. a2enmod ruid2
  773. a2enmod headers
  774. mkdir -p /etc/apache2/conf.d
  775. echo > /etc/apache2/conf.d/vesta.conf
  776. echo "# Powered by vesta" > /etc/apache2/sites-available/default
  777. echo "# Powered by vesta" > /etc/apache2/sites-available/default-ssl
  778. echo "# Powered by vesta" > /etc/apache2/ports.conf
  779. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  780. touch /var/log/apache2/access.log /var/log/apache2/error.log
  781. mkdir -p /var/log/apache2/domains
  782. chmod a+x /var/log/apache2
  783. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  784. chmod 751 /var/log/apache2/domains
  785. update-rc.d apache2 defaults
  786. service apache2 start
  787. check_result $? "apache2 start failed"
  788. else
  789. update-rc.d apache2 disable >/dev/null 2>&1
  790. service apache2 stop >/dev/null 2>&1
  791. fi
  792. #----------------------------------------------------------#
  793. # Configure PHP-FPM #
  794. #----------------------------------------------------------#
  795. if [ "$phpfpm" = 'yes' ]; then
  796. if [ "$release" -eq 9 ]; then
  797. cp -f $vestacp/php-fpm/www.conf /etc/php/7.0/fpm/pool.d/www.conf
  798. update-rc.d php7.0-fpm defaults
  799. service php7.0-fpm start
  800. check_result $? "php-fpm start failed"
  801. else
  802. cp -f $vestacp/php5-fpm/www.conf /etc/php5/fpm/pool.d/www.conf
  803. update-rc.d php5-fpm defaults
  804. service php5-fpm start
  805. check_result $? "php-fpm start failed"
  806. fi
  807. fi
  808. #----------------------------------------------------------#
  809. # Configure PHP #
  810. #----------------------------------------------------------#
  811. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  812. if [ -z "$ZONE" ]; then
  813. ZONE='UTC'
  814. fi
  815. for pconf in $(find /etc/php* -name php.ini); do
  816. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  817. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  818. done
  819. #----------------------------------------------------------#
  820. # Configure VSFTPD #
  821. #----------------------------------------------------------#
  822. if [ "$vsftpd" = 'yes' ]; then
  823. cp -f $vestacp/vsftpd/vsftpd.conf /etc/
  824. update-rc.d vsftpd defaults
  825. service vsftpd start
  826. check_result $? "vsftpd start failed"
  827. # To be deleted after release 0.9.8-18
  828. echo "/sbin/nologin" >> /etc/shells
  829. fi
  830. #----------------------------------------------------------#
  831. # Configure ProFTPD #
  832. #----------------------------------------------------------#
  833. if [ "$proftpd" = 'yes' ]; then
  834. echo "127.0.0.1 $servername" >> /etc/hosts
  835. cp -f $vestacp/proftpd/proftpd.conf /etc/proftpd/
  836. update-rc.d proftpd defaults
  837. service proftpd start
  838. check_result $? "proftpd start failed"
  839. fi
  840. #----------------------------------------------------------#
  841. # Configure MySQL/MariaDB #
  842. #----------------------------------------------------------#
  843. if [ "$mysql" = 'yes' ]; then
  844. mycnf="my-small.cnf"
  845. if [ $memory -gt 1200000 ]; then
  846. mycnf="my-medium.cnf"
  847. fi
  848. if [ $memory -gt 3900000 ]; then
  849. mycnf="my-large.cnf"
  850. fi
  851. # MySQL configuration
  852. cp -f $vestacp/mysql/$mycnf /etc/mysql/my.cnf
  853. mysql_install_db
  854. update-rc.d mysql defaults
  855. service mysql start
  856. check_result $? "mysql start failed"
  857. # Securing MySQL installation
  858. mpass=$(gen_pass)
  859. mysqladmin -u root password $mpass
  860. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  861. chmod 600 /root/.my.cnf
  862. mysql -e "DELETE FROM mysql.user WHERE User=''"
  863. mysql -e "DROP DATABASE test" >/dev/null 2>&1
  864. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  865. mysql -e "DELETE FROM mysql.user WHERE user='' or password='';"
  866. mysql -e "FLUSH PRIVILEGES"
  867. # Configuring phpMyAdmin
  868. if [ "$apache" = 'yes' ]; then
  869. cp -f $vestacp/pma/apache.conf /etc/phpmyadmin/
  870. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  871. fi
  872. cp -f $vestacp/pma/config.inc.php /etc/phpmyadmin/
  873. chmod 777 /var/lib/phpmyadmin/tmp
  874. fi
  875. #----------------------------------------------------------#
  876. # Configure PostgreSQL #
  877. #----------------------------------------------------------#
  878. if [ "$postgresql" = 'yes' ]; then
  879. ppass=$(gen_pass)
  880. cp -f $vestacp/postgresql/pg_hba.conf /etc/postgresql/*/main/
  881. service postgresql restart
  882. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  883. # Configuring phpPgAdmin
  884. if [ "$apache" = 'yes' ]; then
  885. cp -f $vestacp/pga/phppgadmin.conf /etc/apache2/conf.d/
  886. fi
  887. cp -f $vestacp/pga/config.inc.php /etc/phppgadmin/
  888. fi
  889. #----------------------------------------------------------#
  890. # Configure Bind #
  891. #----------------------------------------------------------#
  892. if [ "$named" = 'yes' ]; then
  893. cp -f $vestacp/bind/named.conf /etc/bind/
  894. sed -i "s%listen-on%//listen%" /etc/bind/named.conf.options
  895. chown root:bind /etc/bind/named.conf
  896. chmod 640 /etc/bind/named.conf
  897. aa-complain /usr/sbin/named 2>/dev/null
  898. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2>/dev/null
  899. service apparmor status >/dev/null 2>&1
  900. if [ $? -ne 0 ]; then
  901. service apparmor restart
  902. fi
  903. update-rc.d bind9 defaults
  904. service bind9 start
  905. check_result $? "bind9 start failed"
  906. fi
  907. #----------------------------------------------------------#
  908. # Configure Exim #
  909. #----------------------------------------------------------#
  910. if [ "$exim" = 'yes' ]; then
  911. gpasswd -a Debian-exim mail
  912. cp -f $vestacp/exim/exim4.conf.template /etc/exim4/
  913. cp -f $vestacp/exim/dnsbl.conf /etc/exim4/
  914. cp -f $vestacp/exim/spam-blocks.conf /etc/exim4/
  915. touch /etc/exim4/white-blocks.conf
  916. if [ "$spamd" = 'yes' ]; then
  917. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  918. fi
  919. if [ "$clamd" = 'yes' ]; then
  920. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  921. fi
  922. chmod 640 /etc/exim4/exim4.conf.template
  923. rm -rf /etc/exim4/domains
  924. mkdir -p /etc/exim4/domains
  925. rm -f /etc/alternatives/mta
  926. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  927. update-rc.d -f sendmail remove > /dev/null 2>&1
  928. service sendmail stop > /dev/null 2>&1
  929. update-rc.d -f postfix remove > /dev/null 2>&1
  930. service postfix stop > /dev/null 2>&1
  931. update-rc.d exim4 defaults
  932. service exim4 start
  933. check_result $? "exim4 start failed"
  934. fi
  935. #----------------------------------------------------------#
  936. # Configure Dovecot #
  937. #----------------------------------------------------------#
  938. if [ "$dovecot" = 'yes' ]; then
  939. gpasswd -a dovecot mail
  940. cp -rf $vestacp/dovecot /etc/
  941. cp -f $vestacp/logrotate/dovecot /etc/logrotate.d/
  942. chown -R root:root /etc/dovecot*
  943. if [ "$release" -eq 9 ]; then
  944. sed -i "s#namespace inbox {#namespace inbox {\n inbox = yes#" /etc/dovecot/conf.d/15-mailboxes.conf
  945. fi
  946. update-rc.d dovecot defaults
  947. service dovecot start
  948. check_result $? "dovecot start failed"
  949. fi
  950. #----------------------------------------------------------#
  951. # Configure ClamAV #
  952. #----------------------------------------------------------#
  953. if [ "$clamd" = 'yes' ]; then
  954. gpasswd -a clamav mail
  955. gpasswd -a clamav Debian-exim
  956. cp -f $vestacp/clamav/clamd.conf /etc/clamav/
  957. /usr/bin/freshclam
  958. update-rc.d clamav-daemon defaults
  959. if [ ! -d "/var/run/clamav" ]; then
  960. mkdir /var/run/clamav
  961. fi
  962. chown -R clamav:clamav /var/run/clamav
  963. if [ -e "/lib/systemd/system/clamav-daemon.service" ]; then
  964. exec_pre1='ExecStartPre=-/bin/mkdir -p /var/run/clamav'
  965. exec_pre2='ExecStartPre=-/bin/chown -R clamav:clamav /var/run/clamav'
  966. sed -i "s|\[Service\]/|[Service]\n$exec_pre1\n$exec_pre2|g" \
  967. /lib/systemd/system/clamav-daemon.service
  968. systemctl daemon-reload
  969. fi
  970. service clamav-daemon start
  971. check_result $? "clamav-daeom start failed"
  972. fi
  973. #----------------------------------------------------------#
  974. # Configure SpamAssassin #
  975. #----------------------------------------------------------#
  976. if [ "$spamd" = 'yes' ]; then
  977. update-rc.d spamassassin defaults
  978. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  979. service spamassassin start
  980. check_result $? "spamassassin start failed"
  981. unit_files="$(systemctl list-unit-files |grep spamassassin)"
  982. if [[ "$unit_files" =~ "disabled" ]]; then
  983. systemctl enable spamassassin
  984. fi
  985. fi
  986. #----------------------------------------------------------#
  987. # Configure RoundCube #
  988. #----------------------------------------------------------#
  989. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  990. if [ "$apache" = 'yes' ]; then
  991. cp -f $vestacp/roundcube/apache.conf /etc/roundcube/
  992. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  993. fi
  994. cp -f $vestacp/roundcube/main.inc.php /etc/roundcube/
  995. cp -f $vestacp/roundcube/db.inc.php /etc/roundcube/
  996. chmod 640 /etc/roundcube/debian-db-roundcube.php
  997. chmod 640 /etc/roundcube/config.inc.php
  998. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  999. chown root:www-data /etc/roundcube/config.inc.php
  1000. cp -f $vestacp/roundcube/vesta.php \
  1001. /usr/share/roundcube/plugins/password/drivers/
  1002. cp -f $vestacp/roundcube/config.inc.php /etc/roundcube/plugins/password/
  1003. r="$(gen_pass)"
  1004. mysql -e "CREATE DATABASE roundcube"
  1005. mysql -e "GRANT ALL ON roundcube.*
  1006. TO roundcube@localhost IDENTIFIED BY '$r'"
  1007. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  1008. sed -i "s/localhost/$servername/g" \
  1009. /etc/roundcube/plugins/password/config.inc.php
  1010. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  1011. chmod a+r /etc/roundcube/main.inc.php
  1012. if [ "$release" -eq 8 ] || [ "$release" -eq 9 ]; then
  1013. mv -f /etc/roundcube/main.inc.php /etc/roundcube/config.inc.php
  1014. mv -f /etc/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  1015. chmod 640 /etc/roundcube/debian-db-roundcube.php
  1016. chmod 640 /etc/roundcube/config.inc.php
  1017. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1018. chown root:www-data /etc/roundcube/config.inc.php
  1019. fi
  1020. if [ "$release" -eq 8 ]; then
  1021. # RoundCube tinyMCE fix
  1022. tinymceFixArchiveURL=$vestacp/roundcube/roundcube-tinymce.tar.gz
  1023. tinymceParentFolder=/usr/share/roundcube/program/js
  1024. tinymceFolder=$tinymceParentFolder/tinymce
  1025. tinymceBadJS=$tinymceFolder/tiny_mce.js
  1026. tinymceFixArchive=$tinymceParentFolder/roundcube-tinymce.tar.gz
  1027. if [[ -L "$tinymceFolder" && -d "$tinymceFolder" ]]; then
  1028. if [ -f "$tinymceBadJS" ]; then
  1029. wget $tinymceFixArchiveURL -O $tinymceFixArchive
  1030. if [[ -f "$tinymceFixArchive" && -s "$tinymceFixArchive" ]]
  1031. then
  1032. rm $tinymceFolder
  1033. tar -xzf $tinymceFixArchive -C $tinymceParentFolder
  1034. rm $tinymceFixArchive
  1035. chown -R root:root $tinymceFolder
  1036. else
  1037. echo -n "File roundcube-tinymce.tar.gz is not downloaded,"
  1038. echo "RoundCube tinyMCE fix is not applied"
  1039. rm $tinymceFixArchive
  1040. fi
  1041. fi
  1042. fi
  1043. fi
  1044. fi
  1045. #----------------------------------------------------------#
  1046. # Configure Fail2Ban #
  1047. #----------------------------------------------------------#
  1048. if [ "$fail2ban" = 'yes' ]; then
  1049. cp -rf $vestacp/fail2ban /etc/
  1050. if [ "$dovecot" = 'no' ]; then
  1051. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1052. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1053. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1054. fi
  1055. if [ "$exim" = 'no' ]; then
  1056. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1057. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1058. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1059. fi
  1060. if [ "$vsftpd" = 'yes' ]; then
  1061. #Create vsftpd Log File
  1062. if [ ! -f "/var/log/vsftpd.log" ]; then
  1063. touch /var/log/vsftpd.log
  1064. fi
  1065. fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1066. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1067. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1068. fi
  1069. update-rc.d fail2ban defaults
  1070. service fail2ban start
  1071. check_result $? "fail2ban start failed"
  1072. fi
  1073. #----------------------------------------------------------#
  1074. # Configure Admin User #
  1075. #----------------------------------------------------------#
  1076. # Deleting old admin user
  1077. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1078. chattr -i /home/admin/conf > /dev/null 2>&1
  1079. userdel -f admin >/dev/null 2>&1
  1080. chattr -i /home/admin/conf >/dev/null 2>&1
  1081. mv -f /home/admin $vst_backups/home/ >/dev/null 2>&1
  1082. rm -f /tmp/sess_* >/dev/null 2>&1
  1083. fi
  1084. if [ ! -z "$(grep ^admin: /etc/group)" ]; then
  1085. groupdel admin > /dev/null 2>&1
  1086. fi
  1087. # Adding vesta account
  1088. $VESTA/bin/v-add-user admin $vpass $email default System Administrator
  1089. check_result $? "can't create admin user"
  1090. $VESTA/bin/v-change-user-shell admin bash
  1091. $VESTA/bin/v-change-user-language admin $lang
  1092. # RoundCube permissions fix
  1093. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1094. if [ ! -d "/var/log/roundcube" ]; then
  1095. mkdir /var/log/roundcube
  1096. fi
  1097. chown admin:admin /var/log/roundcube
  1098. fi
  1099. # Configuring system ips
  1100. $VESTA/bin/v-update-sys-ip
  1101. # Get main ip
  1102. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1103. local_ip=$ip
  1104. # Firewall configuration
  1105. if [ "$iptables" = 'yes' ]; then
  1106. $VESTA/bin/v-update-firewall
  1107. fi
  1108. # Get public ip
  1109. pub_ip=$(curl -s vestacp.com/what-is-my-ip/)
  1110. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1111. $VESTA/bin/v-change-sys-ip-nat $ip $pub_ip
  1112. ip=$pub_ip
  1113. fi
  1114. # Configuring libapache2-mod-remoteip
  1115. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  1116. cd /etc/apache2/mods-available
  1117. echo "<IfModule mod_remoteip.c>" > remoteip.conf
  1118. echo " RemoteIPHeader X-Real-IP" >> remoteip.conf
  1119. if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ip" != "127.0.0.1" ]; then
  1120. echo " RemoteIPInternalProxy 127.0.0.1" >> remoteip.conf
  1121. fi
  1122. if [ ! -z "$local_ip" ] && [ "$local_ip" != "$pub_ip" ]; then
  1123. echo " RemoteIPInternalProxy $local_ip" >> remoteip.conf
  1124. fi
  1125. if [ ! -z "$pub_ip" ]; then
  1126. echo " RemoteIPInternalProxy $pub_ip" >> remoteip.conf
  1127. fi
  1128. echo "</IfModule>" >> remoteip.conf
  1129. sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  1130. a2enmod remoteip
  1131. service apache2 restart
  1132. fi
  1133. # Configuring mysql host
  1134. if [ "$mysql" = 'yes' ]; then
  1135. $VESTA/bin/v-add-database-host mysql localhost root $mpass
  1136. $VESTA/bin/v-add-database admin default default $(gen_pass) mysql
  1137. fi
  1138. # Configuring pgsql host
  1139. if [ "$postgresql" = 'yes' ]; then
  1140. $VESTA/bin/v-add-database-host pgsql localhost postgres $ppass
  1141. $VESTA/bin/v-add-database admin db db $(gen_pass) pgsql
  1142. fi
  1143. # Adding default domain
  1144. $VESTA/bin/v-add-domain admin $servername
  1145. check_result $? "can't create $servername domain"
  1146. # Adding cron jobs
  1147. command="sudo $VESTA/bin/v-update-sys-queue disk"
  1148. $VESTA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1149. command="sudo $VESTA/bin/v-update-sys-queue traffic"
  1150. $VESTA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1151. command="sudo $VESTA/bin/v-update-sys-queue webstats"
  1152. $VESTA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1153. command="sudo $VESTA/bin/v-update-sys-queue backup"
  1154. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1155. command="sudo $VESTA/bin/v-backup-users"
  1156. $VESTA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1157. command="sudo $VESTA/bin/v-update-user-stats"
  1158. $VESTA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1159. command="sudo $VESTA/bin/v-update-sys-rrd"
  1160. $VESTA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1161. service cron restart
  1162. # Building inititall rrd images
  1163. $VESTA/bin/v-update-sys-rrd
  1164. # Enabling file system quota
  1165. if [ "$quota" = 'yes' ]; then
  1166. $VESTA/bin/v-add-sys-quota
  1167. fi
  1168. # Enabling softaculous plugin
  1169. if [ "$softaculous" = 'yes' ]; then
  1170. $VESTA/bin/v-add-vesta-softaculous
  1171. fi
  1172. # Starting vesta service
  1173. update-rc.d vesta defaults
  1174. service vesta start
  1175. check_result $? "vesta start failed"
  1176. chown admin:admin $VESTA/data/sessions
  1177. # Adding notifications
  1178. $VESTA/upd/add_notifications.sh
  1179. # Adding cronjob for autoupdates
  1180. $VESTA/bin/v-add-cron-vesta-autoupdate
  1181. #----------------------------------------------------------#
  1182. # Vesta Access Info #
  1183. #----------------------------------------------------------#
  1184. # Comparing hostname and ip
  1185. host_ip=$(host $servername| head -n 1 | awk '{print $NF}')
  1186. if [ "$host_ip" = "$ip" ]; then
  1187. ip="$servername"
  1188. fi
  1189. # Sending notification to admin email
  1190. echo -e "Congratulations, you have just successfully installed \
  1191. Vesta Control Panel
  1192. https://$ip:8083
  1193. username: admin
  1194. password: $vpass
  1195. We hope that you enjoy your installation of Vesta. Please \
  1196. feel free to contact us anytime if you have any questions.
  1197. Thank you.
  1198. --
  1199. Sincerely yours
  1200. vestacp.com team
  1201. " > $tmpfile
  1202. send_mail="$VESTA/web/inc/mail-wrapper.php"
  1203. cat $tmpfile | $send_mail -s "Vesta Control Panel" $email
  1204. # Congrats
  1205. echo '======================================================='
  1206. echo
  1207. echo ' _| _| _|_|_|_| _|_|_| _|_|_|_|_| _|_| '
  1208. echo ' _| _| _| _| _| _| _| '
  1209. echo ' _| _| _|_|_| _|_| _| _|_|_|_| '
  1210. echo ' _| _| _| _| _| _| _| '
  1211. echo ' _| _|_|_|_| _|_|_| _| _| _| '
  1212. echo
  1213. echo
  1214. cat $tmpfile
  1215. rm -f $tmpfile
  1216. # EOF