vst-install-amazon.sh 45 KB

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