vst-install-amazon.sh 45 KB

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