hst-install-debian.sh 63 KB

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