vst-install-ubuntu.sh 46 KB

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