vst-install-ubuntu.sh 49 KB

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