vst-install-amazon.sh 46 KB

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