vst-install-rhel.sh 49 KB

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