vst-install-rhel.sh 44 KB

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