vst-install-rhel.sh 46 KB

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