hst-install-debian.sh 63 KB

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