hst-install-debian.sh 55 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582
  1. #!/bin/bash
  2. # Hestia Debian installer v1.0
  3. #----------------------------------------------------------#
  4. # Variables&Functions #
  5. #----------------------------------------------------------#
  6. export PATH=$PATH:/sbin
  7. export DEBIAN_FRONTEND=noninteractive
  8. RHOST='apt.hestiacp.com'
  9. GPG='gpg.hestiacp.com'
  10. VERSION='debian'
  11. HESTIA='/usr/local/hestia'
  12. LOG="/root/hst_install_backups/$(date +%s).log"
  13. memory=$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])
  14. hst_backups="/root/hst_install_backups/$(date +%s)"
  15. arch=$(uname -i)
  16. os='debian'
  17. release=$(cat /etc/debian_version|grep -o [0-9]|head -n1)
  18. codename="$(cat /etc/os-release |grep VERSION= |cut -f 2 -d \(|cut -f 1 -d \))"
  19. hestiacp="$HESTIA/install/$VERSION/$release"
  20. pma_v='4.8.3'
  21. if [ "$release" -eq 9 ]; then
  22. software="nginx apache2 apache2-utils apache2-suexec-custom
  23. libapache2-mod-ruid2 libapache2-mod-fcgid libapache2-mod-php php
  24. php-common php-cgi php-mysql php-curl php-pgsql awstats webalizer
  25. vsftpd proftpd-basic bind9 exim4 exim4-daemon-heavy clamav-daemon
  26. spamassassin dovecot-imapd dovecot-pop3d roundcube-core net-tools
  27. roundcube-mysql roundcube-plugins mariadb-client mariadb-common
  28. mariadb-server postgresql postgresql-contrib phppgadmin phpmyadmin mc
  29. flex whois rssh git idn zip sudo bc ftp lsof ntpdate rrdtool quota
  30. e2fslibs bsdutils e2fsprogs curl imagemagick fail2ban dnsutils
  31. bsdmainutils cron hestia hestia-nginx hestia-php expect libmail-dkim-perl
  32. unrar-free vim-common"
  33. else
  34. software="nginx apache2 apache2-utils apache2.2-common
  35. apache2-suexec-custom libapache2-mod-ruid2
  36. libapache2-mod-fcgid libapache2-mod-php5 php5 php5-common php5-cgi
  37. php5-mysql php5-curl php5-pgsql awstats webalizer vsftpd net-tools
  38. proftpd-basic bind9 exim4 exim4-daemon-heavy clamav-daemon
  39. spamassassin dovecot-imapd dovecot-pop3d roundcube-core
  40. roundcube-mysql roundcube-plugins mariadb-client mariadb-common
  41. mariadb-server postgresql postgresql-contrib phppgadmin phpMyAdmin mc
  42. flex whois rssh git idn zip sudo bc ftp lsof ntpdate rrdtool quota
  43. e2fslibs bsdutils e2fsprogs curl imagemagick fail2ban dnsutils
  44. bsdmainutils cron hestia hestia-nginx hestia-php expect libmail-dkim-perl
  45. unrar-free vim-common"
  46. fi
  47. # Defining help function
  48. help() {
  49. echo "Usage: $0 [OPTIONS]
  50. -a, --apache Install Apache [yes|no] default: yes
  51. -n, --nginx Install Nginx [yes|no] default: yes
  52. -w, --phpfpm Install PHP-FPM [yes|no] default: no
  53. -o, --multiphp Install Multi-PHP [yes|no] default: no
  54. -v, --vsftpd Install Vsftpd [yes|no] default: yes
  55. -j, --proftpd Install ProFTPD [yes|no] default: no
  56. -k, --named Install Bind [yes|no] default: yes
  57. -m, --mysql Install MariaDB [yes|no] default: yes
  58. -g, --postgresql Install PostgreSQL [yes|no] default: no
  59. -x, --exim Install Exim [yes|no] default: yes
  60. -z, --dovecot Install Dovecot [yes|no] default: yes
  61. -c, --clamav Install ClamAV [yes|no] default: yes
  62. -t, --spamassassin Install SpamAssassin [yes|no] default: yes
  63. -i, --iptables Install Iptables [yes|no] default: yes
  64. -b, --fail2ban Install Fail2ban [yes|no] default: yes
  65. -q, --quota Filesystem Quota [yes|no] default: no
  66. -d, --api Activate API [yes|no] default: yes
  67. -r, --port Change Backend Port default: 8083
  68. -l, --lang Default language default: en
  69. -y, --interactive Interactive install [yes|no] default: yes
  70. -s, --hostname Set hostname
  71. -e, --email Set admin email
  72. -p, --password Set admin password
  73. -f, --force Force installation
  74. -h, --help Print this help
  75. Example: bash $0 -e demo@hestiacp.com -p p4ssw0rd --apache no --phpfpm yes"
  76. exit 1
  77. }
  78. # Defining password-gen function
  79. gen_pass() {
  80. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  81. LENGTH=16
  82. while [ ${n:=1} -le $LENGTH ]; do
  83. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  84. let n+=1
  85. done
  86. echo "$PASS"
  87. }
  88. # Defining return code check function
  89. check_result() {
  90. if [ $1 -ne 0 ]; then
  91. echo "Error: $2"
  92. exit $1
  93. fi
  94. }
  95. # Defining function to set default value
  96. set_default_value() {
  97. eval variable=\$$1
  98. if [ -z "$variable" ]; then
  99. eval $1=$2
  100. fi
  101. if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then
  102. eval $1=$2
  103. fi
  104. }
  105. # Defining function to set default language value
  106. set_default_lang() {
  107. if [ -z "$lang" ]; then
  108. eval lang=$1
  109. fi
  110. lang_list="
  111. ar cz el fa hu ja no pt se ua
  112. bs da en fi id ka pl ro tr vi
  113. cn de es fr it nl pt-BR ru tw
  114. bg ko sr th ur"
  115. if !(echo $lang_list |grep -w $lang > /dev/null 2>&1); then
  116. eval lang=$1
  117. fi
  118. }
  119. # Define the default backend port
  120. set_default_port() {
  121. if [ -z "$port" ]; then
  122. eval port=$1
  123. fi
  124. }
  125. #----------------------------------------------------------#
  126. # Verifications #
  127. #----------------------------------------------------------#
  128. # Creating temporary file
  129. tmpfile=$(mktemp -p /tmp)
  130. # Translating argument to --gnu-long-options
  131. for arg; do
  132. delim=""
  133. case "$arg" in
  134. --apache) args="${args}-a " ;;
  135. --nginx) args="${args}-n " ;;
  136. --phpfpm) args="${args}-w " ;;
  137. --vsftpd) args="${args}-v " ;;
  138. --proftpd) args="${args}-j " ;;
  139. --named) args="${args}-k " ;;
  140. --mysql) args="${args}-m " ;;
  141. --postgresql) args="${args}-g " ;;
  142. --exim) args="${args}-x " ;;
  143. --dovecot) args="${args}-z " ;;
  144. --clamav) args="${args}-c " ;;
  145. --spamassassin) args="${args}-t " ;;
  146. --iptables) args="${args}-i " ;;
  147. --fail2ban) args="${args}-b " ;;
  148. --multiphp) args="${args}-o " ;;
  149. --quota) args="${args}-q " ;;
  150. --port) args="${args}-r " ;;
  151. --lang) args="${args}-l " ;;
  152. --interactive) args="${args}-y " ;;
  153. --api) args="${args}-d " ;;
  154. --hostname) args="${args}-s " ;;
  155. --email) args="${args}-e " ;;
  156. --password) args="${args}-p " ;;
  157. --force) args="${args}-f " ;;
  158. --help) args="${args}-h " ;;
  159. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  160. args="${args}${delim}${arg}${delim} ";;
  161. esac
  162. done
  163. eval set -- "$args"
  164. # Parsing arguments
  165. 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
  166. case $Option in
  167. a) apache=$OPTARG ;; # Apache
  168. n) nginx=$OPTARG ;; # Nginx
  169. w) phpfpm=$OPTARG ;; # PHP-FPM
  170. o) multiphp=$OPTARG ;; # Multi-PHP
  171. v) vsftpd=$OPTARG ;; # Vsftpd
  172. j) proftpd=$OPTARG ;; # Proftpd
  173. k) named=$OPTARG ;; # Named
  174. m) mysql=$OPTARG ;; # MariaDB
  175. g) postgresql=$OPTARG ;; # PostgreSQL
  176. x) exim=$OPTARG ;; # Exim
  177. z) dovecot=$OPTARG ;; # Dovecot
  178. c) clamd=$OPTARG ;; # ClamAV
  179. t) spamd=$OPTARG ;; # SpamAssassin
  180. i) iptables=$OPTARG ;; # Iptables
  181. b) fail2ban=$OPTARG ;; # Fail2ban
  182. q) quota=$OPTARG ;; # FS Quota
  183. r) port=$OPTARG ;; # Backend Port
  184. l) lang=$OPTARG ;; # Language
  185. d) api=$OPTARG ;; # Activate API
  186. y) interactive=$OPTARG ;; # Interactive install
  187. s) servername=$OPTARG ;; # Hostname
  188. e) email=$OPTARG ;; # Admin email
  189. p) vpass=$OPTARG ;; # Admin password
  190. f) force='yes' ;; # Force install
  191. h) help ;; # Help
  192. *) help ;; # Print help (default)
  193. esac
  194. done
  195. # Defining default software stack
  196. set_default_value 'nginx' 'yes'
  197. set_default_value 'apache' 'yes'
  198. set_default_value 'phpfpm' 'no'
  199. set_default_value 'multiphp' 'no'
  200. set_default_value 'vsftpd' 'yes'
  201. set_default_value 'proftpd' 'no'
  202. set_default_value 'named' 'yes'
  203. set_default_value 'mysql' 'yes'
  204. set_default_value 'postgresql' 'no'
  205. set_default_value 'exim' 'yes'
  206. set_default_value 'dovecot' 'yes'
  207. if [ $memory -lt 1500000 ]; then
  208. set_default_value 'clamd' 'no'
  209. set_default_value 'spamd' 'no'
  210. else
  211. set_default_value 'clamd' 'yes'
  212. set_default_value 'spamd' 'yes'
  213. fi
  214. set_default_value 'iptables' 'yes'
  215. set_default_value 'fail2ban' 'yes'
  216. set_default_value 'quota' 'no'
  217. set_default_value 'interactive' 'yes'
  218. set_default_value 'api' 'yes'
  219. set_default_port '8083'
  220. set_default_lang 'en'
  221. # Checking software conflicts
  222. if [ "$phpfpm" = 'yes' ]; then
  223. apache='no'
  224. nginx='yes'
  225. fi
  226. if [ "$multiphp" = 'yes' ]; then
  227. phpfpm='no'
  228. fi
  229. if [ "$proftpd" = 'yes' ]; then
  230. vsftpd='no'
  231. fi
  232. if [ "$exim" = 'no' ]; then
  233. clamd='no'
  234. spamd='no'
  235. dovecot='no'
  236. fi
  237. if [ "$iptables" = 'no' ]; then
  238. fail2ban='no'
  239. fi
  240. # Checking root permissions
  241. if [ "x$(id -u)" != 'x0' ]; then
  242. check_result 1 "Script can be run executed only by root"
  243. fi
  244. # Checking admin user account
  245. if [ ! -z "$(grep ^admin: /etc/passwd /etc/group)" ] && [ -z "$force" ]; then
  246. echo 'Please remove admin user account before proceeding.'
  247. echo 'If you want to do it automatically run installer with -f option:'
  248. echo -e "Example: bash $0 --force\n"
  249. check_result 1 "User admin exists"
  250. fi
  251. # Update apt repository
  252. echo "Please wait a few seconds, we update your repository before we start the installation process..."
  253. apt-get -qq update
  254. # Creating backup directory
  255. mkdir -p $hst_backups
  256. # Checking wget
  257. if [ ! -e '/usr/bin/wget' ]; then
  258. echo "Install missing wget..."
  259. apt-get -y install wget >> $LOG
  260. check_result $? "Can't install wget"
  261. fi
  262. # Checking dirmngr
  263. if [ ! -e '/usr/bin/dirmngr' ]; then
  264. echo "Install missing dirmngr..."
  265. apt-get -y install dirmngr >> $LOG
  266. check_result $? "Can't install dirmngr"
  267. fi
  268. # Checking screen
  269. if [ ! -e '/usr/bin/screen' ]; then
  270. echo "Install missing screen..."
  271. apt-get -y install screen >> $LOG
  272. check_result $? "Can't install screen"
  273. fi
  274. # Check if apt-transport-https is installed
  275. if [ ! -e '/usr/lib/apt/methods/https' ]; then
  276. echo "Install missing apt-transport-https..."
  277. apt-get -y install apt-transport-https >> $LOG
  278. check_result $? "Can't install apt-transport-https"
  279. fi
  280. # Check if apparmor is installed
  281. if [ $(dpkg-query -W -f='${Status}' apparmor 2>/dev/null | grep -c "ok installed") -eq 0 ]; then
  282. apparmor='no'
  283. else
  284. apparmor='yes'
  285. fi
  286. # Checking repository availability
  287. wget --quiet "https://$GPG/deb_signing.key" -O /dev/null
  288. check_result $? "No access to Hestia repository"
  289. # Check installed packages
  290. tmpfile=$(mktemp -p /tmp)
  291. dpkg --get-selections > $tmpfile
  292. for pkg in exim4 mariadb-server apache2 nginx hestia; do
  293. if [ ! -z "$(grep $pkg $tmpfile)" ]; then
  294. conflicts="$pkg $conflicts"
  295. fi
  296. done
  297. rm -f $tmpfile
  298. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  299. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  300. echo
  301. echo 'Following packages are already installed:'
  302. echo "$conflicts"
  303. echo
  304. echo 'It is highly recommended to remove them before proceeding.'
  305. echo 'If you want to force installation run this script with -f option:'
  306. echo "Example: bash $0 --force"
  307. echo
  308. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  309. echo
  310. check_result 1 "Control Panel should be installed on clean server."
  311. fi
  312. #----------------------------------------------------------#
  313. # Brief Info #
  314. #----------------------------------------------------------#
  315. # Printing nice ASCII logo
  316. clear
  317. echo
  318. echo ' _ _ _ _ ____ ____ '
  319. echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
  320. echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) |'
  321. echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
  322. echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
  323. echo
  324. echo ' Hestia Control Panel'
  325. echo -e "\n\n"
  326. echo 'The following software will be installed on your system:'
  327. # Web stack
  328. if [ "$nginx" = 'yes' ]; then
  329. echo ' - Nginx Web Server'
  330. fi
  331. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  332. echo ' - Apache Web Server'
  333. fi
  334. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  335. echo ' - Apache Web Server (as backend)'
  336. fi
  337. if [ "$phpfpm" = 'yes' ]; then
  338. echo ' - PHP-FPM Application Server'
  339. fi
  340. if [ "$multiphp" = 'yes' ]; then
  341. echo ' - Multi-PHP Environment'
  342. fi
  343. # DNS stack
  344. if [ "$named" = 'yes' ]; then
  345. echo ' - Bind DNS Server'
  346. fi
  347. # Mail stack
  348. if [ "$exim" = 'yes' ]; then
  349. echo -n ' - Exim Mail Server'
  350. if [ "$clamd" = 'yes' ] || [ "$spamd" = 'yes' ] ; then
  351. echo -n ' + '
  352. if [ "$clamd" = 'yes' ]; then
  353. echo -n 'ClamAV'
  354. fi
  355. if [ "$spamd" = 'yes' ]; then
  356. echo -n 'SpamAssassin'
  357. fi
  358. fi
  359. echo
  360. if [ "$dovecot" = 'yes' ]; then
  361. echo ' - Dovecot POP3/IMAP Server'
  362. fi
  363. fi
  364. # Database stack
  365. if [ "$mysql" = 'yes' ]; then
  366. echo ' - MariaDB Database Server'
  367. fi
  368. if [ "$postgresql" = 'yes' ]; then
  369. echo ' - PostgreSQL Database Server'
  370. fi
  371. # FTP stack
  372. if [ "$vsftpd" = 'yes' ]; then
  373. echo ' - Vsftpd FTP Server'
  374. fi
  375. if [ "$proftpd" = 'yes' ]; then
  376. echo ' - ProFTPD FTP Server'
  377. fi
  378. # Firewall stack
  379. if [ "$iptables" = 'yes' ]; then
  380. echo -n ' - Iptables Firewall'
  381. fi
  382. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  383. echo -n ' + Fail2Ban'
  384. fi
  385. echo -e "\n\n"
  386. # Asking for confirmation to proceed
  387. if [ "$interactive" = 'yes' ]; then
  388. read -p 'Would you like to continue [y/n]: ' answer
  389. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  390. echo 'Goodbye'
  391. exit 1
  392. fi
  393. # Asking for contact email
  394. if [ -z "$email" ]; then
  395. read -p 'Please enter admin email address: ' email
  396. fi
  397. # Asking to set FQDN hostname
  398. if [ -z "$servername" ]; then
  399. read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
  400. fi
  401. fi
  402. # Generating admin password if it wasn't set
  403. if [ -z "$vpass" ]; then
  404. vpass=$(gen_pass)
  405. fi
  406. # Set hostname if it wasn't set
  407. if [ -z "$servername" ]; then
  408. servername=$(hostname -f)
  409. fi
  410. # Set FQDN if it wasn't set
  411. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  412. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  413. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  414. if [ ! -z "$servername" ]; then
  415. servername="$servername.example.com"
  416. else
  417. servername="example.com"
  418. fi
  419. echo "127.0.0.1 $servername" >> /etc/hosts
  420. fi
  421. # Set email if it wasn't set
  422. if [ -z "$email" ]; then
  423. email="admin@$servername"
  424. fi
  425. # Print backup directory
  426. echo "Installation backup directory: $hst_backups"
  427. # Print Log File Path
  428. echo "Installation Log File: $LOG"
  429. # Printing start message and sleeping for 2 seconds
  430. echo -e "\n\nWe will now install HestiaCP and all required packages. The process will take around 10-15 minutes...\n"
  431. sleep 2
  432. #----------------------------------------------------------#
  433. # Checking swap #
  434. #----------------------------------------------------------#
  435. # Checking swap on small instances
  436. if [ -z "$(swapon -s)" ] && [ $memory -lt 1000000 ]; then
  437. fallocate -l 1G /swapfile
  438. chmod 600 /swapfile
  439. mkswap /swapfile
  440. swapon /swapfile
  441. echo "/swapfile none swap sw 0 0" >> /etc/fstab
  442. fi
  443. #----------------------------------------------------------#
  444. # Install repository #
  445. #----------------------------------------------------------#
  446. # Updating system
  447. echo "Upgrade System using apt-get..."
  448. apt-get -y upgrade >> $LOG
  449. check_result $? 'apt-get upgrade failed'
  450. # Define apt conf location
  451. apt=/etc/apt/sources.list.d
  452. # Installing nginx repo
  453. echo "deb http://nginx.org/packages/mainline/$VERSION/ $codename nginx" \
  454. > $apt/nginx.list
  455. wget --quiet http://nginx.org/keys/nginx_signing.key -O /tmp/nginx_signing.key
  456. apt-key add /tmp/nginx_signing.key >> $LOG
  457. if [ "$multiphp" = 'yes' ] || [ "$phpfpm" = 'yes' ]; then
  458. # Installing sury php repo
  459. echo "deb https://packages.sury.org/php/ $codename main" > $apt/php.list
  460. wget https://packages.sury.org/php/apt.gpg -O /tmp/php_signing.key >> $LOG
  461. apt-key add /tmp/php_signing.key >> $LOG
  462. fi
  463. # Installing MariaDB repo
  464. echo "deb http://ams2.mirrors.digitalocean.com/mariadb/repo/10.3/$VERSION $codename main" > $apt/mariadb.list
  465. screen -dm apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8
  466. # Installing hestia repo
  467. echo "deb https://$RHOST/ $codename main" > $apt/hestia.list
  468. wget --quiet https://gpg.hestiacp.com/deb_signing.key -O /tmp/deb_signing.key
  469. apt-key add /tmp/deb_signing.key >> $LOG
  470. #----------------------------------------------------------#
  471. # Backup #
  472. #----------------------------------------------------------#
  473. # Creating backup directory tree
  474. mkdir -p $hst_backups
  475. cd $hst_backups
  476. mkdir nginx apache2 php vsftpd proftpd bind exim4 dovecot clamd
  477. mkdir spamassassin mysql postgresql hestia
  478. # Backup nginx configuration
  479. service nginx stop > /dev/null 2>&1
  480. cp -r /etc/nginx/* $hst_backups/nginx > /dev/null 2>&1
  481. # Backup Apache configuration
  482. service apache2 stop > /dev/null 2>&1
  483. cp -r /etc/apache2/* $hst_backups/apache2 > /dev/null 2>&1
  484. rm -f /etc/apache2/conf.d/* > /dev/null 2>&1
  485. # Backup PHP-FPM configuration
  486. service php*-fpm stop > /dev/null 2>&1
  487. cp -r /etc/php/* $hst_backups/php/ > /dev/null 2>&1
  488. # Backup Bind configuration
  489. service bind9 stop > /dev/null 2>&1
  490. cp -r /etc/bind/* $hst_backups/bind > /dev/null 2>&1
  491. # Backup Vsftpd configuration
  492. service vsftpd stop > /dev/null 2>&1
  493. cp /etc/vsftpd.conf $hst_backups/vsftpd > /dev/null 2>&1
  494. # Backup ProFTPD configuration
  495. service proftpd stop > /dev/null 2>&1
  496. cp /etc/proftpd.conf $hst_backups/proftpd > /dev/null 2>&1
  497. # Backup Exim configuration
  498. service exim4 stop > /dev/null 2>&1
  499. cp -r /etc/exim4/* $hst_backups/exim4 > /dev/null 2>&1
  500. # Backup ClamAV configuration
  501. service clamav-daemon stop > /dev/null 2>&1
  502. cp -r /etc/clamav/* $hst_backups/clamav > /dev/null 2>&1
  503. # Backup SpamAssassin configuration
  504. service spamassassin stop > /dev/null 2>&1
  505. cp -r /etc/spamassassin/* $hst_backups/spamassassin > /dev/null 2>&1
  506. # Backup Dovecot configuration
  507. service dovecot stop > /dev/null 2>&1
  508. cp /etc/dovecot.conf $hst_backups/dovecot > /dev/null 2>&1
  509. cp -r /etc/dovecot/* $hst_backups/dovecot > /dev/null 2>&1
  510. # Backup MySQL/MariaDB configuration and data
  511. service mysql stop > /dev/null 2>&1
  512. killall -9 mysqld > /dev/null 2>&1
  513. mv /var/lib/mysql $hst_backups/mysql/mysql_datadir > /dev/null 2>&1
  514. cp -r /etc/mysql/* $hst_backups/mysql > /dev/null 2>&1
  515. mv -f /root/.my.cnf $hst_backups/mysql > /dev/null 2>&1
  516. # Backup Hestia
  517. service hestia stop > /dev/null 2>&1
  518. cp -r $HESTIA/* $hst_backups/hestia > /dev/null 2>&1
  519. apt-get -y remove hestia hestia-nginx hestia-php > /dev/null 2>&1
  520. apt-get -y purge hestia hestia-nginx hestia-php > /dev/null 2>&1
  521. rm -rf $HESTIA > /dev/null 2>&1
  522. #----------------------------------------------------------#
  523. # Package Excludes #
  524. #----------------------------------------------------------#
  525. # Excluding packages
  526. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  527. if [ "$nginx" = 'no' ]; then
  528. software=$(echo "$software" | sed -e "s/^nginx//")
  529. fi
  530. if [ "$apache" = 'no' ]; then
  531. software=$(echo "$software" | sed -e "s/apache2 //")
  532. software=$(echo "$software" | sed -e "s/apache2-utils//")
  533. software=$(echo "$software" | sed -e "s/apache2-suexec-custom//")
  534. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  535. software=$(echo "$software" | sed -e "s/libapache2-mod-ruid2//")
  536. software=$(echo "$software" | sed -e "s/libapache2-mod-rpaf//")
  537. software=$(echo "$software" | sed -e "s/libapache2-mod-fcgid//")
  538. software=$(echo "$software" | sed -e "s/libapache2-mod-php7.2//")
  539. software=$(echo "$software" | sed -e "s/libapache2-mod-php//")
  540. fi
  541. if [ "$vsftpd" = 'no' ]; then
  542. software=$(echo "$software" | sed -e "s/vsftpd//")
  543. fi
  544. if [ "$proftpd" = 'no' ]; then
  545. software=$(echo "$software" | sed -e "s/proftpd-basic//")
  546. software=$(echo "$software" | sed -e "s/proftpd-mod-vroot//")
  547. fi
  548. if [ "$named" = 'no' ]; then
  549. software=$(echo "$software" | sed -e "s/bind9//")
  550. fi
  551. if [ "$exim" = 'no' ]; then
  552. software=$(echo "$software" | sed -e "s/exim4 //")
  553. software=$(echo "$software" | sed -e "s/exim4-daemon-heavy//")
  554. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  555. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  556. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  557. software=$(echo "$software" | sed -e "s/spamassassin//")
  558. fi
  559. if [ "$clamd" = 'no' ]; then
  560. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  561. fi
  562. if [ "$spamd" = 'no' ]; then
  563. software=$(echo "$software" | sed -e "s/spamassassin//")
  564. software=$(echo "$software" | sed -e "s/libmail-dkim-perl//")
  565. fi
  566. if [ "$dovecot" = 'no' ]; then
  567. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  568. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  569. fi
  570. if [ "$mysql" = 'no' ]; then
  571. software=$(echo "$software" | sed -e 's/mariadb-server//')
  572. software=$(echo "$software" | sed -e 's/mariadb-client//')
  573. software=$(echo "$software" | sed -e 's/mariadb-common//')
  574. software=$(echo "$software" | sed -e 's/php7.2-mysql//')
  575. software=$(echo "$software" | sed -e 's/php-mysql//')
  576. software=$(echo "$software" | sed -e 's/phpMyAdmin//')
  577. software=$(echo "$software" | sed -e 's/phpmyadmin//')
  578. fi
  579. if [ "$postgresql" = 'no' ]; then
  580. software=$(echo "$software" | sed -e 's/postgresql-contrib//')
  581. software=$(echo "$software" | sed -e 's/postgresql//')
  582. software=$(echo "$software" | sed -e 's/php7.2-pgsql//')
  583. software=$(echo "$software" | sed -e 's/php-pgsql//')
  584. software=$(echo "$software" | sed -e 's/phppgadmin//')
  585. fi
  586. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  587. software=$(echo "$software" | sed -e 's/fail2ban//')
  588. fi
  589. #----------------------------------------------------------#
  590. # Package Includes #
  591. #----------------------------------------------------------#
  592. if [ "$multiphp" = 'yes' ]; then
  593. mph="php5.6-apcu php5.6-mbstring php5.6-bcmath php5.6-cli php5.6-curl
  594. php5.6-fpm php5.6-gd php5.6-intl php5.6-mcrypt php5.6-mysql
  595. php5.6-soap php5.6-xml php5.6-zip php7.0-mbstring php7.0-bcmath
  596. php7.0-cli php7.0-curl php7.0-fpm php7.0-gd php7.0-intl php7.0-mcrypt
  597. php7.0-mysql php7.0-soap php7.0-xml php7.0-zip php7.1-mbstring
  598. php7.1-bcmath php7.1-cli php7.1-curl php7.1-fpm php7.1-gd php7.1-intl
  599. php7.1-mcrypt php7.1-mysql php7.1-soap php7.1-xml php7.1-zip
  600. php7.2-mbstring php7.2-bcmath php7.2-cli php7.2-curl php7.2-fpm
  601. php7.2-gd php7.2-intl php7.2-mysql php7.2-soap php7.2-xml
  602. php7.2-zip php7.3-mbstring php7.3-bcmath php7.3-cli php7.3-curl
  603. php7.3-fpm php7.3-gd php7.3-intl php7.3-mysql php7.3-soap php7.3-xml
  604. php7.3-zip"
  605. software="$software $mph"
  606. fi
  607. if [ "$phpfpm" = 'yes' ]; then
  608. fpm="php7.2-mbstring php7.2-bcmath php7.2-cli php7.2-curl php7.2-fpm
  609. php7.2-gd php7.2-intl php7.2-mysql php7.2-soap php7.2-xml
  610. php7.2-zip"
  611. software="$software $fpm"
  612. fi
  613. #----------------------------------------------------------#
  614. # Install packages #
  615. #----------------------------------------------------------#
  616. # Updating system
  617. apt-get -qq update
  618. # Disabling daemon autostart on apt-get install
  619. echo -e '#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d
  620. chmod a+x /usr/sbin/policy-rc.d
  621. # Installing apt packages
  622. apt-get -y install $software >> $LOG
  623. check_result $? "apt-get install failed"
  624. # Restoring autostart policy
  625. rm -f /usr/sbin/policy-rc.d
  626. #----------------------------------------------------------#
  627. # Configure system #
  628. #----------------------------------------------------------#
  629. # Enable SSH password authentication
  630. sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
  631. # Disable SSH suffix broadcast
  632. echo '' >> /etc/ssh/sshd_config
  633. echo 'DebianBanner no' >> /etc/ssh/sshd_config
  634. service ssh restart
  635. # Disable AWStats cron
  636. rm -f /etc/cron.d/awstats
  637. # Set directory color
  638. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  639. # Register /sbin/nologin and /usr/sbin/nologin
  640. echo "/sbin/nologin" >> /etc/shells
  641. echo "/usr/sbin/nologin" >> /etc/shells
  642. # Configuring NTP
  643. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  644. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  645. chmod 755 /etc/cron.daily/ntpdate
  646. ntpdate -s pool.ntp.org
  647. # Setup rssh
  648. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  649. echo /usr/bin/rssh >> /etc/shells
  650. fi
  651. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  652. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  653. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  654. chmod 755 /usr/bin/rssh
  655. #----------------------------------------------------------#
  656. # Configure Hestia #
  657. #----------------------------------------------------------#
  658. # Installing sudo configuration
  659. mkdir -p /etc/sudoers.d
  660. cp -f $hestiacp/sudo/admin /etc/sudoers.d/
  661. chmod 440 /etc/sudoers.d/admin
  662. # Configuring system env
  663. echo "export HESTIA='$HESTIA'" > /etc/profile.d/hestia.sh
  664. echo "export VESTA='$HESTIA'" >> /etc/profile.d/hestia.sh # Vesta compatibility
  665. chmod 755 /etc/profile.d/hestia.sh
  666. source /etc/profile.d/hestia.sh
  667. echo 'PATH=$PATH:'$HESTIA'/bin' >> /root/.bash_profile
  668. echo 'export PATH' >> /root/.bash_profile
  669. source /root/.bash_profile
  670. # Configuring logrotate for Hestia logs
  671. cp -f $hestiacp/logrotate/hestia /etc/logrotate.d/hestia
  672. # Building directory tree and creating some blank files for Hestia
  673. mkdir -p $HESTIA/conf $HESTIA/log $HESTIA/ssl $HESTIA/data/ips \
  674. $HESTIA/data/queue $HESTIA/data/users $HESTIA/data/firewall \
  675. $HESTIA/data/sessions
  676. touch $HESTIA/data/queue/backup.pipe $HESTIA/data/queue/disk.pipe \
  677. $HESTIA/data/queue/webstats.pipe $HESTIA/data/queue/restart.pipe \
  678. $HESTIA/data/queue/traffic.pipe $HESTIA/log/system.log \
  679. $HESTIA/log/nginx-error.log $HESTIA/log/auth.log
  680. chmod 750 $HESTIA/conf $HESTIA/data/users $HESTIA/data/ips $HESTIA/log
  681. chmod -R 750 $HESTIA/data/queue
  682. chmod 660 $HESTIA/log/*
  683. rm -f /var/log/hestia
  684. ln -s $HESTIA/log /var/log/hestia
  685. chmod 770 $HESTIA/data/sessions
  686. # Generating Hestia configuration
  687. rm -f $HESTIA/conf/hestia.conf 2>/dev/null
  688. touch $HESTIA/conf/hestia.conf
  689. chmod 660 $HESTIA/conf/hestia.conf
  690. # Symlink to Vesta for compatibilty
  691. ln -s $HESTIA /usr/local/vesta
  692. ln -s $HESTIA/conf/hestia.conf /usr/local/vesta/conf/vesta.conf
  693. # Web stack
  694. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  695. echo "WEB_SYSTEM='apache2'" >> $HESTIA/conf/hestia.conf
  696. echo "WEB_RGROUPS='www-data'" >> $HESTIA/conf/hestia.conf
  697. echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
  698. echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  699. echo "WEB_SSL='mod_ssl'" >> $HESTIA/conf/hestia.conf
  700. echo "STATS_SYSTEM='webalizer,awstats'" >> $HESTIA/conf/hestia.conf
  701. fi
  702. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  703. echo "WEB_SYSTEM='apache2'" >> $HESTIA/conf/hestia.conf
  704. echo "WEB_RGROUPS='www-data'" >> $HESTIA/conf/hestia.conf
  705. echo "WEB_PORT='8080'" >> $HESTIA/conf/hestia.conf
  706. echo "WEB_SSL_PORT='8443'" >> $HESTIA/conf/hestia.conf
  707. echo "WEB_SSL='mod_ssl'" >> $HESTIA/conf/hestia.conf
  708. echo "PROXY_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
  709. echo "PROXY_PORT='80'" >> $HESTIA/conf/hestia.conf
  710. echo "PROXY_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  711. echo "STATS_SYSTEM='webalizer,awstats'" >> $HESTIA/conf/hestia.conf
  712. fi
  713. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  714. echo "WEB_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
  715. echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
  716. echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  717. echo "WEB_SSL='openssl'" >> $HESTIA/conf/hestia.conf
  718. if [ "$release" -eq 9 ]; then
  719. if [ "$phpfpm" = 'yes' ]; then
  720. echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
  721. fi
  722. else
  723. if [ "$phpfpm" = 'yes' ]; then
  724. echo "WEB_BACKEND='php5-fpm'" >> $HESTIA/conf/hestia.conf
  725. fi
  726. fi
  727. echo "STATS_SYSTEM='webalizer,awstats'" >> $HESTIA/conf/hestia.conf
  728. fi
  729. # FTP stack
  730. if [ "$vsftpd" = 'yes' ]; then
  731. echo "FTP_SYSTEM='vsftpd'" >> $HESTIA/conf/hestia.conf
  732. fi
  733. if [ "$proftpd" = 'yes' ]; then
  734. echo "FTP_SYSTEM='proftpd'" >> $HESTIA/conf/hestia.conf
  735. fi
  736. # DNS stack
  737. if [ "$named" = 'yes' ]; then
  738. echo "DNS_SYSTEM='bind9'" >> $HESTIA/conf/hestia.conf
  739. fi
  740. # Mail stack
  741. if [ "$exim" = 'yes' ]; then
  742. echo "MAIL_SYSTEM='exim4'" >> $HESTIA/conf/hestia.conf
  743. if [ "$clamd" = 'yes' ]; then
  744. echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $HESTIA/conf/hestia.conf
  745. fi
  746. if [ "$spamd" = 'yes' ]; then
  747. echo "ANTISPAM_SYSTEM='spamassassin'" >> $HESTIA/conf/hestia.conf
  748. fi
  749. if [ "$dovecot" = 'yes' ]; then
  750. echo "IMAP_SYSTEM='dovecot'" >> $HESTIA/conf/hestia.conf
  751. fi
  752. fi
  753. # Cron daemon
  754. echo "CRON_SYSTEM='cron'" >> $HESTIA/conf/hestia.conf
  755. # Firewall stack
  756. if [ "$iptables" = 'yes' ]; then
  757. echo "FIREWALL_SYSTEM='iptables'" >> $HESTIA/conf/hestia.conf
  758. fi
  759. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  760. echo "FIREWALL_EXTENSION='fail2ban'" >> $HESTIA/conf/hestia.conf
  761. fi
  762. # Disk quota
  763. if [ "$quota" = 'yes' ]; then
  764. echo "DISK_QUOTA='yes'" >> $HESTIA/conf/hestia.conf
  765. fi
  766. # Backups
  767. echo "BACKUP_SYSTEM='local'" >> $HESTIA/conf/hestia.conf
  768. # Language
  769. echo "LANGUAGE='$lang'" >> $HESTIA/conf/hestia.conf
  770. # Version
  771. echo "VERSION='0.9.8'" >> $HESTIA/conf/hestia.conf
  772. # Installing hosting packages
  773. cp -rf $hestiacp/packages $HESTIA/data/
  774. # Installing templates
  775. cp -rf $hestiacp/templates $HESTIA/data/
  776. # Copying index.html to default documentroot
  777. cp $HESTIA/data/templates/web/skel/public_html/index.html /var/www/
  778. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  779. # Installing firewall rules
  780. cp -rf $hestiacp/firewall $HESTIA/data/
  781. # Configuring server hostname
  782. $HESTIA/bin/v-change-sys-hostname $servername 2>/dev/null
  783. # Generating SSL certificate
  784. $HESTIA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  785. 'San Francisco' 'Hestia Control Panel' 'IT' > /tmp/hst.pem
  786. # Parsing certificate file
  787. crt_end=$(grep -n "END CERTIFICATE-" /tmp/hst.pem |cut -f 1 -d:)
  788. key_start=$(grep -n "BEGIN RSA" /tmp/hst.pem |cut -f 1 -d:)
  789. key_end=$(grep -n "END RSA" /tmp/hst.pem |cut -f 1 -d:)
  790. # Adding SSL certificate
  791. cd $HESTIA/ssl
  792. sed -n "1,${crt_end}p" /tmp/hst.pem > certificate.crt
  793. sed -n "$key_start,${key_end}p" /tmp/hst.pem > certificate.key
  794. chown root:mail $HESTIA/ssl/*
  795. chmod 660 $HESTIA/ssl/*
  796. rm /tmp/hst.pem
  797. #----------------------------------------------------------#
  798. # Configure Nginx #
  799. #----------------------------------------------------------#
  800. if [ "$nginx" = 'yes' ]; then
  801. rm -f /etc/nginx/conf.d/*.conf
  802. cp -f $hestiacp/nginx/nginx.conf /etc/nginx/
  803. cp -f $hestiacp/nginx/status.conf /etc/nginx/conf.d/
  804. cp -f $hestiacp/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  805. cp -f $hestiacp/nginx/phppgadmin.inc /etc/nginx/conf.d/
  806. cp -f $hestiacp/nginx/webmail.inc /etc/nginx/conf.d/
  807. cp -f $hestiacp/logrotate/nginx /etc/logrotate.d/
  808. echo > /etc/nginx/conf.d/hestia.conf
  809. mkdir -p /var/log/nginx/domains
  810. if [ "$apache" = 'no' ] && [ "$multiphp" = 'yes' ]; then
  811. update-rc.d php5.6-fpm defaults > /dev/null 2>&1
  812. update-rc.d php7.0-fpm defaults > /dev/null 2>&1
  813. update-rc.d php7.1-fpm defaults > /dev/null 2>&1
  814. update-rc.d php7.2-fpm defaults > /dev/null 2>&1
  815. update-rc.d php7.3-fpm defaults > /dev/null 2>&1
  816. cp -r /etc/php/5.6/ /root/hst_install_backups/php5.6/
  817. rm -f /etc/php/5.6/fpm/pool.d/*
  818. cp -r /etc/php/7.0/ /root/hst_install_backups/php7.0/
  819. rm -f /etc/php/7.0/fpm/pool.d/*
  820. cp -r /etc/php/7.1/ /root/hst_install_backups/php7.1/
  821. rm -f /etc/php/7.1/fpm/pool.d/*
  822. cp -r /etc/php/7.2/ /root/hst_install_backups/php7.2/
  823. rm -f /etc/php/7.2/fpm/pool.d/*
  824. cp -r /etc/php/7.3/ /root/hst_install_backups/php7.3/
  825. rm -f /etc/php/7.3/fpm/pool.d/*
  826. rm -fr $HESTIA/data/templates/web/nginx/*
  827. cp -f $hestiacp/multiphp/nginx/* $HESTIA/data/templates/web/nginx/
  828. cp -f $hestiacp/php-fpm/www.conf /etc/php/7.2/fpm/pool.d/
  829. ln -s $HESTIA/data/templates/web/nginx/PHP-72.sh $HESTIA/data/templates/web/nginx/default.sh
  830. ln -s $HESTIA/data/templates/web/nginx/PHP-72.tpl $HESTIA/data/templates/web/nginx/default.tpl
  831. ln -s $HESTIA/data/templates/web/nginx/PHP-72.stpl $HESTIA/data/templates/web/nginx/default.stpl
  832. chmod a+x $HESTIA/data/templates/web/nginx/*.sh
  833. service php7.2-fpm start >> $LOG
  834. check_result $? "php7.2-fpm start failed"
  835. fi
  836. update-rc.d nginx defaults > /dev/null 2>&1
  837. service nginx start >> $LOG
  838. check_result $? "nginx start failed"
  839. fi
  840. #----------------------------------------------------------#
  841. # Configure Apache #
  842. #----------------------------------------------------------#
  843. if [ "$apache" = 'yes' ]; then
  844. cp -f $hestiacp/apache2/apache2.conf /etc/apache2/
  845. cp -f $hestiacp/apache2/status.conf /etc/apache2/mods-enabled/
  846. cp -f $hestiacp/logrotate/apache2 /etc/logrotate.d/
  847. a2enmod rewrite > /dev/null 2>&1
  848. a2enmod suexec > /dev/null 2>&1
  849. a2enmod ssl > /dev/null 2>&1
  850. a2enmod actions > /dev/null 2>&1
  851. a2enmod ruid2 > /dev/null 2>&1
  852. mkdir -p /etc/apache2/conf.d
  853. echo > /etc/apache2/conf.d/hestia.conf
  854. echo "# Powered by hestia" > /etc/apache2/sites-available/default
  855. echo "# Powered by hestia" > /etc/apache2/sites-available/default-ssl
  856. echo "# Powered by hestia" > /etc/apache2/ports.conf
  857. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  858. touch /var/log/apache2/access.log /var/log/apache2/error.log
  859. mkdir -p /var/log/apache2/domains
  860. chmod a+x /var/log/apache2
  861. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  862. chmod 751 /var/log/apache2/domains
  863. if [ "$multiphp" = 'yes' ] ; then
  864. a2enmod proxy_fcgi setenvif > /dev/null 2>&1
  865. a2enconf php5.6-fpm > /dev/null 2>&1
  866. a2enconf php7.0-fpm > /dev/null 2>&1
  867. a2enconf php7.1-fpm > /dev/null 2>&1
  868. a2enconf php7.2-fpm > /dev/null 2>&1
  869. a2enconf php7.3-fpm > /dev/null 2>&1
  870. update-rc.d php5.6-fpm defaults > /dev/null 2>&1
  871. update-rc.d php7.0-fpm defaults > /dev/null 2>&1
  872. update-rc.d php7.1-fpm defaults > /dev/null 2>&1
  873. update-rc.d php7.2-fpm defaults > /dev/null 2>&1
  874. update-rc.d php7.3-fpm defaults > /dev/null 2>&1
  875. cp -r /etc/php/5.6/ /root/hst_install_backups/php5.6/
  876. rm -f /etc/php/5.6/fpm/pool.d/*
  877. cp -r /etc/php/7.0/ /root/hst_install_backups/php7.0/
  878. rm -f /etc/php/7.0/fpm/pool.d/*
  879. cp -r /etc/php/7.1/ /root/hst_install_backups/php7.1/
  880. rm -f /etc/php/7.1/fpm/pool.d/*
  881. cp -r /etc/php/7.2/ /root/hst_install_backups/php7.2/
  882. rm -f /etc/php/7.2/fpm/pool.d/*
  883. cp -r /etc/php/7.3/ /root/hst_install_backups/php7.3/
  884. rm -f /etc/php/7.3/fpm/pool.d/*
  885. cp -f $hestiacp/multiphp/apache2/* $HESTIA/data/templates/web/apache2/
  886. chmod a+x $HESTIA/data/templates/web/apache2/*.sh
  887. if [ "$release" = '8' ]; then
  888. sed -i 's/#//g' $HESTIA/data/templates/web/apache2/*.tpl
  889. sed -i 's/#//g' $HESTIA/data/templates/web/apache2/*.stpl
  890. fi
  891. fi
  892. update-rc.d apache2 defaults > /dev/null 2>&1
  893. service apache2 start >> $LOG
  894. check_result $? "apache2 start failed"
  895. else
  896. update-rc.d apache2 disable >/dev/null 2>&1
  897. service apache2 stop >/dev/null 2>&1
  898. fi
  899. #----------------------------------------------------------#
  900. # Configure PHP-FPM #
  901. #----------------------------------------------------------#
  902. if [ "$phpfpm" = 'yes' ]; then
  903. cp -f $hestiacp/php-fpm/www.conf /etc/php/7.2/fpm/pool.d/www.conf
  904. update-rc.d php7.2-fpm defaults > /dev/null 2>&1
  905. service php7.2-fpm start >> $LOG
  906. check_result $? "php-fpm start failed"
  907. fi
  908. #----------------------------------------------------------#
  909. # Configure PHP #
  910. #----------------------------------------------------------#
  911. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  912. if [ -z "$ZONE" ]; then
  913. ZONE='UTC'
  914. fi
  915. for pconf in $(find /etc/php* -name php.ini); do
  916. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  917. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  918. done
  919. #----------------------------------------------------------#
  920. # Configure VSFTPD #
  921. #----------------------------------------------------------#
  922. if [ "$vsftpd" = 'yes' ]; then
  923. cp -f $hestiacp/vsftpd/vsftpd.conf /etc/
  924. update-rc.d vsftpd defaults
  925. service vsftpd start
  926. check_result $? "vsftpd start failed"
  927. # To be deleted after release 0.9.8-18
  928. echo "/sbin/nologin" >> /etc/shells
  929. fi
  930. #----------------------------------------------------------#
  931. # Configure ProFTPD #
  932. #----------------------------------------------------------#
  933. if [ "$proftpd" = 'yes' ]; then
  934. echo "127.0.0.1 $servername" >> /etc/hosts
  935. cp -f $hestiacp/proftpd/proftpd.conf /etc/proftpd/
  936. update-rc.d proftpd defaults
  937. service proftpd start
  938. check_result $? "proftpd start failed"
  939. fi
  940. #----------------------------------------------------------#
  941. # Configure MariaDB #
  942. #----------------------------------------------------------#
  943. if [ "$mysql" = 'yes' ]; then
  944. mycnf="my-small.cnf"
  945. if [ $memory -gt 1200000 ]; then
  946. mycnf="my-medium.cnf"
  947. fi
  948. if [ $memory -gt 3900000 ]; then
  949. mycnf="my-large.cnf"
  950. fi
  951. # Configuring MariaDB
  952. cp -f $hestiacp/mysql/$mycnf /etc/mysql/my.cnf
  953. mysql_install_db >> $LOG
  954. update-rc.d mysql defaults
  955. service mysql start
  956. check_result $? "mariadb start failed"
  957. # Securing MariaDB installation
  958. mpass=$(gen_pass)
  959. mysqladmin -u root password $mpass >> $LOG
  960. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  961. chmod 600 /root/.my.cnf
  962. # Clear MariaDB Test Users and Databases
  963. mysql -e "DELETE FROM mysql.user WHERE User=''"
  964. mysql -e "DROP DATABASE test" > /dev/null 2>&1
  965. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  966. mysql -e "DELETE FROM mysql.user WHERE user='';"
  967. mysql -e "DELETE FROM mysql.user WHERE password='' AND authentication_string='';"
  968. # Configuring phpMyAdmin
  969. if [ "$apache" = 'yes' ]; then
  970. cp -f $hestiacp/pma/apache.conf /etc/phpmyadmin/
  971. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  972. fi
  973. cp -f $hestiacp/pma/config.inc.php /etc/phpmyadmin/
  974. chmod 777 /var/lib/phpmyadmin/tmp
  975. fi
  976. #----------------------------------------------------------#
  977. # Update phpMyAdmin #
  978. #----------------------------------------------------------#
  979. # Display upgrade information
  980. echo "Upgrade phpMyAdmin to v$pma_v..."
  981. # Download latest phpmyadmin release
  982. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  983. # Unpack files
  984. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  985. # Delete file to prevent error
  986. if [ "$pma_v" = '4.8.3' ]; then
  987. rm -fr /usr/share/phpmyadmin/doc/html
  988. fi
  989. # Overwrite old files
  990. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  991. # Set config and log directory
  992. sed -i "s|define('CONFIG_DIR', '');|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  993. sed -i "s|define('TEMP_DIR', './tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  994. # Create temporary folder and change permission
  995. mkdir /usr/share/phpmyadmin/tmp
  996. chmod 777 /usr/share/phpmyadmin/tmp
  997. # Clear Up
  998. rm -fr phpMyAdmin-$pma_v-all-languages
  999. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  1000. #----------------------------------------------------------#
  1001. # Configure PostgreSQL #
  1002. #----------------------------------------------------------#
  1003. if [ "$postgresql" = 'yes' ]; then
  1004. ppass=$(gen_pass)
  1005. cp -f $hestiacp/postgresql/pg_hba.conf /etc/postgresql/*/main/
  1006. service postgresql restart
  1007. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  1008. # Configuring phpPgAdmin
  1009. if [ "$apache" = 'yes' ]; then
  1010. cp -f $hestiacp/pga/phppgadmin.conf /etc/apache2/conf.d/
  1011. fi
  1012. cp -f $hestiacp/pga/config.inc.php /etc/phppgadmin/
  1013. fi
  1014. #----------------------------------------------------------#
  1015. # Configure Bind #
  1016. #----------------------------------------------------------#
  1017. if [ "$named" = 'yes' ]; then
  1018. cp -f $hestiacp/bind/named.conf /etc/bind/
  1019. cp -f $hestiacp/bind/named.conf.options /etc/bind/
  1020. chown root:bind /etc/bind/named.conf
  1021. chown root:bind /etc/bind/named.conf.options
  1022. chmod 640 /etc/bind/named.conf
  1023. chmod 640 /etc/bind/named.conf.options
  1024. aa-complain /usr/sbin/named 2>/dev/null
  1025. if [ "$apparmor" = 'yes' ]; then
  1026. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2>/dev/null
  1027. service apparmor status >/dev/null 2>&1
  1028. if [ $? -ne 0 ]; then
  1029. service apparmor restart
  1030. fi
  1031. fi
  1032. update-rc.d bind9 defaults
  1033. service bind9 start
  1034. check_result $? "bind9 start failed"
  1035. # Workaround for OpenVZ/Virtuozzo
  1036. if [ -e "/proc/vz/veinfo" ]; then
  1037. sed -i "s/^exit 0/service bind9 restart\nexit 0/" /etc/rc.local
  1038. fi
  1039. fi
  1040. #----------------------------------------------------------#
  1041. # Configure Exim #
  1042. #----------------------------------------------------------#
  1043. if [ "$exim" = 'yes' ]; then
  1044. gpasswd -a Debian-exim mail > /dev/null 2>&1
  1045. cp -f $hestiacp/exim/exim4.conf.template /etc/exim4/
  1046. cp -f $hestiacp/exim/dnsbl.conf /etc/exim4/
  1047. cp -f $hestiacp/exim/spam-blocks.conf /etc/exim4/
  1048. touch /etc/exim4/white-blocks.conf
  1049. if [ "$spamd" = 'yes' ]; then
  1050. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  1051. fi
  1052. if [ "$clamd" = 'yes' ]; then
  1053. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  1054. fi
  1055. chmod 640 /etc/exim4/exim4.conf.template
  1056. rm -rf /etc/exim4/domains
  1057. mkdir -p /etc/exim4/domains
  1058. rm -f /etc/alternatives/mta
  1059. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  1060. update-rc.d -f sendmail remove > /dev/null 2>&1
  1061. service sendmail stop >> $LOG
  1062. update-rc.d -f postfix remove > /dev/null 2>&1
  1063. service postfix stop >> $LOG
  1064. update-rc.d exim4 defaults
  1065. service exim4 start
  1066. check_result $? "exim4 start failed"
  1067. fi
  1068. #----------------------------------------------------------#
  1069. # Configure Dovecot #
  1070. #----------------------------------------------------------#
  1071. if [ "$dovecot" = 'yes' ]; then
  1072. gpasswd -a dovecot mail > /dev/null 2>&1
  1073. cp -rf $hestiacp/dovecot /etc/
  1074. cp -f $hestiacp/logrotate/dovecot /etc/logrotate.d/
  1075. chown -R root:root /etc/dovecot*
  1076. if [ "$release" -eq 9 ]; then
  1077. sed -i "s#namespace inbox {#namespace inbox {\n inbox = yes#" /etc/dovecot/conf.d/15-mailboxes.conf
  1078. fi
  1079. update-rc.d dovecot defaults
  1080. service dovecot start
  1081. check_result $? "dovecot start failed"
  1082. fi
  1083. #----------------------------------------------------------#
  1084. # Configure ClamAV #
  1085. #----------------------------------------------------------#
  1086. if [ "$clamd" = 'yes' ]; then
  1087. gpasswd -a clamav mail > /dev/null 2>&1
  1088. gpasswd -a clamav Debian-exim > /dev/null 2>&1
  1089. cp -f $hestiacp/clamav/clamd.conf /etc/clamav/
  1090. update-rc.d clamav-daemon defaults
  1091. if [ ! -d "/var/run/clamav" ]; then
  1092. mkdir /var/run/clamav
  1093. fi
  1094. chown -R clamav:clamav /var/run/clamav
  1095. if [ -e "/lib/systemd/system/clamav-daemon.service" ]; then
  1096. exec_pre1='ExecStartPre=-/bin/mkdir -p /var/run/clamav'
  1097. exec_pre2='ExecStartPre=-/bin/chown -R clamav:clamav /var/run/clamav'
  1098. sed -i "s|\[Service\]/|[Service]\n$exec_pre1\n$exec_pre2|g" \
  1099. /lib/systemd/system/clamav-daemon.service
  1100. systemctl daemon-reload
  1101. fi
  1102. echo "Updating ClamAV..."
  1103. /usr/bin/freshclam >> $LOG
  1104. service clamav-daemon start
  1105. check_result $? "clamav-daemon start failed"
  1106. fi
  1107. #----------------------------------------------------------#
  1108. # Configure SpamAssassin #
  1109. #----------------------------------------------------------#
  1110. if [ "$spamd" = 'yes' ]; then
  1111. update-rc.d spamassassin defaults > /dev/null 2>&1
  1112. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  1113. service spamassassin start >> $LOG
  1114. check_result $? "spamassassin start failed"
  1115. unit_files="$(systemctl list-unit-files |grep spamassassin)"
  1116. if [[ "$unit_files" =~ "disabled" ]]; then
  1117. systemctl enable spamassassin > /dev/null 2>&1
  1118. fi
  1119. fi
  1120. #----------------------------------------------------------#
  1121. # Configure Roundcube #
  1122. #----------------------------------------------------------#
  1123. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1124. if [ "$apache" = 'yes' ]; then
  1125. cp -f $hestiacp/roundcube/apache.conf /etc/roundcube/
  1126. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  1127. fi
  1128. cp -f $hestiacp/roundcube/main.inc.php /etc/roundcube/
  1129. cp -f $hestiacp/roundcube/db.inc.php /etc/roundcube/
  1130. chmod 640 /etc/roundcube/debian-db-roundcube.php
  1131. chmod 640 /etc/roundcube/config.inc.php
  1132. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1133. chown root:www-data /etc/roundcube/config.inc.php
  1134. cp -f $hestiacp/roundcube/hestia.php \
  1135. /usr/share/roundcube/plugins/password/drivers/
  1136. cp -f $hestiacp/roundcube/config.inc.php /etc/roundcube/plugins/password/
  1137. r="$(gen_pass)"
  1138. mysql -e "CREATE DATABASE roundcube"
  1139. mysql -e "GRANT ALL ON roundcube.*
  1140. TO roundcube@localhost IDENTIFIED BY '$r'"
  1141. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  1142. sed -i "s/localhost/$servername/g" \
  1143. /etc/roundcube/plugins/password/config.inc.php
  1144. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  1145. chmod a+r /etc/roundcube/main.inc.php
  1146. # Send all emails through SMTP and add user information
  1147. sed -i "/\$config\['smtp_server'\]/c\$config\['smtp_server'\] = 'localhost';" /etc/roundcube/defaults.inc.php
  1148. sed -i "/\$config\['smtp_user'\]/c\$config\['smtp_user'\] = '%u';" /etc/roundcube/defaults.inc.php
  1149. sed -i "/\$config\['smtp_pass'\]/c\$config\['smtp_pass'\] = '%p';" /etc/roundcube/defaults.inc.php
  1150. if [ "$release" -eq 8 ] || [ "$release" -eq 9 ]; then
  1151. mv -f /etc/roundcube/main.inc.php /etc/roundcube/config.inc.php
  1152. mv -f /etc/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  1153. chmod 640 /etc/roundcube/debian-db-roundcube.php
  1154. chmod 640 /etc/roundcube/config.inc.php
  1155. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1156. chown root:www-data /etc/roundcube/config.inc.php
  1157. fi
  1158. if [ "$release" -eq 8 ]; then
  1159. # RoundCube tinyMCE fix
  1160. tinymceFixArchiveURL=$hestiacp/roundcube/roundcube-tinymce.tar.gz
  1161. tinymceParentFolder=/usr/share/roundcube/program/js
  1162. tinymceFolder=$tinymceParentFolder/tinymce
  1163. tinymceBadJS=$tinymceFolder/tiny_mce.js
  1164. tinymceFixArchive=$tinymceParentFolder/roundcube-tinymce.tar.gz
  1165. if [[ -L "$tinymceFolder" && -d "$tinymceFolder" ]]; then
  1166. if [ -f "$tinymceBadJS" ]; then
  1167. wget $tinymceFixArchiveURL -O $tinymceFixArchive
  1168. if [[ -f "$tinymceFixArchive" && -s "$tinymceFixArchive" ]]
  1169. then
  1170. rm $tinymceFolder
  1171. tar -xzf $tinymceFixArchive -C $tinymceParentFolder
  1172. rm $tinymceFixArchive
  1173. chown -R root:root $tinymceFolder
  1174. else
  1175. echo -n "File roundcube-tinymce.tar.gz is not downloaded,"
  1176. echo "RoundCube tinyMCE fix is not applied"
  1177. rm $tinymceFixArchive
  1178. fi
  1179. fi
  1180. fi
  1181. fi
  1182. fi
  1183. #----------------------------------------------------------#
  1184. # Configure Fail2Ban #
  1185. #----------------------------------------------------------#
  1186. if [ "$fail2ban" = 'yes' ]; then
  1187. cp -rf $hestiacp/fail2ban /etc/
  1188. if [ "$dovecot" = 'no' ]; then
  1189. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1190. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1191. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1192. fi
  1193. if [ "$exim" = 'no' ]; then
  1194. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1195. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1196. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1197. fi
  1198. if [ "$vsftpd" = 'yes' ]; then
  1199. #Create vsftpd Log File
  1200. if [ ! -f "/var/log/vsftpd.log" ]; then
  1201. touch /var/log/vsftpd.log
  1202. fi
  1203. fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1204. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1205. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1206. fi
  1207. update-rc.d fail2ban defaults
  1208. service fail2ban start
  1209. check_result $? "fail2ban start failed"
  1210. fi
  1211. #----------------------------------------------------------#
  1212. # Configure API #
  1213. #----------------------------------------------------------#
  1214. if [ "$api" = 'yes' ]; then
  1215. echo "API='yes'" >> $HESTIA/conf/hestia.conf
  1216. else
  1217. rm -r $HESTIA/web/api
  1218. echo "API='no'" >> $HESTIA/conf/hestia.conf
  1219. fi
  1220. #----------------------------------------------------------#
  1221. # Fix phpmyadmin #
  1222. #----------------------------------------------------------#
  1223. # Special thanks to Pavel Galkin (https://skurudo.ru)
  1224. # https://github.com/skurudo/phpmyadmin-fixer
  1225. source $hestiacp/phpmyadmin/pma.sh >> $LOG
  1226. #----------------------------------------------------------#
  1227. # Configure Admin User #
  1228. #----------------------------------------------------------#
  1229. # Deleting old admin user
  1230. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1231. chattr -i /home/admin/conf > /dev/null 2>&1
  1232. userdel -f admin > /dev/null 2>&1
  1233. chattr -i /home/admin/conf > /dev/null 2>&1
  1234. mv -f /home/admin $hst_backups/home/ > /dev/null 2>&1
  1235. rm -f /tmp/sess_* > /dev/null 2>&1
  1236. fi
  1237. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  1238. groupdel admin > /dev/null 2>&1
  1239. fi
  1240. # Adding Hestia admin account
  1241. $HESTIA/bin/v-add-user admin $vpass $email default System Administrator
  1242. check_result $? "can't create admin user"
  1243. $HESTIA/bin/v-change-user-shell admin nologin
  1244. $HESTIA/bin/v-change-user-language admin $lang
  1245. # RoundCube permissions fix
  1246. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1247. if [ ! -d "/var/log/roundcube" ]; then
  1248. mkdir /var/log/roundcube
  1249. fi
  1250. chown admin:admin /var/log/roundcube
  1251. fi
  1252. # Configuring system ips
  1253. $HESTIA/bin/v-update-sys-ip > /dev/null 2>&1
  1254. # Get main ip
  1255. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1256. local_ip=$ip
  1257. # Firewall configuration
  1258. if [ "$iptables" = 'yes' ]; then
  1259. $HESTIA/bin/v-update-firewall
  1260. fi
  1261. # Get public ip
  1262. pub_ip=$(curl --ipv4 -s https://www.hestiacp.com/what-is-my-ip/)
  1263. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1264. $HESTIA/bin/v-change-sys-ip-nat $ip $pub_ip > /dev/null 2>&1
  1265. ip=$pub_ip
  1266. fi
  1267. # Configuring libapache2-mod-remoteip
  1268. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  1269. cd /etc/apache2/mods-available
  1270. echo "<IfModule mod_remoteip.c>" > remoteip.conf
  1271. echo " RemoteIPHeader X-Real-IP" >> remoteip.conf
  1272. if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ip" != "127.0.0.1" ]; then
  1273. echo " RemoteIPInternalProxy 127.0.0.1" >> remoteip.conf
  1274. fi
  1275. if [ ! -z "$local_ip" ] && [ "$local_ip" != "$pub_ip" ]; then
  1276. echo " RemoteIPInternalProxy $local_ip" >> remoteip.conf
  1277. fi
  1278. if [ ! -z "$pub_ip" ]; then
  1279. echo " RemoteIPInternalProxy $pub_ip" >> remoteip.conf
  1280. fi
  1281. echo "</IfModule>" >> remoteip.conf
  1282. sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  1283. a2enmod remoteip >> $LOG
  1284. service apache2 restart
  1285. fi
  1286. # Configuring MariaDB host
  1287. if [ "$mysql" = 'yes' ]; then
  1288. $HESTIA/bin/v-add-database-host mysql localhost root $mpass
  1289. fi
  1290. # Configuring PostgreSQL host
  1291. if [ "$postgresql" = 'yes' ]; then
  1292. $HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
  1293. fi
  1294. # Adding default domain
  1295. $HESTIA/bin/v-add-web-domain admin $servername
  1296. check_result $? "can't create $servername domain"
  1297. # Adding cron jobs
  1298. command="sudo $HESTIA/bin/v-update-sys-queue disk"
  1299. $HESTIA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1300. command="sudo $HESTIA/bin/v-update-sys-queue traffic"
  1301. $HESTIA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1302. command="sudo $HESTIA/bin/v-update-sys-queue webstats"
  1303. $HESTIA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1304. command="sudo $HESTIA/bin/v-update-sys-queue backup"
  1305. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1306. command="sudo $HESTIA/bin/v-backup-users"
  1307. $HESTIA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1308. command="sudo $HESTIA/bin/v-update-user-stats"
  1309. $HESTIA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1310. command="sudo $HESTIA/bin/v-update-sys-rrd"
  1311. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1312. service cron restart
  1313. # Building initital rrd images
  1314. $HESTIA/bin/v-update-sys-rrd
  1315. # Enabling file system quota
  1316. if [ "$quota" = 'yes' ]; then
  1317. $HESTIA/bin/v-add-sys-quota
  1318. fi
  1319. # Set backend port
  1320. $HESTIA/bin/v-change-sys-port $port
  1321. # Starting Hestia service
  1322. update-rc.d hestia defaults
  1323. service hestia start
  1324. check_result $? "hestia start failed"
  1325. chown admin:admin $HESTIA/data/sessions
  1326. # Adding cronjob for autoupdates
  1327. $HESTIA/bin/v-add-cron-hestia-autoupdate
  1328. #----------------------------------------------------------#
  1329. # Hestia Access Info #
  1330. #----------------------------------------------------------#
  1331. # Comparing hostname and IP
  1332. host_ip=$(host $servername| head -n 1 |awk '{print $NF}')
  1333. if [ "$host_ip" = "$ip" ]; then
  1334. ip="$servername"
  1335. fi
  1336. # Sending notification to admin email
  1337. echo -e "Congratulations, you have just successfully installed \
  1338. Hestia Control Panel
  1339. https://$ip:$port
  1340. username: admin
  1341. password: $vpass
  1342. We hope that you enjoy your installation of Hestia. Please \
  1343. feel free to contact us anytime if you have any questions.
  1344. Thank you.
  1345. --
  1346. Sincerely yours
  1347. hestiacp.com team
  1348. " > $tmpfile
  1349. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  1350. cat $tmpfile | $send_mail -s "Hestia Control Panel" $email
  1351. # Congrats
  1352. echo
  1353. cat $tmpfile
  1354. rm -f $tmpfile
  1355. # EOF