vst-install-rhel.sh 47 KB

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