hst-install-debian.sh 66 KB

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