vst-install-amazon.sh 45 KB

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