vst-install-rhel.sh 46 KB

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