vst-install-amazon.sh 46 KB

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