1
0

hst-install-debian.sh 65 KB

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