vst-install-ubuntu.sh 46 KB

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