hst-install-debian.sh 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864
  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.0.4'
  25. rc_v="1.4.10"
  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"
  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"
  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 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. # 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/data/queue/daily.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 [ "$postgresql" = 'yes' ]; then
  891. installed_db_types="$installed_db_types,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. else
  938. echo "DISK_QUOTA='no'" >> $HESTIA/conf/hestia.conf
  939. fi
  940. # Backups
  941. echo "BACKUP_SYSTEM='local'" >> $HESTIA/conf/hestia.conf
  942. echo "BACKUP_GZIP='4'" >> $HESTIA/conf/hestia.conf
  943. echo "BACKUP_MODE='zstd'" >> $HESTIA/conf/hestia.conf
  944. # Language
  945. echo "LANGUAGE='$lang'" >> $HESTIA/conf/hestia.conf
  946. # Login in screen
  947. echo "LOGIN_STYLE='default'" >> $HESTIA/conf/hestia.conf
  948. # Inactive session timeout
  949. echo "INACTIVE_SESSION_TIMEOUT='60'" >> $HESTIA/conf/hestia.conf
  950. # Version & Release Branch
  951. echo "VERSION='${HESTIA_INSTALL_VER}'" >> $HESTIA/conf/hestia.conf
  952. echo "RELEASE_BRANCH='release'" >> $HESTIA/conf/hestia.conf
  953. # Email notifications after upgrade
  954. echo "UPGRADE_SEND_EMAIL='true'" >> $HESTIA/conf/hestia.conf
  955. echo "UPGRADE_SEND_EMAIL_LOG='true'" >> $HESTIA/conf/hestia.conf
  956. # Installing hosting packages
  957. cp -rf $HESTIA_INSTALL_DIR/packages $HESTIA/data/
  958. # Update nameservers in hosting package
  959. IFS='.' read -r -a domain_elements <<< "$servername"
  960. if [ ! -z "${domain_elements[-2]}" ] && [ ! -z "${domain_elements[-1]}" ]; then
  961. serverdomain="${domain_elements[-2]}.${domain_elements[-1]}"
  962. sed -i s/"domain.tld"/"$serverdomain"/g $HESTIA/data/packages/*.pkg
  963. fi
  964. # Installing templates
  965. cp -rf $HESTIA_INSTALL_DIR/templates $HESTIA/data/
  966. mkdir -p /var/www/html
  967. mkdir -p /var/www/document_errors
  968. # Install default success page
  969. cp -rf $HESTIA_INSTALL_DIR/templates/web/unassigned/index.html /var/www/html/
  970. cp -rf $HESTIA_INSTALL_DIR/templates/web/skel/document_errors/* /var/www/document_errors/
  971. # Installing firewall rules
  972. cp -rf $HESTIA_INSTALL_DIR/firewall $HESTIA/data/
  973. # Configuring server hostname
  974. $HESTIA/bin/v-change-sys-hostname $servername > /dev/null 2>&1
  975. # Generating SSL certificate
  976. echo "[ * ] Generating default self-signed SSL certificate..."
  977. $HESTIA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  978. 'San Francisco' 'Hestia Control Panel' 'IT' > /tmp/hst.pem
  979. # Parsing certificate file
  980. crt_end=$(grep -n "END CERTIFICATE-" /tmp/hst.pem |cut -f 1 -d:)
  981. key_start=$(grep -n "BEGIN RSA" /tmp/hst.pem |cut -f 1 -d:)
  982. key_end=$(grep -n "END RSA" /tmp/hst.pem |cut -f 1 -d:)
  983. # Adding SSL certificate
  984. echo "[ * ] Adding SSL certificate to Hestia Control Panel..."
  985. cd $HESTIA/ssl
  986. sed -n "1,${crt_end}p" /tmp/hst.pem > certificate.crt
  987. sed -n "$key_start,${key_end}p" /tmp/hst.pem > certificate.key
  988. chown root:mail $HESTIA/ssl/*
  989. chmod 660 $HESTIA/ssl/*
  990. rm /tmp/hst.pem
  991. # Install dhparam.pem
  992. cp -f $HESTIA_INSTALL_DIR/ssl/dhparam.pem /etc/ssl
  993. #----------------------------------------------------------#
  994. # Configure Nginx #
  995. #----------------------------------------------------------#
  996. if [ "$nginx" = 'yes' ]; then
  997. echo "[ * ] Configuring NGINX..."
  998. rm -f /etc/nginx/conf.d/*.conf
  999. cp -f $HESTIA_INSTALL_DIR/nginx/nginx.conf /etc/nginx/
  1000. cp -f $HESTIA_INSTALL_DIR/nginx/status.conf /etc/nginx/conf.d/
  1001. cp -f $HESTIA_INSTALL_DIR/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  1002. cp -f $HESTIA_INSTALL_DIR/nginx/phppgadmin.inc /etc/nginx/conf.d/
  1003. cp -f $HESTIA_INSTALL_DIR/logrotate/nginx /etc/logrotate.d/
  1004. mkdir -p /etc/nginx/conf.d/domains
  1005. mkdir -p /etc/nginx/modules-enabled
  1006. mkdir -p /var/log/nginx/domains
  1007. # Update dns servers in nginx.conf
  1008. dns_resolver=$(cat /etc/resolv.conf | grep -i '^nameserver' | cut -d ' ' -f2 | tr '\r\n' ' ' | xargs)
  1009. for ip in $dns_resolver; do
  1010. if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  1011. resolver="$ip $resolver"
  1012. fi
  1013. done
  1014. if [ ! -z "$resolver" ]; then
  1015. sed -i "s/1.0.0.1 1.1.1.1/$resolver/g" /etc/nginx/nginx.conf
  1016. sed -i "s/1.0.0.1 1.1.1.1/$resolver/g" /usr/local/hestia/nginx/conf/nginx.conf
  1017. fi
  1018. update-rc.d nginx defaults > /dev/null 2>&1
  1019. systemctl start nginx >> $LOG
  1020. check_result $? "nginx start failed"
  1021. fi
  1022. #----------------------------------------------------------#
  1023. # Configure Apache #
  1024. #----------------------------------------------------------#
  1025. if [ "$apache" = 'yes' ]; then
  1026. echo "[ * ] Configuring Apache Web Server..."
  1027. mkdir -p /etc/apache2/conf.d
  1028. mkdir -p /etc/apache2/conf.d/domains
  1029. # Copy configuration files
  1030. cp -f $HESTIA_INSTALL_DIR/apache2/apache2.conf /etc/apache2/
  1031. cp -f $HESTIA_INSTALL_DIR/apache2/status.conf /etc/apache2/mods-available/hestia-status.conf
  1032. cp -f /etc/apache2/mods-available/status.load /etc/apache2/mods-available/hestia-status.load
  1033. cp -f $HESTIA_INSTALL_DIR/logrotate/apache2 /etc/logrotate.d/
  1034. # Enable needed modules
  1035. a2enmod rewrite > /dev/null 2>&1
  1036. a2enmod suexec > /dev/null 2>&1
  1037. a2enmod ssl > /dev/null 2>&1
  1038. a2enmod actions > /dev/null 2>&1
  1039. a2dismod --quiet status > /dev/null 2>&1
  1040. a2enmod --quiet hestia-status > /dev/null 2>&1
  1041. if [ "$phpfpm" = 'yes' ]; then
  1042. # Disable prefork and php, enable event
  1043. a2dismod php$fpm_v > /dev/null 2>&1
  1044. a2dismod mpm_prefork > /dev/null 2>&1
  1045. a2enmod mpm_event > /dev/null 2>&1
  1046. cp -f $HESTIA_INSTALL_DIR/apache2/hestia-event.conf /etc/apache2/conf.d/
  1047. else
  1048. if [ "$release" -eq 10 ]; then
  1049. a2enmod mpm_itk > /dev/null 2>&1
  1050. else
  1051. a2enmod ruid2 > /dev/null 2>&1
  1052. fi
  1053. fi
  1054. echo "# Powered by hestia" > /etc/apache2/sites-available/default
  1055. echo "# Powered by hestia" > /etc/apache2/sites-available/default-ssl
  1056. echo "# Powered by hestia" > /etc/apache2/ports.conf
  1057. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  1058. touch /var/log/apache2/access.log /var/log/apache2/error.log
  1059. mkdir -p /var/log/apache2/domains
  1060. chmod a+x /var/log/apache2
  1061. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  1062. chmod 751 /var/log/apache2/domains
  1063. # Prevent remote access to server-status page
  1064. sed -i '/Allow from all/d' /etc/apache2/mods-available/hestia-status.conf
  1065. update-rc.d apache2 defaults > /dev/null 2>&1
  1066. systemctl start apache2 >> $LOG
  1067. check_result $? "apache2 start failed"
  1068. else
  1069. update-rc.d apache2 disable > /dev/null 2>&1
  1070. systemctl stop apache2 > /dev/null 2>&1
  1071. fi
  1072. #----------------------------------------------------------#
  1073. # Configure PHP-FPM #
  1074. #----------------------------------------------------------#
  1075. if [ "$multiphp" = 'yes' ] ; then
  1076. for v in "${multiphp_v[@]}"; do
  1077. rm -f /etc/php/$v/fpm/pool.d/*
  1078. echo "[ * ] Install PHP version $v..."
  1079. $HESTIA/bin/v-add-web-php "$v" > /dev/null 2>&1
  1080. done
  1081. fi
  1082. if [ "$phpfpm" = 'yes' ]; then
  1083. echo "[ * ] Configuring PHP-FPM..."
  1084. $HESTIA/bin/v-add-web-php "$fpm_v" > /dev/null 2>&1
  1085. cp -f $HESTIA_INSTALL_DIR/php-fpm/www.conf /etc/php/$fpm_v/fpm/pool.d/www.conf
  1086. update-rc.d php$fpm_v-fpm defaults > /dev/null 2>&1
  1087. systemctl start php$fpm_v-fpm >> $LOG
  1088. check_result $? "php-fpm start failed"
  1089. update-alternatives --set php /usr/bin/php$fpm_v > /dev/null 2>&1
  1090. fi
  1091. #----------------------------------------------------------#
  1092. # Configure PHP #
  1093. #----------------------------------------------------------#
  1094. echo "[ * ] Configuring PHP..."
  1095. ZONE=$(timedatectl > /dev/null 2>&1|grep Timezone|awk '{print $2}')
  1096. if [ -z "$ZONE" ]; then
  1097. ZONE='UTC'
  1098. fi
  1099. for pconf in $(find /etc/php* -name php.ini); do
  1100. sed -i "s/;date.timezone =/date.timezone = $ZONE/g" $pconf
  1101. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  1102. done
  1103. # Cleanup php session files not changed in the last 7 days (60*24*7 minutes)
  1104. echo '#!/bin/sh' > /etc/cron.daily/php-session-cleanup
  1105. 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
  1106. 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
  1107. chmod 755 /etc/cron.daily/php-session-cleanup
  1108. #----------------------------------------------------------#
  1109. # Configure Vsftpd #
  1110. #----------------------------------------------------------#
  1111. if [ "$vsftpd" = 'yes' ]; then
  1112. echo "[ * ] Configuring Vsftpd server..."
  1113. cp -f $HESTIA_INSTALL_DIR/vsftpd/vsftpd.conf /etc/
  1114. touch /var/log/vsftpd.log
  1115. chown root:adm /var/log/vsftpd.log
  1116. chmod 640 /var/log/vsftpd.log
  1117. touch /var/log/xferlog
  1118. chown root:adm /var/log/xferlog
  1119. chmod 640 /var/log/xferlog
  1120. update-rc.d vsftpd defaults
  1121. systemctl start vsftpd
  1122. check_result $? "vsftpd start failed"
  1123. fi
  1124. #----------------------------------------------------------#
  1125. # Configure ProFTPD #
  1126. #----------------------------------------------------------#
  1127. if [ "$proftpd" = 'yes' ]; then
  1128. echo "[ * ] Configuring ProFTPD server..."
  1129. echo "127.0.0.1 $servername" >> /etc/hosts
  1130. cp -f $HESTIA_INSTALL_DIR/proftpd/proftpd.conf /etc/proftpd/
  1131. cp -f $HESTIA_INSTALL_DIR/proftpd/tls.conf /etc/proftpd/
  1132. update-rc.d proftpd defaults > /dev/null 2>&1
  1133. systemctl start proftpd >> $LOG
  1134. check_result $? "proftpd start failed"
  1135. fi
  1136. #----------------------------------------------------------#
  1137. # Configure MariaDB #
  1138. #----------------------------------------------------------#
  1139. if [ "$mysql" = 'yes' ]; then
  1140. echo "[ * ] Configuring MariaDB database server..."
  1141. mycnf="my-small.cnf"
  1142. if [ $memory -gt 1200000 ]; then
  1143. mycnf="my-medium.cnf"
  1144. fi
  1145. if [ $memory -gt 3900000 ]; then
  1146. mycnf="my-large.cnf"
  1147. fi
  1148. # Remove symbolic link
  1149. rm -f /etc/mysql/my.cnf
  1150. # Configuring MariaDB
  1151. cp -f $HESTIA_INSTALL_DIR/mysql/$mycnf /etc/mysql/my.cnf
  1152. mysql_install_db >> $LOG
  1153. update-rc.d mysql defaults > /dev/null 2>&1
  1154. systemctl start mysql >> $LOG
  1155. check_result $? "mariadb start failed"
  1156. # Securing MariaDB installation
  1157. mpass=$(gen_pass)
  1158. mysqladmin -u root password $mpass >> $LOG
  1159. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  1160. chmod 600 /root/.my.cnf
  1161. # Clear MariaDB Test Users and Databases
  1162. mysql -e "DELETE FROM mysql.user WHERE User=''"
  1163. mysql -e "DROP DATABASE test" > /dev/null 2>&1
  1164. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  1165. mysql -e "DELETE FROM mysql.user WHERE user='';"
  1166. mysql -e "DELETE FROM mysql.user WHERE password='' AND authentication_string='';"
  1167. fi
  1168. #----------------------------------------------------------#
  1169. # Configure phpMyAdmin #
  1170. #----------------------------------------------------------#
  1171. if [ "$mysql" = 'yes' ]; then
  1172. # Display upgrade information
  1173. echo "[ * ] Installing phpMyAdmin version v$pma_v..."
  1174. # Download latest phpmyadmin release
  1175. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  1176. # Unpack files
  1177. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  1178. # Create folders
  1179. mkdir -p /usr/share/phpmyadmin
  1180. mkdir -p /etc/phpmyadmin
  1181. mkdir -p /etc/phpmyadmin/conf.d/
  1182. mkdir /usr/share/phpmyadmin/tmp
  1183. # Configuring Apache2 for PHPMYADMIN
  1184. if [ "$apache" = 'yes' ]; then
  1185. cp -f $HESTIA_INSTALL_DIR/pma/apache.conf /etc/phpmyadmin/
  1186. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  1187. fi
  1188. # Overwrite old files
  1189. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  1190. # Create copy of config file
  1191. cp -f $HESTIA_INSTALL_DIR/phpmyadmin/config.inc.php /etc/phpmyadmin/
  1192. mkdir -p /var/lib/phpmyadmin/tmp
  1193. chmod 777 /var/lib/phpmyadmin/tmp
  1194. # Set config and log directory
  1195. sed -i "s|define('CONFIG_DIR', ROOT_PATH);|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  1196. sed -i "s|define('TEMP_DIR', ROOT_PATH . 'tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  1197. # Create temporary folder and change permission
  1198. chmod 777 /usr/share/phpmyadmin/tmp
  1199. # Generate blow fish
  1200. blowfish=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
  1201. sed -i "s|%blowfish_secret%|$blowfish|" /etc/phpmyadmin/config.inc.php
  1202. # Clean Up
  1203. rm -fr phpMyAdmin-$pma_v-all-languages
  1204. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  1205. echo "DB_PMA_ALIAS='phpmyadmin'" >> $HESTIA/conf/hestia.conf
  1206. $HESTIA/bin/v-change-sys-db-alias 'pma' "phpmyadmin"
  1207. # Special thanks to Pavel Galkin (https://skurudo.ru)
  1208. # https://github.com/skurudo/phpmyadmin-fixer
  1209. source $HESTIA_INSTALL_DIR/phpmyadmin/pma.sh > /dev/null 2>&1
  1210. fi
  1211. #----------------------------------------------------------#
  1212. # Configure PostgreSQL #
  1213. #----------------------------------------------------------#
  1214. if [ "$postgresql" = 'yes' ]; then
  1215. echo "[ * ] Configuring PostgreSQL database server..."
  1216. ppass=$(gen_pass)
  1217. cp -f $HESTIA_INSTALL_DIR/postgresql/pg_hba.conf /etc/postgresql/*/main/
  1218. systemctl restart postgresql
  1219. sudo -iu postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  1220. # Configuring phpPgAdmin
  1221. if [ "$apache" = 'yes' ]; then
  1222. cp -f $HESTIA_INSTALL_DIR/pga/phppgadmin.conf /etc/apache2/conf.d/
  1223. fi
  1224. cp -f $HESTIA_INSTALL_DIR/pga/config.inc.php /etc/phppgadmin/
  1225. echo "DB_PGA_ALIAS='phppgadmin'" >> $HESTIA/conf/hestia.conf
  1226. $HESTIA/bin/v-change-sys-db-alias 'pga' "phppgadmin"
  1227. fi
  1228. #----------------------------------------------------------#
  1229. # Configure Bind #
  1230. #----------------------------------------------------------#
  1231. if [ "$named" = 'yes' ]; then
  1232. echo "[ * ] Configuring Bind DNS server..."
  1233. cp -f $HESTIA_INSTALL_DIR/bind/named.conf /etc/bind/
  1234. cp -f $HESTIA_INSTALL_DIR/bind/named.conf.options /etc/bind/
  1235. chown root:bind /etc/bind/named.conf
  1236. chown root:bind /etc/bind/named.conf.options
  1237. chown bind:bind /var/cache/bind
  1238. chmod 640 /etc/bind/named.conf
  1239. chmod 640 /etc/bind/named.conf.options
  1240. aa-complain /usr/sbin/named 2>/dev/null
  1241. if [ "$apparmor" = 'yes' ]; then
  1242. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2> /dev/null
  1243. systemctl status apparmor >/dev/null 2>&1
  1244. if [ $? -ne 0 ]; then
  1245. systemctl restart apparmor
  1246. fi
  1247. fi
  1248. update-rc.d bind9 defaults
  1249. systemctl start bind9
  1250. check_result $? "bind9 start failed"
  1251. # Workaround for OpenVZ/Virtuozzo
  1252. if [ -e "/proc/vz/veinfo" ] && [ -e "/etc/rc.local" ]; then
  1253. sed -i "s/^exit 0/service bind9 restart\nexit 0/" /etc/rc.local
  1254. fi
  1255. fi
  1256. #----------------------------------------------------------#
  1257. # Configure Exim #
  1258. #----------------------------------------------------------#
  1259. if [ "$exim" = 'yes' ]; then
  1260. echo "[ * ] Configuring Exim mail server..."
  1261. gpasswd -a Debian-exim mail > /dev/null 2>&1
  1262. cp -f $HESTIA_INSTALL_DIR/exim/exim4.conf.template /etc/exim4/
  1263. cp -f $HESTIA_INSTALL_DIR/exim/dnsbl.conf /etc/exim4/
  1264. cp -f $HESTIA_INSTALL_DIR/exim/spam-blocks.conf /etc/exim4/
  1265. touch /etc/exim4/white-blocks.conf
  1266. if [ "$spamd" = 'yes' ]; then
  1267. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  1268. fi
  1269. if [ "$clamd" = 'yes' ]; then
  1270. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  1271. fi
  1272. chmod 640 /etc/exim4/exim4.conf.template
  1273. rm -rf /etc/exim4/domains
  1274. mkdir -p /etc/exim4/domains
  1275. rm -f /etc/alternatives/mta
  1276. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  1277. update-rc.d -f sendmail remove > /dev/null 2>&1
  1278. systemctl stop sendmail > /dev/null 2>&1
  1279. update-rc.d -f postfix remove > /dev/null 2>&1
  1280. systemctl stop postfix > /dev/null 2>&1
  1281. update-rc.d exim4 defaults
  1282. systemctl start exim4
  1283. check_result $? "exim4 start failed"
  1284. fi
  1285. #----------------------------------------------------------#
  1286. # Configure Dovecot #
  1287. #----------------------------------------------------------#
  1288. if [ "$dovecot" = 'yes' ]; then
  1289. echo "[ * ] Configuring Dovecot POP/IMAP mail server..."
  1290. gpasswd -a dovecot mail > /dev/null 2>&1
  1291. cp -rf $HESTIA_INSTALL_DIR/dovecot /etc/
  1292. cp -f $HESTIA_INSTALL_DIR/logrotate/dovecot /etc/logrotate.d/
  1293. chown -R root:root /etc/dovecot*
  1294. if [ "$release" -eq 9 ] || [ "$release" -eq 10 ]; then
  1295. rm -f /etc/dovecot/conf.d/15-mailboxes.conf
  1296. fi
  1297. update-rc.d dovecot defaults
  1298. systemctl start dovecot
  1299. check_result $? "dovecot start failed"
  1300. fi
  1301. #----------------------------------------------------------#
  1302. # Configure ClamAV #
  1303. #----------------------------------------------------------#
  1304. if [ "$clamd" = 'yes' ]; then
  1305. gpasswd -a clamav mail > /dev/null 2>&1
  1306. gpasswd -a clamav Debian-exim > /dev/null 2>&1
  1307. cp -f $HESTIA_INSTALL_DIR/clamav/clamd.conf /etc/clamav/
  1308. update-rc.d clamav-daemon defaults
  1309. if [ ! -d "/var/run/clamav" ]; then
  1310. mkdir /var/run/clamav
  1311. fi
  1312. chown -R clamav:clamav /var/run/clamav
  1313. if [ -e "/lib/systemd/system/clamav-daemon.service" ]; then
  1314. exec_pre1='ExecStartPre=-/bin/mkdir -p /var/run/clamav'
  1315. exec_pre2='ExecStartPre=-/bin/chown -R clamav:clamav /var/run/clamav'
  1316. sed -i "s|\[Service\]/|[Service]\n$exec_pre1\n$exec_pre2|g" \
  1317. /lib/systemd/system/clamav-daemon.service
  1318. systemctl daemon-reload
  1319. fi
  1320. echo -ne "[ * ] Installing ClamAV anti-virus definitions... "
  1321. /usr/bin/freshclam >> $LOG &
  1322. BACK_PID=$!
  1323. spin_i=1
  1324. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  1325. printf "\b${spinner:spin_i++%${#spinner}:1}"
  1326. sleep 0.5
  1327. done
  1328. echo
  1329. systemctl start clamav-daemon
  1330. check_result $? "clamav-daemon start failed"
  1331. fi
  1332. #----------------------------------------------------------#
  1333. # Configure SpamAssassin #
  1334. #----------------------------------------------------------#
  1335. if [ "$spamd" = 'yes' ]; then
  1336. echo "[ * ] Configuring SpamAssassin..."
  1337. update-rc.d spamassassin defaults > /dev/null 2>&1
  1338. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  1339. systemctl start spamassassin >> $LOG
  1340. check_result $? "spamassassin start failed"
  1341. unit_files="$(systemctl list-unit-files |grep spamassassin)"
  1342. if [[ "$unit_files" =~ "disabled" ]]; then
  1343. systemctl enable spamassassin > /dev/null 2>&1
  1344. fi
  1345. fi
  1346. #----------------------------------------------------------#
  1347. # Configure Fail2Ban #
  1348. #----------------------------------------------------------#
  1349. if [ "$fail2ban" = 'yes' ]; then
  1350. echo "[ * ] Configuring fail2ban access monitor..."
  1351. cp -rf $HESTIA_INSTALL_DIR/fail2ban /etc/
  1352. if [ "$dovecot" = 'no' ]; then
  1353. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1354. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1355. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1356. fi
  1357. if [ "$exim" = 'no' ]; then
  1358. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1359. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1360. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1361. fi
  1362. if [ "$vsftpd" = 'yes' ]; then
  1363. #Create vsftpd Log File
  1364. if [ ! -f "/var/log/vsftpd.log" ]; then
  1365. touch /var/log/vsftpd.log
  1366. fi
  1367. fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1368. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1369. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1370. fi
  1371. if [ ! -e /var/log/auth.log ]; then
  1372. # Debian workaround: auth logging was moved to systemd
  1373. touch /var/log/auth.log
  1374. chmod 640 /var/log/auth.log
  1375. chown root:adm /var/log/auth.log
  1376. fi
  1377. if [ -f /etc/fail2ban/jail.d/defaults-debian.conf ]; then
  1378. rm -f /etc/fail2ban/jail.d/defaults-debian.conf
  1379. fi
  1380. update-rc.d fail2ban defaults
  1381. systemctl start fail2ban
  1382. check_result $? "fail2ban start failed"
  1383. fi
  1384. #----------------------------------------------------------#
  1385. # Install Roundcube #
  1386. #----------------------------------------------------------#
  1387. echo "[ * ] Install Roundcube..."
  1388. # Min requirements Dovecote + Exim + Mysql
  1389. if [ "$mysql" == 'yes' ] && [ "$$dovecot" == "yes" ]; then
  1390. $BIN/v-add-sys-roundcube
  1391. fi
  1392. #----------------------------------------------------------#
  1393. # Configure API #
  1394. #----------------------------------------------------------#
  1395. if [ "$api" = 'yes' ]; then
  1396. echo "API='yes'" >> $HESTIA/conf/hestia.conf
  1397. else
  1398. rm -r $HESTIA/web/api
  1399. echo "API='no'" >> $HESTIA/conf/hestia.conf
  1400. fi
  1401. #----------------------------------------------------------#
  1402. # Configure Admin User #
  1403. #----------------------------------------------------------#
  1404. # Deleting old admin user
  1405. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1406. chattr -i /home/admin/conf > /dev/null 2>&1
  1407. userdel -f admin > /dev/null 2>&1
  1408. chattr -i /home/admin/conf > /dev/null 2>&1
  1409. mv -f /home/admin $hst_backups/home/ > /dev/null 2>&1
  1410. rm -f /tmp/sess_* > /dev/null 2>&1
  1411. fi
  1412. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  1413. groupdel admin > /dev/null 2>&1
  1414. fi
  1415. # Enable sftp jail
  1416. $HESTIA/bin/v-add-sys-sftp-jail > /dev/null 2>&1
  1417. check_result $? "can't enable sftp jail"
  1418. # Adding Hestia admin account
  1419. $HESTIA/bin/v-add-user admin $vpass $email default "System Administrator"
  1420. check_result $? "can't create admin user"
  1421. $HESTIA/bin/v-change-user-shell admin nologin
  1422. $HESTIA/bin/v-change-user-role admin admin
  1423. $HESTIA/bin/v-change-user-language admin $lang
  1424. # Roundcube permissions fix
  1425. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1426. if [ ! -d "/var/log/roundcube" ]; then
  1427. mkdir /var/log/roundcube
  1428. fi
  1429. chown admin:admin /var/log/roundcube
  1430. fi
  1431. # Configuring system IPs
  1432. $HESTIA/bin/v-update-sys-ip > /dev/null 2>&1
  1433. # Get main IP
  1434. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1435. local_ip=$ip
  1436. # Configuring firewall
  1437. if [ "$iptables" = 'yes' ]; then
  1438. $HESTIA/bin/v-update-firewall
  1439. fi
  1440. # Get public IP
  1441. pub_ip=$(curl --ipv4 -s https://ip.hestiacp.com/)
  1442. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1443. $HESTIA/bin/v-change-sys-ip-nat $ip $pub_ip > /dev/null 2>&1
  1444. ip=$pub_ip
  1445. fi
  1446. # Configuring libapache2-mod-remoteip
  1447. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  1448. cd /etc/apache2/mods-available
  1449. echo "<IfModule mod_remoteip.c>" > remoteip.conf
  1450. echo " RemoteIPHeader X-Real-IP" >> remoteip.conf
  1451. if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ip" != "127.0.0.1" ]; then
  1452. echo " RemoteIPInternalProxy 127.0.0.1" >> remoteip.conf
  1453. fi
  1454. if [ ! -z "$local_ip" ] && [ "$local_ip" != "$pub_ip" ]; then
  1455. echo " RemoteIPInternalProxy $local_ip" >> remoteip.conf
  1456. fi
  1457. if [ ! -z "$pub_ip" ]; then
  1458. echo " RemoteIPInternalProxy $pub_ip" >> remoteip.conf
  1459. fi
  1460. echo "</IfModule>" >> remoteip.conf
  1461. sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  1462. a2enmod remoteip >> $LOG
  1463. systemctl restart apache2
  1464. fi
  1465. # Configuring MariaDB host
  1466. if [ "$mysql" = 'yes' ]; then
  1467. $HESTIA/bin/v-add-database-host mysql localhost root $mpass
  1468. fi
  1469. # Configuring PostgreSQL host
  1470. if [ "$postgresql" = 'yes' ]; then
  1471. $HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
  1472. fi
  1473. # Adding default domain
  1474. $HESTIA/bin/v-add-web-domain admin $servername
  1475. check_result $? "can't create $servername domain"
  1476. # Adding cron jobs
  1477. export SCHEDULED_RESTART="yes"
  1478. command="sudo $HESTIA/bin/v-update-sys-queue restart"
  1479. $HESTIA/bin/v-add-cron-job 'admin' '*/2' '*' '*' '*' '*' "$command"
  1480. systemctl restart cron
  1481. command="sudo $HESTIA/bin/v-update-sys-queue daily"
  1482. $HESTIA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1483. command="sudo $HESTIA/bin/v-update-sys-queue disk"
  1484. $HESTIA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1485. command="sudo $HESTIA/bin/v-update-sys-queue traffic"
  1486. $HESTIA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1487. command="sudo $HESTIA/bin/v-update-sys-queue webstats"
  1488. $HESTIA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1489. command="sudo $HESTIA/bin/v-update-sys-queue backup"
  1490. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1491. command="sudo $HESTIA/bin/v-backup-users"
  1492. $HESTIA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1493. command="sudo $HESTIA/bin/v-update-user-stats"
  1494. $HESTIA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1495. command="sudo $HESTIA/bin/v-update-sys-rrd"
  1496. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1497. # Enable automatic updates
  1498. $HESTIA/bin/v-add-cron-hestia-autoupdate apt
  1499. # Building initital rrd images
  1500. $HESTIA/bin/v-update-sys-rrd
  1501. # Enabling file system quota
  1502. if [ "$quota" = 'yes' ]; then
  1503. $HESTIA/bin/v-add-sys-quota
  1504. fi
  1505. # Set backend port
  1506. $HESTIA/bin/v-change-sys-port $port > /dev/null 2>&1
  1507. # Set default theme
  1508. $HESTIA/bin/v-change-sys-theme 'dark'
  1509. # Update remaining packages since repositories have changed
  1510. echo -ne "[ * ] Installing remaining software updates..."
  1511. apt-get -qq update
  1512. apt-get -y upgrade >> $LOG &
  1513. BACK_PID=$!
  1514. echo
  1515. # Starting Hestia service
  1516. update-rc.d hestia defaults
  1517. systemctl start hestia
  1518. check_result $? "hestia start failed"
  1519. chown admin:admin $HESTIA/data/sessions
  1520. #----------------------------------------------------------#
  1521. # Configure File Manager #
  1522. #----------------------------------------------------------#
  1523. echo "[ * ] Configuring File Manager..."
  1524. $HESTIA/bin/v-add-sys-filemanager quiet
  1525. #----------------------------------------------------------#
  1526. # Hestia Access Info #
  1527. #----------------------------------------------------------#
  1528. # Comparing hostname and IP
  1529. host_ip=$(host $servername| head -n 1 |awk '{print $NF}')
  1530. if [ "$host_ip" = "$ip" ]; then
  1531. ip="$servername"
  1532. fi
  1533. echo -e "\n"
  1534. echo "===================================================================="
  1535. echo -e "\n"
  1536. # Sending notification to admin email
  1537. echo -e "Congratulations!
  1538. You have successfully installed Hestia Control Panel on your server.
  1539. Ready to get started? Log in using the following credentials:
  1540. Admin URL: https://$ip:$port
  1541. Username: admin
  1542. Password: $vpass
  1543. Thank you for choosing Hestia Control Panel to power your full stack web server,
  1544. we hope that you enjoy using it as much as we do!
  1545. Please feel free to contact us at any time if you have any questions,
  1546. or if you encounter any bugs or problems:
  1547. E-mail: info@hestiacp.com
  1548. Web: https://www.hestiacp.com/
  1549. Forum: https://forum.hestiacp.com/
  1550. Discord: https://discord.gg/nXRUZch
  1551. GitHub: https://www.github.com/hestiacp/hestiacp
  1552. Note: Automatic updates are enabled by default. If you would like to disable them,
  1553. please log in and navigate to Server > Updates to turn them off.
  1554. Help support the Hestia Control Panel project by donating via PayPal:
  1555. https://www.hestiacp.com/donate
  1556. --
  1557. Sincerely yours,
  1558. The Hestia Control Panel development team
  1559. Made with love & pride by the open-source community around the world.
  1560. " > $tmpfile
  1561. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  1562. cat $tmpfile | $send_mail -s "Hestia Control Panel" $email
  1563. # Congrats
  1564. echo
  1565. cat $tmpfile
  1566. rm -f $tmpfile
  1567. # Add welcome message to notification panel
  1568. $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'
  1569. echo "[ ! ] IMPORTANT: You must logout or restart the server before continuing."
  1570. echo ""
  1571. if [ "$interactive" = 'yes' ]; then
  1572. echo -n " Do you want to reboot now? [Y/N] "
  1573. read reboot
  1574. if [ "$reboot" = "Y" ] || [ "$reboot" = "y" ]; then
  1575. reboot
  1576. fi
  1577. fi
  1578. # EOF