vst-install-rhel.sh 43 KB

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