vst-install-rhel.sh 46 KB

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