vst-install-rhel.sh 49 KB

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