vst-install-rhel.sh 45 KB

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