vst-install-rhel.sh 45 KB

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