hst-install-ubuntu.sh 86 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473
  1. #!/bin/bash
  2. # ======================================================== #
  3. #
  4. # Hestia Control Panel Installer for Ubuntu
  5. # https://www.hestiacp.com/
  6. #
  7. # Currently Supported Versions:
  8. # Ubuntu 22.04, 24.04 LTS
  9. #
  10. # ======================================================== #
  11. #----------------------------------------------------------#
  12. # Variables&Functions #
  13. #----------------------------------------------------------#
  14. export PATH=$PATH:/sbin
  15. export DEBIAN_FRONTEND=noninteractive
  16. RHOST='apt.hestiacp.com'
  17. VERSION='ubuntu'
  18. HESTIA='/usr/local/hestia'
  19. LOG="/root/hst_install_backups/hst_install-$(date +%d%m%Y%H%M).log"
  20. memory=$(grep 'MemTotal' /proc/meminfo | tr ' ' '\n' | grep [0-9])
  21. hst_backups="/root/hst_install_backups/$(date +%d%m%Y%H%M)"
  22. spinner="/-\|"
  23. os='ubuntu'
  24. release="$(lsb_release -s -r)"
  25. codename="$(lsb_release -s -c)"
  26. architecture="$(arch)"
  27. HESTIA_INSTALL_DIR="$HESTIA/install/deb"
  28. HESTIA_COMMON_DIR="$HESTIA/install/common"
  29. VERBOSE='no'
  30. # Define software versions
  31. HESTIA_INSTALL_VER='1.10.0~alpha'
  32. # Supported PHP versions
  33. multiphp_v=("5.6" "7.0" "7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3" "8.4")
  34. # One of the following PHP versions is required for Roundcube / phpmyadmin
  35. multiphp_required=("7.3" "7.4" "8.0" "8.1" "8.2" "8.3")
  36. # Default PHP version if none supplied
  37. fpm_v="8.3"
  38. # MariaDB version
  39. mariadb_v="11.4"
  40. # Node.js version
  41. node_v="20"
  42. # Defining software pack for all distros
  43. software="acl apache2 apache2.2-common apache2-suexec-custom apache2-utils apparmor-utils at awstats bc bind9 bsdmainutils bsdutils
  44. clamav-daemon cron curl dnsutils dovecot-imapd dovecot-managesieved dovecot-pop3d dovecot-sieve e2fslibs e2fsprogs
  45. exim4 exim4-daemon-heavy expect fail2ban flex ftp git hestia=${HESTIA_INSTALL_VER} hestia-nginx hestia-php hestia-web-terminal
  46. idn2 imagemagick ipset jq libapache2-mod-fcgid libapache2-mod-php$fpm_v libapache2-mod-rpaf libonig5 libzip4 lsb-release
  47. lsof mariadb-client mariadb-common mariadb-server mc mysql-client mysql-common mysql-server nginx nodejs openssh-server
  48. php$fpm_v php$fpm_v-apcu php$fpm_v-bz2 php$fpm_v-cgi php$fpm_v-cli php$fpm_v-common php$fpm_v-curl php$fpm_v-gd
  49. php$fpm_v-imagick php$fpm_v-imap php$fpm_v-intl php$fpm_v-ldap php$fpm_v-mbstring php$fpm_v-mysql php$fpm_v-opcache
  50. php$fpm_v-pgsql php$fpm_v-pspell php$fpm_v-readline php$fpm_v-xml php$fpm_v-zip postgresql postgresql-contrib
  51. proftpd-core proftpd-mod-crypto quota rrdtool rsyslog util-linux spamassassin
  52. sysstat unzip vim-common vsftpd whois zip zstd bubblewrap restic"
  53. installer_dependencies="apt-transport-https ca-certificates curl dirmngr gnupg openssl software-properties-common wget sudo"
  54. # Defining help function
  55. help() {
  56. echo "Usage: $0 [OPTIONS]
  57. -a, --apache Install Apache [yes|no] default: yes
  58. -w, --phpfpm Install PHP-FPM [yes|no] default: yes
  59. -o, --multiphp Install MultiPHP [yes|no] default: no
  60. -v, --vsftpd Install VSFTPD [yes|no] default: yes
  61. -j, --proftpd Install ProFTPD [yes|no] default: no
  62. -k, --named Install BIND [yes|no] default: yes
  63. -m, --mysql Install MariaDB [yes|no] default: yes
  64. -M, --mysql8 Install MySQL 8 [yes|no] default: no
  65. -g, --postgresql Install PostgreSQL [yes|no] default: no
  66. -x, --exim Install Exim [yes|no] default: yes
  67. -z, --dovecot Install Dovecot [yes|no] default: yes
  68. -Z, --sieve Install Sieve [yes|no] default: no
  69. -c, --clamav Install ClamAV [yes|no] default: yes
  70. -t, --spamassassin Install SpamAssassin [yes|no] default: yes
  71. -i, --iptables Install iptables [yes|no] default: yes
  72. -b, --fail2ban Install Fail2Ban [yes|no] default: yes
  73. -q, --quota Filesystem Quota [yes|no] default: no
  74. -L, --resourcelimit Resource Limitation [yes|no] default: no
  75. -W, --webterminal Web Terminal [yes|no] default: no
  76. -d, --api Activate API [yes|no] default: yes
  77. -r, --port Change Backend Port default: 8083
  78. -l, --lang Default language default: en
  79. -y, --interactive Interactive install [yes|no] default: yes
  80. -s, --hostname Set hostname
  81. -e, --email Set admin email
  82. -u, --username Set admin user
  83. -p, --password Set admin password
  84. -D, --with-debs Path to Hestia debs
  85. -f, --force Force installation
  86. -h, --help Print this help
  87. Example: bash $0 -e [email protected] -p p4ssw0rd --multiphp yes"
  88. exit 1
  89. }
  90. # Defining file download function
  91. download_file() {
  92. wget $1 -q --show-progress --progress=bar:force
  93. }
  94. # Defining password-gen function
  95. gen_pass() {
  96. matrix=$1
  97. length=$2
  98. if [ -z "$matrix" ]; then
  99. matrix="A-Za-z0-9"
  100. fi
  101. if [ -z "$length" ]; then
  102. length=16
  103. fi
  104. head /dev/urandom | tr -dc $matrix | head -c$length
  105. }
  106. # Defining return code check function
  107. check_result() {
  108. if [ $1 -ne 0 ]; then
  109. echo "Error: $2"
  110. exit $1
  111. fi
  112. }
  113. # Source conf in installer
  114. source_conf() {
  115. while IFS='= ' read -r lhs rhs; do
  116. if [[ ! $lhs =~ ^\ *# && -n $lhs ]]; then
  117. rhs="${rhs%%^\#*}" # Del in line right comments
  118. rhs="${rhs%%*( )}" # Del trailing spaces
  119. rhs="${rhs%\'*}" # Del opening string quotes
  120. rhs="${rhs#\'*}" # Del closing string quotes
  121. declare -g $lhs="$rhs"
  122. fi
  123. done < $1
  124. }
  125. # Defining function to set default value
  126. set_default_value() {
  127. eval variable=\$$1
  128. if [ -z "$variable" ]; then
  129. eval $1=$2
  130. fi
  131. if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then
  132. eval $1=$2
  133. fi
  134. }
  135. # Defining function to set default language value
  136. set_default_lang() {
  137. if [ -z "$lang" ]; then
  138. eval lang=$1
  139. fi
  140. lang_list="ar az bg bn bs ca cs da de el en es fa fi fr hr hu id it ja ka ku ko nl no pl pt pt-br ro ru sk sq sr sv th tr uk ur vi zh-cn zh-tw"
  141. if ! (echo $lang_list | grep -w $lang > /dev/null 2>&1); then
  142. eval lang=$1
  143. fi
  144. }
  145. # Define the default backend port
  146. set_default_port() {
  147. if [ -z "$port" ]; then
  148. eval port=$1
  149. fi
  150. }
  151. # Write configuration KEY/VALUE pair to $HESTIA/conf/hestia.conf
  152. write_config_value() {
  153. local key="$1"
  154. local value="$2"
  155. echo "$key='$value'" >> $HESTIA/conf/hestia.conf
  156. }
  157. # Sort configuration file values
  158. # Write final copy to $HESTIA/conf/hestia.conf for active usage
  159. # Duplicate file to $HESTIA/conf/defaults/hestia.conf to restore known good installation values
  160. sort_config_file() {
  161. sort $HESTIA/conf/hestia.conf -o /tmp/updconf
  162. mv $HESTIA/conf/hestia.conf $HESTIA/conf/hestia.conf.bak
  163. mv /tmp/updconf $HESTIA/conf/hestia.conf
  164. rm -f $HESTIA/conf/hestia.conf.bak
  165. if [ ! -d "$HESTIA/conf/defaults/" ]; then
  166. mkdir -p "$HESTIA/conf/defaults/"
  167. fi
  168. cp $HESTIA/conf/hestia.conf $HESTIA/conf/defaults/hestia.conf
  169. }
  170. # todo add check for usernames that are blocked
  171. validate_username() {
  172. if [[ "$username" =~ ^[[:alnum:]][-|\.|_[:alnum:]]{0,28}[[:alnum:]]$ ]]; then
  173. if [ -n "$(grep ^$username: /etc/passwd /etc/group)" ]; then
  174. echo -e "\nUsername or Group allready exists please select a new user name or delete the user and / or group."
  175. else
  176. return 1
  177. fi
  178. else
  179. echo -e "\nPlease use a valid username (ex. user)."
  180. return 0
  181. fi
  182. }
  183. validate_password() {
  184. if [ -z "$vpass" ]; then
  185. return 0
  186. else
  187. return 1
  188. fi
  189. }
  190. # Validate hostname according to RFC1178
  191. validate_hostname() {
  192. # remove extra .
  193. servername=$(echo "$servername" | sed -e "s/[.]*$//g")
  194. servername=$(echo "$servername" | sed -e "s/^[.]*//")
  195. if [[ $(echo "$servername" | grep -o "\." | wc -l) -gt 1 ]] && [[ ! $servername =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  196. # Hostname valid
  197. return 1
  198. else
  199. # Hostname invalid
  200. return 0
  201. fi
  202. }
  203. validate_email() {
  204. if [[ ! "$email" =~ ^[A-Za-z0-9._%+-]+@[[:alnum:].-]+\.[A-Za-z]{2,63}$ ]]; then
  205. # Email invalid
  206. return 0
  207. else
  208. # Email valid
  209. return 1
  210. fi
  211. }
  212. version_ge() { test "$(printf '%s\n' "$@" | sort -V | head -n 1)" != "$1" -o -n "$1" -a "$1" = "$2"; }
  213. #----------------------------------------------------------#
  214. # Verifications #
  215. #----------------------------------------------------------#
  216. # Creating temporary file
  217. tmpfile=$(mktemp -p /tmp)
  218. # Translating argument to --gnu-long-options
  219. for arg; do
  220. delim=""
  221. case "$arg" in
  222. --apache) args="${args}-a " ;;
  223. --phpfpm) args="${args}-w " ;;
  224. --vsftpd) args="${args}-v " ;;
  225. --proftpd) args="${args}-j " ;;
  226. --named) args="${args}-k " ;;
  227. --mysql) args="${args}-m " ;;
  228. --mariadb) args="${args}-m " ;;
  229. --mysql-classic) args="${args}-M " ;;
  230. --mysql8) args="${args}-M " ;;
  231. --postgresql) args="${args}-g " ;;
  232. --exim) args="${args}-x " ;;
  233. --dovecot) args="${args}-z " ;;
  234. --sieve) args="${args}-Z " ;;
  235. --clamav) args="${args}-c " ;;
  236. --spamassassin) args="${args}-t " ;;
  237. --iptables) args="${args}-i " ;;
  238. --fail2ban) args="${args}-b " ;;
  239. --multiphp) args="${args}-o " ;;
  240. --quota) args="${args}-q " ;;
  241. --resourcelimit) args="${args}-L " ;;
  242. --webterminal) args="${args}-W " ;;
  243. --port) args="${args}-r " ;;
  244. --lang) args="${args}-l " ;;
  245. --interactive) args="${args}-y " ;;
  246. --api) args="${args}-d " ;;
  247. --hostname) args="${args}-s " ;;
  248. --email) args="${args}-e " ;;
  249. --username) args="${args}-u " ;;
  250. --password) args="${args}-p " ;;
  251. --force) args="${args}-f " ;;
  252. --with-debs) args="${args}-D " ;;
  253. --help) args="${args}-h " ;;
  254. *)
  255. [[ "${arg:0:1}" == "-" ]] || delim="\""
  256. args="${args}${delim}${arg}${delim} "
  257. ;;
  258. esac
  259. done
  260. eval set -- "$args"
  261. # Parsing arguments
  262. while getopts "a:w:v:j:k:m:M:g:d:x:z:Z:c:t:i:b:r:o:q:L:l:y:s:u:e:p:W:D:fh" Option; do
  263. case $Option in
  264. a) apache=$OPTARG ;; # Apache
  265. w) phpfpm=$OPTARG ;; # PHP-FPM
  266. o) multiphp=$OPTARG ;; # Multi-PHP
  267. v) vsftpd=$OPTARG ;; # Vsftpd
  268. j) proftpd=$OPTARG ;; # Proftpd
  269. k) named=$OPTARG ;; # Named
  270. m) mysql=$OPTARG ;; # MariaDB
  271. M) mysql8=$OPTARG ;; # MySQL
  272. g) postgresql=$OPTARG ;; # PostgreSQL
  273. x) exim=$OPTARG ;; # Exim
  274. z) dovecot=$OPTARG ;; # Dovecot
  275. Z) sieve=$OPTARG ;; # Sieve
  276. c) clamd=$OPTARG ;; # ClamAV
  277. t) spamd=$OPTARG ;; # SpamAssassin
  278. i) iptables=$OPTARG ;; # Iptables
  279. b) fail2ban=$OPTARG ;; # Fail2ban
  280. q) quota=$OPTARG ;; # FS Quota
  281. L) resourcelimit=$OPTARG ;; # Resource Limitation
  282. W) webterminal=$OPTARG ;; # Web Terminal
  283. r) port=$OPTARG ;; # Backend Port
  284. l) lang=$OPTARG ;; # Language
  285. d) api=$OPTARG ;; # Activate API
  286. y) interactive=$OPTARG ;; # Interactive install
  287. s) servername=$OPTARG ;; # Hostname
  288. e) email=$OPTARG ;; # Admin email
  289. u) username=$OPTARG ;; # Admin username
  290. p) vpass=$OPTARG ;; # Admin password
  291. D) withdebs=$OPTARG ;; # Hestia debs path
  292. f) force='yes' ;; # Force install
  293. h) help ;; # Help
  294. *) help ;; # Print help (default)
  295. esac
  296. done
  297. if [ -n "$multiphp" ]; then
  298. if [ "$multiphp" != 'no' ] && [ "$multiphp" != 'yes' ]; then
  299. php_versions=$(echo $multiphp | tr ',' "\n")
  300. multiphp_version=()
  301. for php_version in "${php_versions[@]}"; do
  302. if [[ $(echo "${multiphp_v[@]}" | fgrep -w "$php_version") ]]; then
  303. multiphp_version=(${multiphp_version[@]} "$php_version")
  304. else
  305. echo "$php_version is not supported"
  306. exit 1
  307. fi
  308. done
  309. multiphp_v=()
  310. for version in "${multiphp_version[@]}"; do
  311. multiphp_v=(${multiphp_v[@]} $version)
  312. done
  313. fpm_old=$fpm_v
  314. multiphp="yes"
  315. fpm_v=$(printf "%s\n" "${multiphp_version[@]}" | sort -V | tail -n1)
  316. fpm_last=$(printf "%s\n" "${multiphp_required[@]}" | sort -V | tail -n1)
  317. # Allow Maintainer to set minimum fpm version to make sure phpmyadmin and roundcube keep working
  318. if [[ -z $(echo "${multiphp_required[@]}" | fgrep -w $fpm_v) ]]; then
  319. if version_ge $fpm_v $fpm_last; then
  320. multiphp_version=(${multiphp_version[@]} $fpm_last)
  321. fpm_v=$fpm_last
  322. else
  323. # Roundcube and PHPmyadmin doesn't support the version selected.
  324. echo "Selected PHP versions are not supported any more by Dependencies..."
  325. exit 1
  326. fi
  327. fi
  328. software=$(echo "$software" | sed -e "s/php$fpm_old/php$fpm_v/g")
  329. fi
  330. fi
  331. # Defining default software stack
  332. set_default_value 'nginx' 'yes'
  333. set_default_value 'apache' 'yes'
  334. set_default_value 'phpfpm' 'yes'
  335. set_default_value 'multiphp' 'no'
  336. set_default_value 'vsftpd' 'yes'
  337. set_default_value 'proftpd' 'no'
  338. set_default_value 'named' 'yes'
  339. set_default_value 'mysql' 'yes'
  340. set_default_value 'mysql8' 'no'
  341. set_default_value 'postgresql' 'no'
  342. set_default_value 'exim' 'yes'
  343. set_default_value 'dovecot' 'yes'
  344. set_default_value 'sieve' 'no'
  345. if [ $memory -lt 1500000 ]; then
  346. set_default_value 'clamd' 'no'
  347. set_default_value 'spamd' 'no'
  348. elif [ $memory -lt 3000000 ]; then
  349. set_default_value 'clamd' 'no'
  350. set_default_value 'spamd' 'yes'
  351. else
  352. set_default_value 'clamd' 'yes'
  353. set_default_value 'spamd' 'yes'
  354. fi
  355. set_default_value 'iptables' 'yes'
  356. set_default_value 'fail2ban' 'yes'
  357. set_default_value 'quota' 'no'
  358. set_default_value 'resourcelimit' 'no'
  359. set_default_value 'webterminal' 'no'
  360. set_default_value 'interactive' 'yes'
  361. set_default_value 'api' 'yes'
  362. set_default_port '8083'
  363. set_default_lang 'en'
  364. # Checking software conflicts
  365. if [ "$proftpd" = 'yes' ]; then
  366. vsftpd='no'
  367. fi
  368. if [ "$exim" = 'no' ]; then
  369. clamd='no'
  370. spamd='no'
  371. dovecot='no'
  372. fi
  373. if [ "$dovecot" = 'no' ]; then
  374. sieve='no'
  375. fi
  376. if [ "$iptables" = 'no' ]; then
  377. fail2ban='no'
  378. fi
  379. if [ "$apache" = 'no' ]; then
  380. phpfpm='yes'
  381. fi
  382. if [ "$mysql" = 'yes' ] && [ "$mysql8" = 'yes' ]; then
  383. mysql='no'
  384. fi
  385. # Checking root permissions
  386. if [ "x$(id -u)" != 'x0' ]; then
  387. check_result 1 "Script can be run executed only by root"
  388. fi
  389. if [ -d "/usr/local/hestia" ]; then
  390. check_result 1 "Hestia install detected. Unable to continue"
  391. fi
  392. type=$(grep "^ID=" /etc/os-release | cut -f 2 -d '=')
  393. if [ "$type" = "debian" ]; then
  394. check_result 1 "You are running the wrong installer for Debian. Please run hst-install.sh or hst-install-debian.sh instead."
  395. elif [ "$type" != "ubuntu" ]; then
  396. check_result 1 "You are running an unsupported OS."
  397. fi
  398. # Clear the screen once launch permissions have been verified
  399. clear
  400. # Configure apt to retry downloading on error
  401. if [ ! -f /etc/apt/apt.conf.d/80-retries ]; then
  402. echo "APT::Acquire::Retries \"3\";" > /etc/apt/apt.conf.d/80-retries
  403. fi
  404. # Welcome message
  405. echo "Welcome to the Hestia Control Panel installer!"
  406. echo
  407. echo "Please wait, the installer is now checking for missing dependencies..."
  408. echo
  409. # Update apt repository
  410. apt-get -qq update
  411. # Creating backup directory
  412. mkdir -p "$hst_backups"
  413. # Pre-install packages
  414. echo "[ * ] Installing dependencies..."
  415. apt-get -y install $installer_dependencies >> $LOG
  416. check_result $? "Package installation failed, check log file for more details."
  417. # Check repository availability
  418. wget --quiet "https://$RHOST" -O /dev/null
  419. check_result $? "Unable to connect to the Hestia APT repository"
  420. # Check installed packages
  421. tmpfile=$(mktemp -p /tmp)
  422. dpkg --get-selections > $tmpfile
  423. conflicts_pkg="exim4 mariadb-server apache2 nginx hestia postfix ufw"
  424. # Drop postfix from the list if exim should not be installed
  425. if [ "$exim" = 'no' ]; then
  426. conflicts_pkg=$(echo $conflicts_pkg | sed 's/postfix//g' | xargs)
  427. fi
  428. for pkg in $conflicts_pkg; do
  429. if [ -n "$(grep $pkg $tmpfile)" ]; then
  430. conflicts="$pkg* $conflicts"
  431. fi
  432. done
  433. rm -f $tmpfile
  434. if [ -n "$conflicts" ] && [ -z "$force" ]; then
  435. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  436. echo
  437. echo 'WARNING: The following packages are already installed'
  438. echo "$conflicts"
  439. echo
  440. echo 'It is highly recommended that you remove them before proceeding.'
  441. echo
  442. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  443. echo
  444. read -p 'Would you like to remove the conflicting packages? [y/N] ' answer
  445. if [ "$answer" = 'y' ] || [ "$answer" = 'Y' ]; then
  446. apt-get -qq purge $conflicts -y
  447. check_result $? 'apt-get remove failed'
  448. unset $answer
  449. else
  450. check_result 1 "Hestia Control Panel should be installed on a clean server."
  451. fi
  452. fi
  453. # Check network configuration
  454. if [ -d /etc/netplan ] && [ -z "$force" ]; then
  455. if [ -z "$(ls -A /etc/netplan)" ]; then
  456. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  457. echo
  458. echo 'WARNING: Your network configuration may not be set up correctly.'
  459. echo 'Details: The netplan configuration directory is empty.'
  460. echo ''
  461. echo 'You may have a network configuration file that was created using'
  462. echo 'systemd-networkd.'
  463. echo ''
  464. echo 'It is strongly recommended to migrate to netplan, which is now the'
  465. echo 'default network configuration system in newer releases of Ubuntu.'
  466. echo ''
  467. echo 'While you can leave your configuration as-is, please note that you'
  468. echo 'will not be able to use additional IPs properly.'
  469. echo ''
  470. echo 'If you wish to continue and force the installation,'
  471. echo 'run this script with -f option:'
  472. echo "Example: bash $0 --force"
  473. echo
  474. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  475. echo
  476. check_result 1 "Unable to detect netplan configuration."
  477. fi
  478. fi
  479. # Validate whether installation script matches release version before continuing with install
  480. if [ -z "$withdebs" ] || [ ! -d "$withdebs" ]; then
  481. release_branch_ver=$(curl -s https://raw.githubusercontent.com/hestiacp/hestiacp/release/src/deb/hestia/control | grep "Version:" | awk '{print $2}')
  482. if [ "$HESTIA_INSTALL_VER" != "$release_branch_ver" ]; then
  483. echo
  484. echo -e "\e[91mInstallation aborted\e[0m"
  485. echo "===================================================================="
  486. echo -e "\e[33mERROR: Install script version does not match package version!\e[0m"
  487. echo -e "\e[33mPlease download the installer from the release branch in order to continue:\e[0m"
  488. echo ""
  489. echo -e "\e[33mhttps://raw.githubusercontent.com/hestiacp/hestiacp/release/install/hst-install.sh\e[0m"
  490. echo ""
  491. echo -e "\e[33mTo test pre-release versions, build the .deb packages and re-run the installer:\e[0m"
  492. echo -e " \e[33m./hst_autocompile.sh \e[1m--hestia branchname no\e[21m\e[0m"
  493. echo -e " \e[33m./hst-install.sh .. \e[1m--with-debs /tmp/hestiacp-src/debs\e[21m\e[0m"
  494. echo ""
  495. check_result 1 "Installation aborted"
  496. fi
  497. fi
  498. case $architecture in
  499. x86_64)
  500. ARCH="amd64"
  501. ;;
  502. aarch64)
  503. ARCH="arm64"
  504. ;;
  505. *)
  506. echo
  507. echo -e "\e[91mInstallation aborted\e[0m"
  508. echo "===================================================================="
  509. echo -e "\e[33mERROR: $architecture is currently not supported!\e[0m"
  510. echo -e "\e[33mPlease verify the achitecture used is currenlty supported\e[0m"
  511. echo ""
  512. echo -e "\e[33mhttps://github.com/hestiacp/hestiacp/blob/main/README.md\e[0m"
  513. echo ""
  514. check_result 1 "Installation aborted"
  515. ;;
  516. esac
  517. #----------------------------------------------------------#
  518. # Brief Info #
  519. #----------------------------------------------------------#
  520. install_welcome_message() {
  521. DISPLAY_VER=$(echo $HESTIA_INSTALL_VER | sed "s|~alpha||g" | sed "s|~beta||g")
  522. echo
  523. echo ' _ _ _ _ ____ ____ '
  524. echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
  525. echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) | '
  526. echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
  527. echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
  528. echo " "
  529. echo " Hestia Control Panel "
  530. if [[ "$HESTIA_INSTALL_VER" =~ "beta" ]]; then
  531. echo " BETA RELEASE "
  532. fi
  533. if [[ "$HESTIA_INSTALL_VER" =~ "alpha" ]]; then
  534. echo " DEVELOPMENT SNAPSHOT "
  535. echo " NOT INTENDED FOR PRODUCTION USE "
  536. echo " USE AT YOUR OWN RISK "
  537. fi
  538. echo " ${DISPLAY_VER} "
  539. echo " www.hestiacp.com "
  540. echo
  541. echo "========================================================================"
  542. echo
  543. echo "Thank you for downloading Hestia Control Panel! In a few moments,"
  544. echo "we will begin installing the following components on your server:"
  545. echo
  546. }
  547. # Printing nice ASCII logo
  548. clear
  549. install_welcome_message
  550. # Web stack
  551. echo ' - NGINX Web / Proxy Server'
  552. if [ "$apache" = 'yes' ]; then
  553. echo ' - Apache Web Server (as backend)'
  554. fi
  555. if [ "$phpfpm" = 'yes' ] && [ "$multiphp" = 'no' ]; then
  556. echo ' - PHP-FPM Application Server'
  557. fi
  558. if [ "$multiphp" = 'yes' ]; then
  559. phpfpm='yes'
  560. echo -n ' - Multi-PHP Environment: Version'
  561. for version in "${multiphp_v[@]}"; do
  562. echo -n " php$version"
  563. done
  564. echo ''
  565. fi
  566. # DNS stack
  567. if [ "$named" = 'yes' ]; then
  568. echo ' - Bind DNS Server'
  569. fi
  570. # Mail stack
  571. if [ "$exim" = 'yes' ]; then
  572. echo -n ' - Exim Mail Server'
  573. if [ "$clamd" = 'yes' ] || [ "$spamd" = 'yes' ]; then
  574. echo -n ' + '
  575. if [ "$clamd" = 'yes' ]; then
  576. echo -n 'ClamAV '
  577. fi
  578. if [ "$spamd" = 'yes' ]; then
  579. if [ "$clamd" = 'yes' ]; then
  580. echo -n '+ '
  581. fi
  582. echo -n 'SpamAssassin'
  583. fi
  584. fi
  585. echo
  586. if [ "$dovecot" = 'yes' ]; then
  587. echo -n ' - Dovecot POP3/IMAP Server'
  588. if [ "$sieve" = 'yes' ]; then
  589. echo -n '+ Sieve'
  590. fi
  591. fi
  592. fi
  593. echo
  594. # Database stack
  595. if [ "$mysql" = 'yes' ]; then
  596. echo ' - MariaDB Database Server'
  597. fi
  598. if [ "$mysql8" = 'yes' ]; then
  599. echo ' - MySQL8 Database Server'
  600. fi
  601. if [ "$postgresql" = 'yes' ]; then
  602. echo ' - PostgreSQL Database Server'
  603. fi
  604. # FTP stack
  605. if [ "$vsftpd" = 'yes' ]; then
  606. echo ' - Vsftpd FTP Server'
  607. fi
  608. if [ "$proftpd" = 'yes' ]; then
  609. echo ' - ProFTPD FTP Server'
  610. fi
  611. if [ "$webterminal" = 'yes' ]; then
  612. echo ' - Web terminal'
  613. fi
  614. # Firewall stack
  615. if [ "$iptables" = 'yes' ]; then
  616. echo -n ' - Firewall (iptables)'
  617. fi
  618. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  619. echo -n ' + Fail2Ban Access Monitor'
  620. fi
  621. echo -e "\n"
  622. echo "========================================================================"
  623. echo -e "\n"
  624. # Asking for confirmation to proceed
  625. if [ "$interactive" = 'yes' ]; then
  626. read -p 'Would you like to continue with the installation? [y/N]: ' answer
  627. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  628. echo 'Goodbye'
  629. exit 1
  630. fi
  631. fi
  632. # Validate Username / Password / Email / Hostname even when interactive = no
  633. if [ -z "$username" ]; then
  634. while validate_username; do
  635. read -p 'Please enter administrator username: ' username
  636. done
  637. else
  638. if validate_username; then
  639. exit 1
  640. fi
  641. fi
  642. # Ask for password
  643. if [ -z "$vpass" ]; then
  644. while validate_password; do
  645. read -p 'Please enter administrator password: ' vpass
  646. done
  647. else
  648. if validate_password; then
  649. echo "Please use a valid password"
  650. exit 1
  651. fi
  652. fi
  653. # Asking for contact email
  654. if [ -z "$email" ]; then
  655. while validate_email; do
  656. echo -e "\nPlease use a valid emailadress (ex. [email protected])."
  657. read -p 'Please enter admin email address: ' email
  658. done
  659. else
  660. if validate_email; then
  661. echo "Please use a valid emailadress (ex. [email protected])."
  662. exit 1
  663. fi
  664. fi
  665. # Asking to set FQDN hostname
  666. if [ -z "$servername" ]; then
  667. # Ask and validate FQDN hostname.
  668. read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
  669. # Set hostname if it wasn't set
  670. if [ -z "$servername" ]; then
  671. servername=$(hostname -f)
  672. fi
  673. # Validate Hostname, go to loop if the validation fails.
  674. while validate_hostname; do
  675. echo -e "\nPlease use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
  676. read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
  677. done
  678. else
  679. # Validate FQDN hostname if it is preset
  680. if validate_hostname; then
  681. echo "Please use a valid hostname according to RFC1178 (ex. hostname.domain.tld)."
  682. exit 1
  683. fi
  684. fi
  685. # Generating admin password if it wasn't set
  686. displaypass="The password you chose during installation."
  687. if [ -z "$vpass" ]; then
  688. vpass=$(gen_pass)
  689. displaypass=$vpass
  690. fi
  691. # Set FQDN if it wasn't set
  692. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  693. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  694. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  695. if [[ -n "$servername" ]]; then
  696. servername="$servername.example.com"
  697. else
  698. servername="example.com"
  699. fi
  700. echo "127.0.0.1 $servername" >> /etc/hosts
  701. fi
  702. if [[ -z $(grep -i "$servername" /etc/hosts) ]]; then
  703. echo "127.0.0.1 $servername" >> /etc/hosts
  704. fi
  705. # Set email if it wasn't set
  706. if [[ -z "$email" ]]; then
  707. email="admin@$servername"
  708. fi
  709. # Defining backup directory
  710. echo -e "Installation backup directory: $hst_backups"
  711. # Print Log File Path
  712. echo "Installation log file: $LOG"
  713. # Print new line
  714. echo
  715. #----------------------------------------------------------#
  716. # Checking swap #
  717. #----------------------------------------------------------#
  718. # Add swap for low memory servers
  719. if [ -z "$(swapon -s)" ] && [ "$memory" -lt 1000000 ]; then
  720. fallocate -l 1G /swapfile
  721. chmod 600 /swapfile
  722. mkswap /swapfile
  723. swapon /swapfile
  724. echo "/swapfile none swap sw 0 0" >> /etc/fstab
  725. fi
  726. #----------------------------------------------------------#
  727. # Install repository #
  728. #----------------------------------------------------------#
  729. # Define apt conf location
  730. apt=/etc/apt/sources.list.d
  731. # Create new folder if it doesn't exist
  732. mkdir -p /root/.gnupg/ && chmod 700 /root/.gnupg/
  733. # Updating system
  734. echo "Adding required repositories to proceed with installation:"
  735. echo
  736. # Installing Nginx repo
  737. echo "[ * ] NGINX"
  738. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nginx-keyring.gpg] https://nginx.org/packages/mainline/$VERSION/ $codename nginx" > $apt/nginx.list
  739. curl -s https://nginx.org/keys/nginx_signing.key | gpg --dearmor | tee /usr/share/keyrings/nginx-keyring.gpg > /dev/null 2>&1
  740. # Installing sury PHP repo
  741. # add-apt-repository does not yet support signed-by see: https://bugs.launchpad.net/ubuntu/+source/software-properties/+bug/1862764
  742. echo "[ * ] PHP"
  743. if [ "$release" = '24.04' ]; then
  744. # Workaround for Ubuntu 24.04 due to weak key warning it sheduled to be fixed in 24.04.1
  745. echo 'APT::Key::Assert-Pubkey-Algo "";' > /etc/apt/apt.conf.d/99weakkey-warning
  746. fi
  747. LC_ALL=C.UTF-8 add-apt-repository -y ppa:ondrej/php > /dev/null 2>&1
  748. # Installing sury Apache2 repo
  749. if [ "$apache" = 'yes' ] && [ "$release" != '24.04' ]; then
  750. echo "[ * ] Apache2"
  751. echo "deb http://ppa.launchpad.net/ondrej/apache2/ubuntu $codename main" > $apt/apache2.list
  752. fi
  753. # Installing MariaDB repo
  754. if [ "$mysql" = 'yes' ]; then
  755. echo "[ * ] MariaDB $mariadb_v"
  756. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/mariadb-keyring.gpg] https://dlm.mariadb.com/repo/mariadb-server/$mariadb_v/repo/$VERSION $codename main" > $apt/mariadb.list
  757. curl -s https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor | tee /usr/share/keyrings/mariadb-keyring.gpg > /dev/null 2>&1
  758. fi
  759. # Installing HestiaCP repo
  760. echo "[ * ] Hestia Control Panel"
  761. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/hestia-keyring.gpg] https://$RHOST/ $codename main" > $apt/hestia.list
  762. gpg --no-default-keyring --keyring /usr/share/keyrings/hestia-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys A189E93654F0B0E5 > /dev/null 2>&1
  763. # Installing Node.js repo
  764. if [ "$webterminal" = 'yes' ]; then
  765. echo "[ * ] Node.js $node_v"
  766. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/nodejs.gpg] https://deb.nodesource.com/node_$node_v.x nodistro main" > $apt/nodejs.list
  767. curl -s https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor | tee /usr/share/keyrings/nodejs.gpg > /dev/null 2>&1
  768. apt-get -y install nodejs >> $LOG
  769. fi
  770. # Installing PostgreSQL repo
  771. if [ "$postgresql" = 'yes' ]; then
  772. echo "[ * ] PostgreSQL"
  773. echo "deb [arch=$ARCH signed-by=/usr/share/keyrings/postgresql-keyring.gpg] https://apt.postgresql.org/pub/repos/apt/ $codename-pgdg main" > $apt/postgresql.list
  774. curl -s https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor | tee /usr/share/keyrings/postgresql-keyring.gpg > /dev/null 2>&1
  775. fi
  776. # Echo for a new line
  777. echo
  778. # Updating system
  779. echo -ne "Updating currently installed packages, please wait... "
  780. apt-get -qq update
  781. apt-get -y upgrade >> $LOG &
  782. BACK_PID=$!
  783. # Check if package installation is done, print a spinner
  784. spin_i=1
  785. while kill -0 $BACK_PID > /dev/null 2>&1; do
  786. printf "\b${spinner:spin_i++%${#spinner}:1}"
  787. sleep 0.5
  788. done
  789. # Do a blank echo to get the \n back
  790. echo
  791. # Check Installation result
  792. wait $BACK_PID
  793. check_result $? 'apt-get upgrade failed'
  794. #----------------------------------------------------------#
  795. # Backup #
  796. #----------------------------------------------------------#
  797. # Creating backup directory tree
  798. mkdir -p $hst_backups
  799. cd $hst_backups
  800. mkdir nginx apache2 php vsftpd proftpd bind exim4 dovecot clamd
  801. mkdir spamassassin mysql postgresql openssl hestia
  802. # Backup OpenSSL configuration
  803. cp /etc/ssl/openssl.cnf $hst_backups/openssl > /dev/null 2>&1
  804. # Backup nginx configuration
  805. systemctl stop nginx > /dev/null 2>&1
  806. cp -r /etc/nginx/* $hst_backups/nginx > /dev/null 2>&1
  807. # Backup Apache configuration
  808. systemctl stop apache2 > /dev/null 2>&1
  809. cp -r /etc/apache2/* $hst_backups/apache2 > /dev/null 2>&1
  810. rm -f /etc/apache2/conf.d/* > /dev/null 2>&1
  811. # Backup PHP-FPM configuration
  812. systemctl stop php*-fpm > /dev/null 2>&1
  813. cp -r /etc/php/* $hst_backups/php > /dev/null 2>&1
  814. # Backup Bind configuration
  815. systemctl stop bind9 > /dev/null 2>&1
  816. cp -r /etc/bind/* $hst_backups/bind > /dev/null 2>&1
  817. # Backup Vsftpd configuration
  818. systemctl stop vsftpd > /dev/null 2>&1
  819. cp /etc/vsftpd.conf $hst_backups/vsftpd > /dev/null 2>&1
  820. # Backup ProFTPD configuration
  821. systemctl stop proftpd > /dev/null 2>&1
  822. cp /etc/proftpd/* $hst_backups/proftpd > /dev/null 2>&1
  823. # Backup Exim configuration
  824. systemctl stop exim4 > /dev/null 2>&1
  825. cp -r /etc/exim4/* $hst_backups/exim4 > /dev/null 2>&1
  826. # Backup ClamAV configuration
  827. systemctl stop clamav-daemon > /dev/null 2>&1
  828. cp -r /etc/clamav/* $hst_backups/clamav > /dev/null 2>&1
  829. # Backup SpamAssassin configuration
  830. systemctl stop spamassassin > /dev/null 2>&1
  831. cp -r /etc/spamassassin/* $hst_backups/spamassassin > /dev/null 2>&1
  832. # Backup Dovecot configuration
  833. systemctl stop dovecot > /dev/null 2>&1
  834. cp /etc/dovecot.conf $hst_backups/dovecot > /dev/null 2>&1
  835. cp -r /etc/dovecot/* $hst_backups/dovecot > /dev/null 2>&1
  836. # Backup MySQL/MariaDB configuration and data
  837. systemctl stop mysql > /dev/null 2>&1
  838. killall -9 mysqld > /dev/null 2>&1
  839. mv /var/lib/mysql $hst_backups/mysql/mysql_datadir > /dev/null 2>&1
  840. cp -r /etc/mysql/* $hst_backups/mysql > /dev/null 2>&1
  841. mv -f /root/.my.cnf $hst_backups/mysql > /dev/null 2>&1
  842. # Backup Hestia
  843. systemctl stop hestia > /dev/null 2>&1
  844. cp -r $HESTIA/* $hst_backups/hestia > /dev/null 2>&1
  845. apt-get -y purge hestia hestia-nginx hestia-php > /dev/null 2>&1
  846. rm -rf $HESTIA > /dev/null 2>&1
  847. #----------------------------------------------------------#
  848. # Package Includes #
  849. #----------------------------------------------------------#
  850. if [ "$phpfpm" = 'yes' ]; then
  851. fpm="php$fpm_v php$fpm_v-common php$fpm_v-bcmath php$fpm_v-cli
  852. php$fpm_v-curl php$fpm_v-fpm php$fpm_v-gd php$fpm_v-intl
  853. php$fpm_v-mysql php$fpm_v-soap php$fpm_v-xml php$fpm_v-zip
  854. php$fpm_v-mbstring php$fpm_v-bz2 php$fpm_v-pspell
  855. php$fpm_v-imagick"
  856. software="$software $fpm"
  857. fi
  858. #----------------------------------------------------------#
  859. # Package Excludes #
  860. #----------------------------------------------------------#
  861. # Excluding packages
  862. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  863. if [ "$apache" = 'no' ]; then
  864. software=$(echo "$software" | sed -e "s/apache2 //")
  865. software=$(echo "$software" | sed -e "s/apache2-bin//")
  866. software=$(echo "$software" | sed -e "s/apache2-utils//")
  867. software=$(echo "$software" | sed -e "s/apache2-suexec-custom//")
  868. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  869. software=$(echo "$software" | sed -e "s/libapache2-mod-rpaf//")
  870. software=$(echo "$software" | sed -e "s/libapache2-mod-fcgid//")
  871. software=$(echo "$software" | sed -e "s/libapache2-mod-php$fpm_v//")
  872. fi
  873. if [ "$vsftpd" = 'no' ]; then
  874. software=$(echo "$software" | sed -e "s/vsftpd//")
  875. fi
  876. if [ "$proftpd" = 'no' ]; then
  877. software=$(echo "$software" | sed -e "s/proftpd-core//")
  878. software=$(echo "$software" | sed -e "s/proftpd-mod-vroot//")
  879. software=$(echo "$software" | sed -e "s/proftpd-mod-crypto//")
  880. fi
  881. if [ "$named" = 'no' ]; then
  882. software=$(echo "$software" | sed -e "s/bind9//")
  883. fi
  884. if [ "$exim" = 'no' ]; then
  885. software=$(echo "$software" | sed -e "s/exim4 //")
  886. software=$(echo "$software" | sed -e "s/exim4-daemon-heavy//")
  887. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  888. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  889. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  890. software=$(echo "$software" | sed -e "s/spamassassin//")
  891. software=$(echo "$software" | sed -e "s/dovecot-sieve//")
  892. software=$(echo "$software" | sed -e "s/dovecot-managesieved//")
  893. fi
  894. if [ "$clamd" = 'no' ]; then
  895. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  896. fi
  897. if [ "$spamd" = 'no' ]; then
  898. software=$(echo "$software" | sed -e "s/spamassassin//")
  899. fi
  900. if [ "$dovecot" = 'no' ]; then
  901. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  902. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  903. fi
  904. if [ "$sieve" = 'no' ]; then
  905. software=$(echo "$software" | sed -e "s/dovecot-sieve//")
  906. software=$(echo "$software" | sed -e "s/dovecot-managesieved//")
  907. fi
  908. if [ "$mysql" = 'no' ]; then
  909. software=$(echo "$software" | sed -e "s/mariadb-server//")
  910. software=$(echo "$software" | sed -e "s/mariadb-client//")
  911. software=$(echo "$software" | sed -e "s/mariadb-common//")
  912. fi
  913. if [ "$mysql8" = 'no' ]; then
  914. software=$(echo "$software" | sed -e "s/mysql-server//")
  915. software=$(echo "$software" | sed -e "s/mysql-client//")
  916. software=$(echo "$software" | sed -e "s/mysql-common//")
  917. fi
  918. if [ "$mysql" = 'no' ] && [ "$mysql8" = 'no' ]; then
  919. software=$(echo "$software" | sed -e "s/php$fpm_v-mysql//")
  920. if [ "$multiphp" = 'yes' ]; then
  921. for v in "${multiphp_v[@]}"; do
  922. software=$(echo "$software" | sed -e "s/php$v-mysql//")
  923. software=$(echo "$software" | sed -e "s/php$v-bz2//")
  924. done
  925. fi
  926. fi
  927. if [ "$postgresql" = 'no' ]; then
  928. software=$(echo "$software" | sed -e "s/postgresql-contrib//")
  929. software=$(echo "$software" | sed -e "s/postgresql//")
  930. software=$(echo "$software" | sed -e "s/php$fpm_v-pgsql//")
  931. fi
  932. if [ "$fail2ban" = 'no' ]; then
  933. software=$(echo "$software" | sed -e "s/fail2ban//")
  934. fi
  935. if [ "$iptables" = 'no' ]; then
  936. software=$(echo "$software" | sed -e "s/ipset//")
  937. software=$(echo "$software" | sed -e "s/fail2ban//")
  938. fi
  939. if [ "$webterminal" = 'no' ]; then
  940. software=$(echo "$software" | sed -e "s/nodejs//")
  941. software=$(echo "$software" | sed -e "s/hestia-web-terminal//")
  942. fi
  943. if [ "$phpfpm" = 'yes' ]; then
  944. software=$(echo "$software" | sed -e "s/php$fpm_v-cgi//")
  945. software=$(echo "$software" | sed -e "s/libapache2-mod-ruid2//")
  946. software=$(echo "$software" | sed -e "s/libapache2-mod-php$fpm_v//")
  947. fi
  948. if [ -d "$withdebs" ]; then
  949. software=$(echo "$software" | sed -e "s/hestia-nginx//")
  950. software=$(echo "$software" | sed -e "s/hestia-php//")
  951. software=$(echo "$software" | sed -e "s/hestia-web-terminal//")
  952. software=$(echo "$software" | sed -e "s/hestia=${HESTIA_INSTALL_VER}//")
  953. fi
  954. if [ "$release" = '24.04' ]; then
  955. software=$(echo "$software" | sed -e "s/libzip4/libzip4t64/")
  956. fi
  957. #----------------------------------------------------------#
  958. # Disable Apparmor on LXC #
  959. #----------------------------------------------------------#
  960. if grep --quiet lxc /proc/1/environ; then
  961. if [ -f /etc/init.d/apparmor ]; then
  962. systemctl stop apparmor > /dev/null 2>&1
  963. systemctl disable apparmor > /dev/null 2>&1
  964. fi
  965. fi
  966. #----------------------------------------------------------#
  967. # Install packages #
  968. #----------------------------------------------------------#
  969. # Enable en_US.UTF-8
  970. if [ -f /etc/locale.gen ]; then
  971. sed -i "s/# en_US.UTF-8 UTF-8/en_US.UTF-8 UTF-8/g" /etc/locale.gen
  972. locale-gen > /dev/null 2>&1
  973. elif [ -f /usr/bin/localectl ]; then
  974. apt-get -y install locales-all >> $LOG
  975. localectl set-locale LANG=en_US.UTF-8 > /dev/null 2>&1
  976. fi
  977. # Disabling daemon autostart on apt-get install
  978. echo -e '#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d
  979. chmod a+x /usr/sbin/policy-rc.d
  980. # Installing apt packages
  981. echo "The installer is now downloading and installing all required packages."
  982. echo -ne "NOTE: This process may take 10 to 15 minutes to complete, please wait... "
  983. echo
  984. apt-get -y install $software > $LOG
  985. BACK_PID=$!
  986. # Check if package installation is done, print a spinner
  987. spin_i=1
  988. while kill -0 $BACK_PID > /dev/null 2>&1; do
  989. printf "\b${spinner:spin_i++%${#spinner}:1}"
  990. sleep 0.5
  991. done
  992. # Do a blank echo to get the \n back
  993. echo
  994. # Check Installation result
  995. wait $BACK_PID
  996. check_result $? "apt-get install failed"
  997. echo
  998. echo "========================================================================"
  999. echo
  1000. # Install Hestia packages from local folder
  1001. if [ -n "$withdebs" ] && [ -d "$withdebs" ]; then
  1002. echo "[ * ] Installing local package files..."
  1003. echo " - hestia core package"
  1004. dpkg -i $withdebs/hestia_*.deb > /dev/null 2>&1
  1005. if [ -z $(ls $withdebs/hestia-php_*.deb 2> /dev/null) ]; then
  1006. echo " - hestia-php backend package (from apt)"
  1007. apt-get -y install hestia-php > /dev/null 2>&1
  1008. else
  1009. echo " - hestia-php backend package"
  1010. dpkg -i $withdebs/hestia-php_*.deb > /dev/null 2>&1
  1011. fi
  1012. if [ -z $(ls $withdebs/hestia-nginx_*.deb 2> /dev/null) ]; then
  1013. echo " - hestia-nginx backend package (from apt)"
  1014. apt-get -y install hestia-nginx > /dev/null 2>&1
  1015. else
  1016. echo " - hestia-nginx backend package"
  1017. dpkg -i $withdebs/hestia-nginx_*.deb > /dev/null 2>&1
  1018. fi
  1019. if [ "$webterminal" = "yes" ]; then
  1020. if [ -z $(ls $withdebs/hestia-web-terminal_*.deb 2> /dev/null) ]; then
  1021. echo " - hestia-web-terminal package (from apt)"
  1022. apt-get -y install hestia-web-terminal > /dev/null 2>&1
  1023. else
  1024. echo " - hestia-web-terminal"
  1025. dpkg -i $withdebs/hestia-web-terminal_*.deb > /dev/null 2>&1
  1026. fi
  1027. fi
  1028. fi
  1029. # Restoring autostart policy
  1030. rm -f /usr/sbin/policy-rc.d
  1031. #----------------------------------------------------------#
  1032. # Configure system #
  1033. #----------------------------------------------------------#
  1034. echo "[ * ] Configuring system settings..."
  1035. # Generate a random password
  1036. random_password=$(gen_pass '32')
  1037. # Create the new hestiaweb user
  1038. /usr/sbin/useradd "hestiaweb" -c "$email" --no-create-home
  1039. # do not allow login into hestiaweb user
  1040. echo hestiaweb:$random_password | sudo chpasswd -e
  1041. # Add a general group for normal users created by Hestia
  1042. if [ -z "$(grep ^hestia-users: /etc/group)" ]; then
  1043. groupadd --system "hestia-users"
  1044. fi
  1045. # Create user for php-fpm configs
  1046. /usr/sbin/useradd "hestiamail" -c "$email" --no-create-home
  1047. # Ensures proper permissions for Hestia service interactions.
  1048. /usr/sbin/adduser hestiamail hestia-users
  1049. # Enable SFTP subsystem for SSH
  1050. sftp_subsys_enabled=$(grep -iE "^#?.*subsystem.+(sftp )?sftp-server" /etc/ssh/sshd_config)
  1051. if [ -n "$sftp_subsys_enabled" ]; then
  1052. sed -i -E "s/^#?.*Subsystem.+(sftp )?sftp-server/Subsystem sftp internal-sftp/g" /etc/ssh/sshd_config
  1053. fi
  1054. # Reduce SSH login grace time
  1055. sed -i "s/[#]LoginGraceTime [[:digit:]]m/LoginGraceTime 1m/g" /etc/ssh/sshd_config
  1056. # Disable SSH suffix broadcast
  1057. if [ -z "$(grep "^DebianBanner no" /etc/ssh/sshd_config)" ]; then
  1058. sed -i '/^[#]Banner .*/a DebianBanner no' /etc/ssh/sshd_config
  1059. if [ -z "$(grep "^DebianBanner no" /etc/ssh/sshd_config)" ]; then
  1060. # If first attempt fails just add it
  1061. echo '' >> /etc/ssh/sshd_config
  1062. echo 'DebianBanner no' >> /etc/ssh/sshd_config
  1063. fi
  1064. fi
  1065. # Restart SSH daemon
  1066. systemctl restart ssh
  1067. # Disable AWStats cron
  1068. rm -f /etc/cron.d/awstats
  1069. # Replace AWStats function
  1070. cp -f $HESTIA_INSTALL_DIR/logrotate/httpd-prerotate/* /etc/logrotate.d/httpd-prerotate/
  1071. # Set directory color
  1072. if [ -z "$(grep 'LS_COLORS="$LS_COLORS:di=00;33"' /etc/profile)" ]; then
  1073. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  1074. fi
  1075. # Register /usr/sbin/nologin
  1076. if [ -z "$(grep nologin /etc/shells)" ]; then
  1077. echo "/usr/sbin/nologin" >> /etc/shells
  1078. fi
  1079. # Configuring NTP
  1080. sed -i 's/#NTP=/NTP=pool.ntp.org/' /etc/systemd/timesyncd.conf
  1081. systemctl enable systemd-timesyncd
  1082. systemctl start systemd-timesyncd
  1083. # Check iptables paths and add symlinks when necessary
  1084. if [ ! -e "/sbin/iptables" ]; then
  1085. if which iptables > /dev/null; then
  1086. ln -s "$(which iptables)" /sbin/iptables
  1087. elif [ -e "/usr/sbin/iptables" ]; then
  1088. ln -s /usr/sbin/iptables /sbin/iptables
  1089. elif whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables; then
  1090. autoiptables=$(whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables | cut -d '' -f 2)
  1091. if [ -x "$autoiptables" ]; then
  1092. ln -s "$autoiptables" /sbin/iptables
  1093. fi
  1094. fi
  1095. fi
  1096. if [ ! -e "/sbin/iptables-save" ]; then
  1097. if which iptables-save > /dev/null; then
  1098. ln -s "$(which iptables-save)" /sbin/iptables-save
  1099. elif [ -e "/usr/sbin/iptables-save" ]; then
  1100. ln -s /usr/sbin/iptables-save /sbin/iptables-save
  1101. elif whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables-save; then
  1102. autoiptables_save=$(whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables-save | cut -d '' -f 2)
  1103. if [ -x "$autoiptables_save" ]; then
  1104. ln -s "$autoiptables_save" /sbin/iptables-save
  1105. fi
  1106. fi
  1107. fi
  1108. if [ ! -e "/sbin/iptables-restore" ]; then
  1109. if which iptables-restore > /dev/null; then
  1110. ln -s "$(which iptables-restore)" /sbin/iptables-restore
  1111. elif [ -e "/usr/sbin/iptables-restore" ]; then
  1112. ln -s /usr/sbin/iptables-restore /sbin/iptables-restore
  1113. elif whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables-restore; then
  1114. autoiptables_restore=$(whereis -B /bin /sbin /usr/bin /usr/sbin -f -b iptables-restore | cut -d '' -f 2)
  1115. if [ -x "$autoiptables_restore" ]; then
  1116. ln -s "$autoiptables_restore" /sbin/iptables-restore
  1117. fi
  1118. fi
  1119. fi
  1120. # Restrict access to /proc fs
  1121. # Prevent unpriv users from seeing each other running processes
  1122. mount -o remount,defaults,hidepid=2 /proc > /dev/null 2>&1
  1123. if [ $? -ne 0 ]; then
  1124. echo "Info: Cannot remount /proc (LXC containers require additional perm added to host apparmor profile)"
  1125. else
  1126. echo "@reboot root sleep 5 && mount -o remount,defaults,hidepid=2 /proc" > /etc/cron.d/hestia-proc
  1127. fi
  1128. #----------------------------------------------------------#
  1129. # Configure Hestia #
  1130. #----------------------------------------------------------#
  1131. echo "[ * ] Configuring Hestia Control Panel..."
  1132. # Installing sudo configuration
  1133. mkdir -p /etc/sudoers.d
  1134. cp -f $HESTIA_COMMON_DIR/sudo/hestiaweb /etc/sudoers.d/
  1135. chmod 440 /etc/sudoers.d/hestiaweb
  1136. # Add Hestia global config
  1137. if [[ ! -e /etc/hestiacp/hestia.conf ]]; then
  1138. mkdir -p /etc/hestiacp
  1139. 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
  1140. fi
  1141. # Configuring system env
  1142. echo "export HESTIA='$HESTIA'" > /etc/profile.d/hestia.sh
  1143. echo 'PATH=$PATH:'$HESTIA'/bin' >> /etc/profile.d/hestia.sh
  1144. echo 'export PATH' >> /etc/profile.d/hestia.sh
  1145. chmod 755 /etc/profile.d/hestia.sh
  1146. source /etc/profile.d/hestia.sh
  1147. # Configuring logrotate for Hestia logs
  1148. cp -f $HESTIA_INSTALL_DIR/logrotate/hestia /etc/logrotate.d/hestia
  1149. # Create log path and symbolic link
  1150. rm -f /var/log/hestia
  1151. mkdir -p /var/log/hestia
  1152. ln -s /var/log/hestia $HESTIA/log
  1153. # Building directory tree and creating some blank files for Hestia
  1154. mkdir -p $HESTIA/conf $HESTIA/ssl $HESTIA/data/ips \
  1155. $HESTIA/data/queue $HESTIA/data/users $HESTIA/data/firewall \
  1156. $HESTIA/data/sessions
  1157. touch $HESTIA/data/queue/backup.pipe $HESTIA/data/queue/disk.pipe \
  1158. $HESTIA/data/queue/webstats.pipe $HESTIA/data/queue/restart.pipe \
  1159. $HESTIA/data/queue/traffic.pipe $HESTIA/data/queue/daily.pipe $HESTIA/log/system.log \
  1160. $HESTIA/log/nginx-error.log $HESTIA/log/auth.log $HESTIA/log/backup.log
  1161. chmod 750 $HESTIA/conf $HESTIA/data/users $HESTIA/data/ips $HESTIA/log
  1162. chmod -R 750 $HESTIA/data/queue
  1163. chmod 660 /var/log/hestia/*
  1164. chmod 770 $HESTIA/data/sessions
  1165. # Generating Hestia configuration
  1166. rm -f $HESTIA/conf/hestia.conf > /dev/null 2>&1
  1167. touch $HESTIA/conf/hestia.conf
  1168. chmod 660 $HESTIA/conf/hestia.conf
  1169. # Write default port value to hestia.conf
  1170. # If a custom port is specified it will be set at the end of the installation process
  1171. write_config_value "BACKEND_PORT" "8083"
  1172. # Web stack
  1173. if [ "$apache" = 'yes' ]; then
  1174. write_config_value "WEB_SYSTEM" "apache2"
  1175. write_config_value "WEB_RGROUPS" "www-data"
  1176. write_config_value "WEB_PORT" "8080"
  1177. write_config_value "WEB_SSL_PORT" "8443"
  1178. write_config_value "WEB_SSL" "mod_ssl"
  1179. write_config_value "PROXY_SYSTEM" "nginx"
  1180. write_config_value "PROXY_PORT" "80"
  1181. write_config_value "PROXY_SSL_PORT" "443"
  1182. write_config_value "STATS_SYSTEM" "awstats"
  1183. fi
  1184. if [ "$apache" = 'no' ]; then
  1185. write_config_value "WEB_SYSTEM" "nginx"
  1186. write_config_value "WEB_PORT" "80"
  1187. write_config_value "WEB_SSL_PORT" "443"
  1188. write_config_value "WEB_SSL" "openssl"
  1189. write_config_value "STATS_SYSTEM" "awstats"
  1190. fi
  1191. if [ "$phpfpm" = 'yes' ] || [ "$multiphp" = 'yes' ]; then
  1192. write_config_value "WEB_BACKEND" "php-fpm"
  1193. fi
  1194. # Database stack
  1195. if [ "$mysql" = 'yes' ] || [ "$mysql8" = 'yes' ]; then
  1196. installed_db_types='mysql'
  1197. fi
  1198. if [ "$postgresql" = 'yes' ]; then
  1199. installed_db_types="$installed_db_types,pgsql"
  1200. fi
  1201. if [ -n "$installed_db_types" ]; then
  1202. db=$(echo "$installed_db_types" \
  1203. | sed "s/,/\n/g" \
  1204. | sort -r -u \
  1205. | sed "/^$/d" \
  1206. | sed ':a;N;$!ba;s/\n/,/g')
  1207. write_config_value "DB_SYSTEM" "$db"
  1208. fi
  1209. # FTP stack
  1210. if [ "$vsftpd" = 'yes' ]; then
  1211. write_config_value "FTP_SYSTEM" "vsftpd"
  1212. fi
  1213. if [ "$proftpd" = 'yes' ]; then
  1214. write_config_value "FTP_SYSTEM" "proftpd"
  1215. fi
  1216. # DNS stack
  1217. if [ "$named" = 'yes' ]; then
  1218. write_config_value "DNS_SYSTEM" "bind9"
  1219. fi
  1220. # Mail stack
  1221. if [ "$exim" = 'yes' ]; then
  1222. write_config_value "MAIL_SYSTEM" "exim4"
  1223. if [ "$clamd" = 'yes' ]; then
  1224. write_config_value "ANTIVIRUS_SYSTEM" "clamav-daemon"
  1225. fi
  1226. if [ "$spamd" = 'yes' ]; then
  1227. write_config_value "ANTISPAM_SYSTEM" "spamassassin"
  1228. fi
  1229. if [ "$dovecot" = 'yes' ]; then
  1230. write_config_value "IMAP_SYSTEM" "dovecot"
  1231. fi
  1232. if [ "$sieve" = 'yes' ]; then
  1233. write_config_value "SIEVE_SYSTEM" "yes"
  1234. fi
  1235. fi
  1236. # Cron daemon
  1237. write_config_value "CRON_SYSTEM" "cron"
  1238. # Firewall stack
  1239. if [ "$iptables" = 'yes' ]; then
  1240. write_config_value "FIREWALL_SYSTEM" "iptables"
  1241. fi
  1242. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  1243. write_config_value "FIREWALL_EXTENSION" "fail2ban"
  1244. fi
  1245. # Disk quota
  1246. if [ "$quota" = 'yes' ]; then
  1247. write_config_value "DISK_QUOTA" "yes"
  1248. else
  1249. write_config_value "DISK_QUOTA" "no"
  1250. fi
  1251. # Resource limitation
  1252. if [ "$resourcelimit" = 'yes' ]; then
  1253. write_config_value "RESOURCES_LIMIT" "yes"
  1254. else
  1255. write_config_value "RESOURCES_LIMIT" "no"
  1256. fi
  1257. write_config_value "WEB_TERMINAL_PORT" "8085"
  1258. # Backups
  1259. write_config_value "BACKUP_SYSTEM" "local"
  1260. write_config_value "BACKUP_GZIP" "4"
  1261. write_config_value "BACKUP_MODE" "zstd"
  1262. # Language
  1263. write_config_value "LANGUAGE" "$lang"
  1264. # Login screen style
  1265. write_config_value "LOGIN_STYLE" "default"
  1266. # Theme
  1267. write_config_value "THEME" "dark"
  1268. # Inactive session timeout
  1269. write_config_value "INACTIVE_SESSION_TIMEOUT" "60"
  1270. # Version & Release Branch
  1271. write_config_value "VERSION" "${HESTIA_INSTALL_VER}"
  1272. write_config_value "RELEASE_BRANCH" "release"
  1273. # Email notifications after upgrade
  1274. write_config_value "UPGRADE_SEND_EMAIL" "true"
  1275. write_config_value "UPGRADE_SEND_EMAIL_LOG" "false"
  1276. # Set "root" user
  1277. write_config_value "ROOT_USER" "$username"
  1278. # Installing hosting packages
  1279. cp -rf $HESTIA_COMMON_DIR/packages $HESTIA/data/
  1280. # Update nameservers in hosting package
  1281. IFS='.' read -r -a domain_elements <<< "$servername"
  1282. if [ -n "${domain_elements[-2]}" ] && [ -n "${domain_elements[-1]}" ]; then
  1283. serverdomain="${domain_elements[-2]}.${domain_elements[-1]}"
  1284. sed -i s/"domain.tld"/"$serverdomain"/g $HESTIA/data/packages/*.pkg
  1285. fi
  1286. # Installing templates
  1287. cp -rf $HESTIA_INSTALL_DIR/templates $HESTIA/data/
  1288. cp -rf $HESTIA_COMMON_DIR/templates/web/ $HESTIA/data/templates
  1289. cp -rf $HESTIA_COMMON_DIR/templates/dns/ $HESTIA/data/templates
  1290. mkdir -p /var/www/html
  1291. mkdir -p /var/www/document_errors
  1292. # Install default success page
  1293. cp -rf $HESTIA_COMMON_DIR/templates/web/unassigned/index.html /var/www/html/
  1294. cp -rf $HESTIA_COMMON_DIR/templates/web/skel/document_errors/* /var/www/document_errors/
  1295. # Installing firewall rules
  1296. cp -rf $HESTIA_COMMON_DIR/firewall $HESTIA/data/
  1297. rm -f $HESTIA/data/firewall/ipset/blacklist.sh $HESTIA/data/firewall/ipset/blacklist.ipv6.sh
  1298. # Delete rules for services that are not installed
  1299. if [ "$vsftpd" = "no" ] && [ "$proftpd" = "no" ]; then
  1300. # Remove FTP
  1301. sed -i "/COMMENT='FTP'/d" $HESTIA/data/firewall/rules.conf
  1302. fi
  1303. if [ "$exim" = "no" ]; then
  1304. # Remove SMTP
  1305. sed -i "/COMMENT='SMTP'/d" $HESTIA/data/firewall/rules.conf
  1306. fi
  1307. if [ "$dovecot" = "no" ]; then
  1308. # Remove IMAP / Dovecot
  1309. sed -i "/COMMENT='IMAP'/d" $HESTIA/data/firewall/rules.conf
  1310. sed -i "/COMMENT='POP3'/d" $HESTIA/data/firewall/rules.conf
  1311. fi
  1312. if [ "$named" = "no" ]; then
  1313. # Remove IMAP / Dovecot
  1314. sed -i "/COMMENT='DNS'/d" $HESTIA/data/firewall/rules.conf
  1315. fi
  1316. # Installing API
  1317. cp -rf $HESTIA_COMMON_DIR/api $HESTIA/data/
  1318. # Configuring server hostname
  1319. $HESTIA/bin/v-change-sys-hostname $servername > /dev/null 2>&1
  1320. # Configuring global OpenSSL options
  1321. echo "[ * ] Configuring OpenSSL to improve TLS performance..."
  1322. tls13_ciphers="TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384"
  1323. if [ "$release" = "22.04" ]; then
  1324. sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
  1325. elif [ "$release" = "24.04" ]; then
  1326. if ! grep -qw "^ssl_conf = ssl_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
  1327. sed -i '/providers = provider_sect$/a ssl_conf = ssl_sect' /etc/ssl/openssl.cnf
  1328. fi
  1329. if ! grep -qw "^[ssl_sect]$" /etc/ssl/openssl.cnf 2> /dev/null; then
  1330. sed -i '$a \\n[ssl_sect]\nsystem_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
  1331. elif grep -qw "^system_default = system_default_sect$" /etc/ssl/openssl.cnf 2> /dev/null; then
  1332. sed -i '/^system_default = system_default_sect$/a system_default = hestia_openssl_sect\n\n[hestia_openssl_sect]\nCiphersuites = '"$tls13_ciphers"'\nOptions = PrioritizeChaCha' /etc/ssl/openssl.cnf
  1333. fi
  1334. fi
  1335. # Generating SSL certificate
  1336. echo "[ * ] Generating default self-signed SSL certificate..."
  1337. $HESTIA/bin/v-generate-ssl-cert $(hostname) '' 'US' 'California' \
  1338. 'San Francisco' 'Hestia Control Panel' 'IT' > /tmp/hst.pem
  1339. # Parsing certificate file
  1340. crt_end=$(grep -n "END CERTIFICATE-" /tmp/hst.pem | cut -f 1 -d:)
  1341. key_start=$(grep -n "BEGIN RSA" /tmp/hst.pem | cut -f 1 -d:)
  1342. key_end=$(grep -n "END RSA" /tmp/hst.pem | cut -f 1 -d:)
  1343. # Adding SSL certificate
  1344. echo "[ * ] Adding SSL certificate to Hestia Control Panel..."
  1345. cd $HESTIA/ssl
  1346. sed -n "1,${crt_end}p" /tmp/hst.pem > certificate.crt
  1347. sed -n "$key_start,${key_end}p" /tmp/hst.pem > certificate.key
  1348. chown root:mail $HESTIA/ssl/*
  1349. chmod 660 $HESTIA/ssl/*
  1350. rm /tmp/hst.pem
  1351. # Install dhparam.pem
  1352. cp -f $HESTIA_INSTALL_DIR/ssl/dhparam.pem /etc/ssl
  1353. # Enable SFTP jail
  1354. echo "[ * ] Enabling SFTP jail..."
  1355. $HESTIA/bin/v-add-sys-sftp-jail > /dev/null 2>&1
  1356. check_result $? "can't enable sftp jail"
  1357. # Enable SSH jail
  1358. echo "[ * ] Enabling SSH jail..."
  1359. $HESTIA/bin/v-add-sys-ssh-jail > /dev/null 2>&1
  1360. check_result $? "can't enable ssh jail"
  1361. # Adding Hestia admin account
  1362. echo "[ * ] Creating default admin account..."
  1363. $HESTIA/bin/v-add-user $username $vpass $email "default" "System Administrator"
  1364. check_result $? "can't create admin user"
  1365. $HESTIA/bin/v-change-user-shell $username nologin no
  1366. $HESTIA/bin/v-change-user-role $username admin
  1367. $HESTIA/bin/v-change-user-language $username $lang
  1368. $HESTIA/bin/v-change-sys-config-value 'POLICY_SYSTEM_PROTECTED_ADMIN' 'yes'
  1369. #----------------------------------------------------------#
  1370. # Configure Nginx #
  1371. #----------------------------------------------------------#
  1372. echo "[ * ] Configuring NGINX..."
  1373. rm -f /etc/nginx/conf.d/*.conf
  1374. cp -f $HESTIA_INSTALL_DIR/nginx/nginx.conf /etc/nginx/
  1375. cp -f $HESTIA_INSTALL_DIR/nginx/status.conf /etc/nginx/conf.d/
  1376. cp -f $HESTIA_INSTALL_DIR/nginx/0rtt-anti-replay.conf /etc/nginx/conf.d/
  1377. cp -f $HESTIA_INSTALL_DIR/nginx/agents.conf /etc/nginx/conf.d/
  1378. # Copy over cloudflare.inc incase in the next step there are connection issues with CF
  1379. cp -f $HESTIA_INSTALL_DIR/nginx/cloudflare.inc /etc/nginx/conf.d/
  1380. cp -f $HESTIA_INSTALL_DIR/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  1381. cp -f $HESTIA_INSTALL_DIR/nginx/phppgadmin.inc /etc/nginx/conf.d/
  1382. cp -f $HESTIA_INSTALL_DIR/logrotate/nginx /etc/logrotate.d/
  1383. mkdir -p /etc/nginx/conf.d/domains
  1384. mkdir -p /etc/nginx/conf.d/main
  1385. mkdir -p /etc/nginx/modules-enabled
  1386. mkdir -p /var/log/nginx/domains
  1387. # Update dns servers in nginx.conf
  1388. for nameserver in $(grep -is '^nameserver' /etc/resolv.conf | cut -d' ' -f2 | tr '\r\n' ' ' | xargs); do
  1389. if [[ "$nameserver" =~ ^([0-9]{1,3}\.){3}[0-9]{1,3}$ ]]; then
  1390. if [ -z "$resolver" ]; then
  1391. resolver="$nameserver"
  1392. else
  1393. resolver="$resolver $nameserver"
  1394. fi
  1395. fi
  1396. done
  1397. if [ -n "$resolver" ]; then
  1398. sed -i "s/1.0.0.1 8.8.4.4 1.1.1.1 8.8.8.8/$resolver/g" /etc/nginx/nginx.conf
  1399. fi
  1400. # https://github.com/ergin/nginx-cloudflare-real-ip/
  1401. cf_ips="$(curl -fsLm5 --retry 2 https://api.cloudflare.com/client/v4/ips)"
  1402. if [ -n "$cf_ips" ] && [ "$(echo "$cf_ips" | jq -r '.success//""')" = "true" ]; then
  1403. cf_inc="/etc/nginx/conf.d/cloudflare.inc"
  1404. echo "[ * ] Updating Cloudflare IP Ranges for Nginx..."
  1405. echo "# Cloudflare IP Ranges" > $cf_inc
  1406. echo "" >> $cf_inc
  1407. echo "# IPv4" >> $cf_inc
  1408. for ipv4 in $(echo "$cf_ips" | jq -r '.result.ipv4_cidrs[]//""' | sort); do
  1409. echo "set_real_ip_from $ipv4;" >> $cf_inc
  1410. done
  1411. echo "" >> $cf_inc
  1412. echo "# IPv6" >> $cf_inc
  1413. for ipv6 in $(echo "$cf_ips" | jq -r '.result.ipv6_cidrs[]//""' | sort); do
  1414. echo "set_real_ip_from $ipv6;" >> $cf_inc
  1415. done
  1416. echo "" >> $cf_inc
  1417. echo "real_ip_header CF-Connecting-IP;" >> $cf_inc
  1418. fi
  1419. update-rc.d nginx defaults > /dev/null 2>&1
  1420. systemctl start nginx >> $LOG
  1421. check_result $? "nginx start failed"
  1422. #----------------------------------------------------------#
  1423. # Configure Apache #
  1424. #----------------------------------------------------------#
  1425. if [ "$apache" = 'yes' ]; then
  1426. echo "[ * ] Configuring Apache Web Server..."
  1427. mkdir -p /etc/apache2/conf.d
  1428. mkdir -p /etc/apache2/conf.d/domains
  1429. # Copy configuration files
  1430. cp -f $HESTIA_INSTALL_DIR/apache2/apache2.conf /etc/apache2/
  1431. cp -f $HESTIA_INSTALL_DIR/apache2/status.conf /etc/apache2/mods-available/hestia-status.conf
  1432. cp -f /etc/apache2/mods-available/status.load /etc/apache2/mods-available/hestia-status.load
  1433. cp -f $HESTIA_INSTALL_DIR/logrotate/apache2 /etc/logrotate.d/
  1434. # Enable needed modules
  1435. a2enmod rewrite > /dev/null 2>&1
  1436. a2enmod suexec > /dev/null 2>&1
  1437. a2enmod ssl > /dev/null 2>&1
  1438. a2enmod actions > /dev/null 2>&1
  1439. a2enmod headers > /dev/null 2>&1
  1440. a2dismod --quiet status > /dev/null 2>&1
  1441. a2enmod --quiet hestia-status > /dev/null 2>&1
  1442. # Enable mod_ruid/mpm_itk or mpm_event
  1443. if [ "$phpfpm" = 'yes' ]; then
  1444. # Disable prefork and php, enable event
  1445. a2dismod php$fpm_v > /dev/null 2>&1
  1446. a2dismod mpm_prefork > /dev/null 2>&1
  1447. a2enmod mpm_event > /dev/null 2>&1
  1448. cp -f $HESTIA_INSTALL_DIR/apache2/hestia-event.conf /etc/apache2/conf.d/
  1449. else
  1450. a2enmod ruid2 > /dev/null 2>&1
  1451. fi
  1452. echo "# Powered by hestia" > /etc/apache2/sites-available/default
  1453. echo "# Powered by hestia" > /etc/apache2/sites-available/default-ssl
  1454. echo "# Powered by hestia" > /etc/apache2/ports.conf
  1455. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  1456. touch /var/log/apache2/access.log /var/log/apache2/error.log
  1457. mkdir -p /var/log/apache2/domains
  1458. chmod a+x /var/log/apache2
  1459. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  1460. chmod 751 /var/log/apache2/domains
  1461. # Prevent remote access to server-status page
  1462. sed -i '/Allow from all/d' /etc/apache2/mods-available/hestia-status.conf
  1463. update-rc.d apache2 defaults > /dev/null 2>&1
  1464. systemctl start apache2 >> $LOG
  1465. check_result $? "apache2 start failed"
  1466. else
  1467. update-rc.d apache2 disable > /dev/null 2>&1
  1468. systemctl stop apache2 > /dev/null 2>&1
  1469. fi
  1470. #----------------------------------------------------------#
  1471. # Configure PHP-FPM #
  1472. #----------------------------------------------------------#
  1473. if [ "$phpfpm" = "yes" ]; then
  1474. if [ "$multiphp" = 'yes' ]; then
  1475. for v in "${multiphp_v[@]}"; do
  1476. echo "[ * ] Installing PHP $v..."
  1477. $HESTIA/bin/v-add-web-php "$v" > /dev/null 2>&1
  1478. done
  1479. else
  1480. echo "[ * ] Installing PHP $fpm_v..."
  1481. $HESTIA/bin/v-add-web-php "$fpm_v" > /dev/null 2>&1
  1482. fi
  1483. echo "[ * ] Configuring PHP-FPM $fpm_v..."
  1484. # Create www.conf for webmail and php(*)admin
  1485. cp -f $HESTIA_INSTALL_DIR/php-fpm/www.conf /etc/php/$fpm_v/fpm/pool.d/www.conf
  1486. update-rc.d php$fpm_v-fpm defaults > /dev/null 2>&1
  1487. systemctl start php$fpm_v-fpm >> $LOG
  1488. check_result $? "php-fpm start failed"
  1489. # Set default php version to $fpm_v
  1490. update-alternatives --set php /usr/bin/php$fpm_v > /dev/null 2>&1
  1491. fi
  1492. #----------------------------------------------------------#
  1493. # Configure PHP #
  1494. #----------------------------------------------------------#
  1495. echo "[ * ] Configuring PHP..."
  1496. ZONE=$(timedatectl > /dev/null 2>&1 | grep Timezone | awk '{print $2}')
  1497. if [ -z "$ZONE" ]; then
  1498. ZONE='UTC'
  1499. fi
  1500. for pconf in $(find /etc/php* -name php.ini); do
  1501. sed -i "s%;date.timezone =%date.timezone = $ZONE%g" $pconf
  1502. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  1503. done
  1504. # Cleanup php session files not changed in the last 7 days (60*24*7 minutes)
  1505. echo '#!/bin/sh' > /etc/cron.daily/php-session-cleanup
  1506. 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
  1507. 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
  1508. chmod 755 /etc/cron.daily/php-session-cleanup
  1509. #----------------------------------------------------------#
  1510. # Configure Vsftpd #
  1511. #----------------------------------------------------------#
  1512. if [ "$vsftpd" = 'yes' ]; then
  1513. echo "[ * ] Configuring Vsftpd server..."
  1514. cp -f $HESTIA_INSTALL_DIR/vsftpd/vsftpd.conf /etc/
  1515. touch /var/log/vsftpd.log
  1516. chown root:adm /var/log/vsftpd.log
  1517. chmod 640 /var/log/vsftpd.log
  1518. touch /var/log/xferlog
  1519. chown root:adm /var/log/xferlog
  1520. chmod 640 /var/log/xferlog
  1521. if [ -s /etc/logrotate.d/vsftpd ] && ! grep -Fq "/var/log/xferlog" /etc/logrotate.d/vsftpd; then
  1522. sed -i 's|/var/log/vsftpd.log|/var/log/vsftpd.log /var/log/xferlog|g' /etc/logrotate.d/vsftpd
  1523. fi
  1524. update-rc.d vsftpd defaults > /dev/null 2>&1
  1525. systemctl start vsftpd >> $LOG
  1526. check_result $? "vsftpd start failed"
  1527. fi
  1528. #----------------------------------------------------------#
  1529. # Configure ProFTPD #
  1530. #----------------------------------------------------------#
  1531. if [ "$proftpd" = 'yes' ]; then
  1532. echo "[ * ] Configuring ProFTPD server..."
  1533. echo "127.0.0.1 $servername" >> /etc/hosts
  1534. cp -f $HESTIA_INSTALL_DIR/proftpd/proftpd.conf /etc/proftpd/
  1535. cp -f $HESTIA_INSTALL_DIR/proftpd/tls.conf /etc/proftpd/
  1536. update-rc.d proftpd defaults > /dev/null 2>&1
  1537. systemctl start proftpd >> $LOG
  1538. check_result $? "proftpd start failed"
  1539. unit_files="$(systemctl list-unit-files | grep proftpd)"
  1540. if [[ "$unit_files" =~ "disabled" ]]; then
  1541. systemctl enable proftpd
  1542. fi
  1543. fi
  1544. #----------------------------------------------------------#
  1545. # Configure MariaDB / MySQL #
  1546. #----------------------------------------------------------#
  1547. if [ "$mysql" = 'yes' ] || [ "$mysql8" = 'yes' ]; then
  1548. [ "$mysql" = 'yes' ] && mysql_type="MariaDB" || mysql_type="MySQL"
  1549. echo "[ * ] Configuring $mysql_type database server..."
  1550. mycnf="my-small.cnf"
  1551. if [ $memory -gt 1200000 ]; then
  1552. mycnf="my-medium.cnf"
  1553. fi
  1554. if [ $memory -gt 3900000 ]; then
  1555. mycnf="my-large.cnf"
  1556. fi
  1557. if [ "$mysql_type" = 'MariaDB' ]; then
  1558. # Run mariadb-install-db
  1559. mariadb-install-db >> $LOG
  1560. fi
  1561. # Remove symbolic link
  1562. rm -f /etc/mysql/my.cnf
  1563. # Configuring MariaDB
  1564. cp -f $HESTIA_INSTALL_DIR/mysql/$mycnf /etc/mysql/my.cnf
  1565. # Switch MariaDB inclusions to the MySQL
  1566. if [ "$mysql_type" = 'MySQL' ]; then
  1567. sed -i '/query_cache_size/d' /etc/mysql/my.cnf
  1568. sed -i 's|mariadb.conf.d|mysql.conf.d|g' /etc/mysql/my.cnf
  1569. fi
  1570. if [ "$mysql_type" = 'MariaDB' ]; then
  1571. sed -i 's|/usr/share/mysql|/usr/share/mariadb|g' /etc/mysql/my.cnf
  1572. update-rc.d mariadb defaults > /dev/null 2>&1
  1573. systemctl -q enable mariadb 2> /dev/null
  1574. systemctl start mariadb >> $LOG
  1575. check_result $? "${mysql_type,,} start failed"
  1576. fi
  1577. if [ "$mysql_type" = 'MySQL' ]; then
  1578. update-rc.d mysql defaults > /dev/null 2>&1
  1579. systemctl -q enable mysql 2> /dev/null
  1580. systemctl start mysql >> $LOG
  1581. check_result $? "${mysql_type,,} start failed"
  1582. fi
  1583. # Securing MariaDB/MySQL installation
  1584. mpass=$(gen_pass)
  1585. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  1586. chmod 600 /root/.my.cnf
  1587. if [ -f '/usr/bin/mariadb' ]; then
  1588. mysql_server="mariadb"
  1589. else
  1590. mysql_server="mysql"
  1591. fi
  1592. # Alter root password
  1593. $mysql_server -e "ALTER USER 'root'@'localhost' IDENTIFIED BY '$mpass'; FLUSH PRIVILEGES;"
  1594. if [ "$mysql_type" = 'MariaDB' ]; then
  1595. # Allow mysql access via socket for startup
  1596. $mysql_server -e "UPDATE mysql.global_priv SET priv=json_set(priv, '$.password_last_changed', UNIX_TIMESTAMP(), '$.plugin', 'mysql_native_password', '$.authentication_string', 'invalid', '$.auth_or', json_array(json_object(), json_object('plugin', 'unix_socket'))) WHERE User='root';"
  1597. # Disable anonymous users
  1598. $mysql_server -e "DELETE FROM mysql.global_priv WHERE User='';"
  1599. else
  1600. $mysql_server -e "ALTER USER 'root'@'localhost' IDENTIFIED WITH caching_sha2_password BY '$mpass';"
  1601. $mysql_server -e "DELETE FROM mysql.user WHERE User='';"
  1602. $mysql_server -e "DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');"
  1603. fi
  1604. # Drop test database
  1605. $mysql_server -e "DROP DATABASE IF EXISTS test"
  1606. $mysql_server -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  1607. # Flush privileges
  1608. $mysql_server -e "FLUSH PRIVILEGES;"
  1609. fi
  1610. #----------------------------------------------------------#
  1611. # Configure phpMyAdmin #
  1612. #----------------------------------------------------------#
  1613. # Source upgrade.conf with phpmyadmin versions
  1614. # shellcheck source=/usr/local/hestia/install/upgrade/upgrade.conf
  1615. source $HESTIA/install/upgrade/upgrade.conf
  1616. if [ "$mysql" = 'yes' ] || [ "$mysql8" = 'yes' ]; then
  1617. # Display upgrade information
  1618. echo "[ * ] Installing phpMyAdmin version v$pma_v..."
  1619. # Download latest phpmyadmin release
  1620. wget --quiet --retry-connrefused https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  1621. # Unpack files
  1622. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  1623. # Create folders
  1624. mkdir -p /usr/share/phpmyadmin
  1625. mkdir -p /etc/phpmyadmin
  1626. mkdir -p /etc/phpmyadmin/conf.d/
  1627. mkdir /usr/share/phpmyadmin/tmp
  1628. # Configuring Apache2 for PHPMYADMIN
  1629. if [ "$apache" = 'yes' ]; then
  1630. touch /etc/apache2/conf.d/phpmyadmin.inc
  1631. fi
  1632. # Overwrite old files
  1633. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  1634. # Create copy of config file
  1635. cp -f $HESTIA_INSTALL_DIR/phpmyadmin/config.inc.php /etc/phpmyadmin/
  1636. # Set config and log directory
  1637. sed -i "s|'configFile' => ROOT_PATH . 'config.inc.php',|'configFile' => '/etc/phpmyadmin/config.inc.php',|g" /usr/share/phpmyadmin/libraries/vendor_config.php
  1638. # Create temporary folder and change permission
  1639. mkdir -p /var/lib/phpmyadmin/tmp
  1640. chmod 770 /var/lib/phpmyadmin/tmp
  1641. chown -R hestiamail:www-data /usr/share/phpmyadmin/tmp/
  1642. # Generate blow fish
  1643. blowfish=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 32)
  1644. sed -i "s|%blowfish_secret%|$blowfish|" /etc/phpmyadmin/config.inc.php
  1645. # Clean Up
  1646. rm -fr phpMyAdmin-$pma_v-all-languages
  1647. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  1648. write_config_value "DB_PMA_ALIAS" "phpmyadmin"
  1649. $HESTIA/bin/v-change-sys-db-alias 'pma' "phpmyadmin"
  1650. # Special thanks to Pavel Galkin (https://skurudo.ru)
  1651. # https://github.com/skurudo/phpmyadmin-fixer
  1652. # shellcheck source=/usr/local/hestia/install/deb/phpmyadmin/pma.sh
  1653. source $HESTIA_INSTALL_DIR/phpmyadmin/pma.sh > /dev/null 2>&1
  1654. # Limit access to /etc/phpmyadmin/
  1655. chown -R root:hestiamail /etc/phpmyadmin/
  1656. chmod 640 /etc/phpmyadmin/config.inc.php
  1657. chmod 750 /etc/phpmyadmin/conf.d/
  1658. fi
  1659. #----------------------------------------------------------#
  1660. # Configure PostgreSQL #
  1661. #----------------------------------------------------------#
  1662. if [ "$postgresql" = 'yes' ]; then
  1663. echo "[ * ] Configuring PostgreSQL database server..."
  1664. ppass=$(gen_pass)
  1665. cp -f $HESTIA_INSTALL_DIR/postgresql/pg_hba.conf /etc/postgresql/*/main/
  1666. systemctl restart postgresql
  1667. sudo -iu postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'" > /dev/null 2>&1
  1668. mkdir -p /etc/phppgadmin/
  1669. mkdir -p /usr/share/phppgadmin/
  1670. wget --retry-connrefused --quiet https://github.com/hestiacp/phppgadmin/releases/download/v$pga_v/phppgadmin-v$pga_v.tar.gz
  1671. tar xzf phppgadmin-v$pga_v.tar.gz -C /usr/share/phppgadmin/
  1672. cp -f $HESTIA_INSTALL_DIR/pga/config.inc.php /etc/phppgadmin/
  1673. ln -s /etc/phppgadmin/config.inc.php /usr/share/phppgadmin/conf/
  1674. # Configuring phpPgAdmin
  1675. if [ "$apache" = 'yes' ]; then
  1676. cp -f $HESTIA_INSTALL_DIR/pga/phppgadmin.conf /etc/apache2/conf.d/phppgadmin.inc
  1677. fi
  1678. rm phppgadmin-v$pga_v.tar.gz
  1679. write_config_value "DB_PGA_ALIAS" "phppgadmin"
  1680. $HESTIA/bin/v-change-sys-db-alias 'pga' "phppgadmin"
  1681. # Limit access to /etc/phppgadmin/
  1682. chown -R root:hestiamail /etc/phppgadmin/
  1683. chmod 640 /etc/phppgadmin/config.inc.php
  1684. fi
  1685. #----------------------------------------------------------#
  1686. # Configure Bind #
  1687. #----------------------------------------------------------#
  1688. if [ "$named" = 'yes' ]; then
  1689. echo "[ * ] Configuring Bind DNS server..."
  1690. cp -f $HESTIA_INSTALL_DIR/bind/named.conf /etc/bind/
  1691. cp -f $HESTIA_INSTALL_DIR/bind/named.conf.options /etc/bind/
  1692. chown root:bind /etc/bind/named.conf
  1693. chown root:bind /etc/bind/named.conf.options
  1694. chown bind:bind /var/cache/bind
  1695. chmod 640 /etc/bind/named.conf
  1696. chmod 640 /etc/bind/named.conf.options
  1697. aa-complain /usr/sbin/named > /dev/null 2>&1
  1698. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2> /dev/null
  1699. if ! grep --quiet lxc /proc/1/environ; then
  1700. systemctl status apparmor > /dev/null 2>&1
  1701. if [ $? -ne 0 ]; then
  1702. systemctl restart apparmor >> $LOG
  1703. fi
  1704. fi
  1705. update-rc.d bind9 defaults > /dev/null 2>&1
  1706. systemctl start bind9
  1707. check_result $? "bind9 start failed"
  1708. # Workaround for OpenVZ/Virtuozzo
  1709. if [ -e "/proc/vz/veinfo" ] && [ -e "/etc/rc.local" ]; then
  1710. sed -i "s/^exit 0/service bind9 restart\nexit 0/" /etc/rc.local
  1711. fi
  1712. fi
  1713. #----------------------------------------------------------#
  1714. # Configure Exim #
  1715. #----------------------------------------------------------#
  1716. if [ "$exim" = 'yes' ]; then
  1717. echo "[ * ] Configuring Exim mail server..."
  1718. gpasswd -a Debian-exim mail > /dev/null 2>&1
  1719. exim_version=$(exim4 --version | head -1 | awk '{print $3}' | cut -f -2 -d .)
  1720. # if Exim version > 4.9.4 or greater!
  1721. if ! version_ge "4.94" "$exim_version"; then
  1722. # Ubuntu 22.04 (Jammy) uses Exim 4.95 instead but config works with Exim4.94
  1723. cp -f $HESTIA_INSTALL_DIR/exim/exim4.conf.4.95.template /etc/exim4/exim4.conf.template
  1724. else
  1725. cp -f $HESTIA_INSTALL_DIR/exim/exim4.conf.template /etc/exim4/
  1726. fi
  1727. cp -f $HESTIA_INSTALL_DIR/exim/dnsbl.conf /etc/exim4/
  1728. cp -f $HESTIA_INSTALL_DIR/exim/spam-blocks.conf /etc/exim4/
  1729. cp -f $HESTIA_INSTALL_DIR/exim/limit.conf /etc/exim4/
  1730. cp -f $HESTIA_INSTALL_DIR/exim/system.filter /etc/exim4/
  1731. touch /etc/exim4/white-blocks.conf
  1732. if [ "$spamd" = 'yes' ]; then
  1733. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  1734. fi
  1735. if [ "$clamd" = 'yes' ]; then
  1736. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  1737. fi
  1738. # Generate SRS KEY If not support just created it will get ignored anyway
  1739. srs=$(gen_pass)
  1740. echo $srs > /etc/exim4/srs.conf
  1741. chmod 640 /etc/exim4/srs.conf
  1742. chmod 640 /etc/exim4/exim4.conf.template
  1743. chown root:Debian-exim /etc/exim4/srs.conf
  1744. rm -rf /etc/exim4/domains
  1745. mkdir -p /etc/exim4/domains
  1746. rm -f /etc/alternatives/mta
  1747. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  1748. update-rc.d -f sendmail remove > /dev/null 2>&1
  1749. systemctl stop sendmail > /dev/null 2>&1
  1750. update-rc.d -f postfix remove > /dev/null 2>&1
  1751. systemctl stop postfix > /dev/null 2>&1
  1752. update-rc.d exim4 defaults
  1753. systemctl start exim4 >> $LOG
  1754. check_result $? "exim4 start failed"
  1755. fi
  1756. #----------------------------------------------------------#
  1757. # Configure Dovecot #
  1758. #----------------------------------------------------------#
  1759. if [ "$dovecot" = 'yes' ]; then
  1760. echo "[ * ] Configuring Dovecot POP/IMAP mail server..."
  1761. gpasswd -a dovecot mail > /dev/null 2>&1
  1762. cp -rf $HESTIA_COMMON_DIR/dovecot /etc/
  1763. cp -f $HESTIA_INSTALL_DIR/logrotate/dovecot /etc/logrotate.d/
  1764. rm -f /etc/dovecot/conf.d/15-mailboxes.conf
  1765. chown -R root:root /etc/dovecot*
  1766. touch /var/log/dovecot.log
  1767. chown -R dovecot:mail /var/log/dovecot.log
  1768. chmod 660 /var/log/dovecot.log
  1769. # Alter config for 2.2
  1770. version=$(dovecot --version | cut -f -2 -d .)
  1771. if [ "$version" = "2.2" ]; then
  1772. echo "[ * ] Downgrade dovecot config to sync with 2.2 settings"
  1773. sed -i 's|#ssl_dh_parameters_length = 4096|ssl_dh_parameters_length = 4096|g' /etc/dovecot/conf.d/10-ssl.conf
  1774. sed -i 's|ssl_dh = </etc/ssl/dhparam.pem|#ssl_dh = </etc/ssl/dhparam.pem|g' /etc/dovecot/conf.d/10-ssl.conf
  1775. sed -i 's|ssl_min_protocol = TLSv1.2|ssl_protocols = !SSLv3 !TLSv1 !TLSv1.1|g' /etc/dovecot/conf.d/10-ssl.conf
  1776. fi
  1777. update-rc.d dovecot defaults
  1778. systemctl start dovecot >> $LOG
  1779. check_result $? "dovecot start failed"
  1780. fi
  1781. #----------------------------------------------------------#
  1782. # Configure ClamAV #
  1783. #----------------------------------------------------------#
  1784. if [ "$clamd" = 'yes' ]; then
  1785. gpasswd -a clamav mail > /dev/null 2>&1
  1786. gpasswd -a clamav Debian-exim > /dev/null 2>&1
  1787. cp -f $HESTIA_INSTALL_DIR/clamav/clamd.conf /etc/clamav/
  1788. update-rc.d clamav-daemon defaults
  1789. echo -ne "[ * ] Installing ClamAV anti-virus definitions... "
  1790. /usr/bin/freshclam >> $LOG > /dev/null 2>&1
  1791. BACK_PID=$!
  1792. spin_i=1
  1793. while kill -0 $BACK_PID > /dev/null 2>&1; do
  1794. printf "\b${spinner:spin_i++%${#spinner}:1}"
  1795. sleep 0.5
  1796. done
  1797. echo
  1798. systemctl start clamav-daemon >> $LOG
  1799. check_result $? "clamav-daemon start failed"
  1800. fi
  1801. #----------------------------------------------------------#
  1802. # Configure SpamAssassin #
  1803. #----------------------------------------------------------#
  1804. if [ "$spamd" = 'yes' ]; then
  1805. # Set SpamAssassin Service Name
  1806. if [ "$release" = '24.04' ]; then
  1807. spamd_srvname="spamd"
  1808. else
  1809. spamd_srvname="spamassassin"
  1810. fi
  1811. echo "[ * ] Configuring SpamAssassin..."
  1812. update-rc.d $spamd_srvname defaults > /dev/null 2>&1
  1813. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/$spamd_srvname
  1814. systemctl start $spamd_srvname >> $LOG
  1815. check_result $? "$spamd_srvname start failed"
  1816. unit_files="$(systemctl list-unit-files | grep spamassassin)"
  1817. if [[ "$unit_files" =~ "disabled" ]]; then
  1818. systemctl enable $spamd_srvname > /dev/null 2>&1
  1819. fi
  1820. sed -i "s/#CRON=1/CRON=1/" /etc/default/$spamd_srvname
  1821. fi
  1822. #----------------------------------------------------------#
  1823. # Configure Fail2Ban #
  1824. #----------------------------------------------------------#
  1825. if [ "$fail2ban" = 'yes' ]; then
  1826. echo "[ * ] Configuring fail2ban access monitor..."
  1827. cp -rf $HESTIA_INSTALL_DIR/fail2ban /etc/
  1828. if [ "$dovecot" = 'no' ]; then
  1829. fline=$(cat /etc/fail2ban/jail.local | grep -n dovecot-iptables -A 2)
  1830. fline=$(echo "$fline" | grep enabled | tail -n1 | cut -f 1 -d -)
  1831. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1832. fi
  1833. if [ "$exim" = 'no' ]; then
  1834. fline=$(cat /etc/fail2ban/jail.local | grep -n exim-iptables -A 2)
  1835. fline=$(echo "$fline" | grep enabled | tail -n1 | cut -f 1 -d -)
  1836. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1837. fi
  1838. if [ "$vsftpd" = 'yes' ]; then
  1839. # Create vsftpd Log File
  1840. if [ ! -f "/var/log/vsftpd.log" ]; then
  1841. touch /var/log/vsftpd.log
  1842. fi
  1843. fline=$(cat /etc/fail2ban/jail.local | grep -n vsftpd-iptables -A 2)
  1844. fline=$(echo "$fline" | grep enabled | tail -n1 | cut -f 1 -d -)
  1845. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1846. fi
  1847. if [ -f /etc/fail2ban/jail.d/defaults-debian.conf ]; then
  1848. rm -f /etc/fail2ban/jail.d/defaults-debian.conf
  1849. fi
  1850. update-rc.d fail2ban defaults
  1851. # Ubuntu 22.04 doesn't start F2B by default on boot
  1852. update-rc.d fail2ban enable
  1853. systemctl start fail2ban >> $LOG
  1854. check_result $? "fail2ban start failed"
  1855. fi
  1856. # Configuring MariaDB/MySQL host
  1857. if [ "$mysql" = 'yes' ] || [ "$mysql8" = 'yes' ]; then
  1858. $HESTIA/bin/v-add-database-host mysql localhost root $mpass
  1859. fi
  1860. # Configuring PostgreSQL host
  1861. if [ "$postgresql" = 'yes' ]; then
  1862. $HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
  1863. fi
  1864. #----------------------------------------------------------#
  1865. # Install Roundcube #
  1866. #----------------------------------------------------------#
  1867. # Min requirements Dovecot + Exim + Mysql
  1868. if ([ "$mysql" == 'yes' ] || [ "$mysql8" == 'yes' ]) && [ "$dovecot" == "yes" ]; then
  1869. echo "[ * ] Installing Roundcube..."
  1870. $HESTIA/bin/v-add-sys-roundcube
  1871. write_config_value "WEBMAIL_ALIAS" "webmail"
  1872. else
  1873. write_config_value "WEBMAIL_ALIAS" ""
  1874. write_config_value "WEBMAIL_SYSTEM" ""
  1875. fi
  1876. #----------------------------------------------------------#
  1877. # Install Sieve #
  1878. #----------------------------------------------------------#
  1879. # Min requirements Dovecot + Exim + Mysql + Roundcube
  1880. if [ "$sieve" = 'yes' ]; then
  1881. # Folder paths
  1882. RC_INSTALL_DIR="/var/lib/roundcube"
  1883. RC_CONFIG_DIR="/etc/roundcube"
  1884. echo "[ * ] Installing Sieve Mail Filter..."
  1885. # dovecot.conf install
  1886. sed -i "s/namespace/service stats \{\n unix_listener stats-writer \{\n group = mail\n mode = 0660\n user = dovecot\n \}\n\}\n\nnamespace/g" /etc/dovecot/dovecot.conf
  1887. # Dovecot conf files
  1888. # 10-master.conf
  1889. sed -i -E -z "s/ }\n user = dovecot\n}/ \}\n unix_listener auth-master \{\n group = mail\n mode = 0660\n user = dovecot\n \}\n user = dovecot\n\}/g" /etc/dovecot/conf.d/10-master.conf
  1890. # 15-lda.conf
  1891. sed -i "s/\#mail_plugins = \\\$mail_plugins/mail_plugins = \$mail_plugins quota sieve\n auth_socket_path = \/var\/run\/dovecot\/auth-master/g" /etc/dovecot/conf.d/15-lda.conf
  1892. # 20-imap.conf
  1893. sed -i "s/mail_plugins = quota imap_quota/mail_plugins = quota imap_quota imap_sieve/g" /etc/dovecot/conf.d/20-imap.conf
  1894. # Replace dovecot-sieve config files
  1895. cp -f $HESTIA_COMMON_DIR/dovecot/sieve/* /etc/dovecot/conf.d
  1896. # Dovecot default file install
  1897. echo -e "require [\"fileinto\"];\n# rule:[SPAM]\nif header :contains \"X-Spam-Flag\" \"YES\" {\n fileinto \"INBOX.Spam\";\n}\n" > /etc/dovecot/sieve/default
  1898. # exim4 install
  1899. sed -i "s/\stransport = local_delivery/ transport = dovecot_virtual_delivery/" /etc/exim4/exim4.conf.template
  1900. sed -i "s/address_pipe:/dovecot_virtual_delivery:\n driver = pipe\n command = \/usr\/lib\/dovecot\/dovecot-lda -e -d \${extract{1}{:}{\${lookup{\$local_part}lsearch{\/etc\/exim4\/domains\/\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\/accounts}}}}@\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\n delivery_date_add\n envelope_to_add\n return_path_add\n log_output = true\n log_defer_output = true\n user = \${extract{2}{:}{\${lookup{\$local_part}lsearch{\/etc\/exim4\/domains\/\${lookup{\$domain}dsearch{\/etc\/exim4\/domains\/}}\/passwd}}}}\n group = mail\n return_output\n\naddress_pipe:/g" /etc/exim4/exim4.conf.template
  1901. # Permission changes
  1902. touch /var/log/dovecot.log
  1903. chown -R dovecot:mail /var/log/dovecot.log
  1904. chmod 660 /var/log/dovecot.log
  1905. if [ -d "/var/lib/roundcube" ]; then
  1906. # Modify Roundcube config
  1907. mkdir -p $RC_CONFIG_DIR/plugins/managesieve
  1908. cp -f $HESTIA_COMMON_DIR/roundcube/plugins/config_managesieve.inc.php $RC_CONFIG_DIR/plugins/managesieve/config.inc.php
  1909. ln -s $RC_CONFIG_DIR/plugins/managesieve/config.inc.php $RC_INSTALL_DIR/plugins/managesieve/config.inc.php
  1910. chown -R hestiamail:www-data $RC_CONFIG_DIR/
  1911. chmod 751 -R $RC_CONFIG_DIR
  1912. chmod 644 $RC_CONFIG_DIR/*.php
  1913. chmod 644 $RC_CONFIG_DIR/plugins/managesieve/config.inc.php
  1914. sed -i "s/\"archive\"/\"archive\", \"managesieve\"/g" $RC_CONFIG_DIR/config.inc.php
  1915. chmod 640 $RC_CONFIG_DIR/config.inc.php
  1916. fi
  1917. # Restart Dovecot and Exim4
  1918. systemctl restart dovecot > /dev/null 2>&1
  1919. systemctl restart exim4 > /dev/null 2>&1
  1920. fi
  1921. #----------------------------------------------------------#
  1922. # Configure API #
  1923. #----------------------------------------------------------#
  1924. if [ "$api" = "yes" ]; then
  1925. # Keep legacy api enabled until transition is complete
  1926. write_config_value "API" "yes"
  1927. write_config_value "API_SYSTEM" "1"
  1928. write_config_value "API_ALLOWED_IP" ""
  1929. else
  1930. write_config_value "API" "no"
  1931. write_config_value "API_SYSTEM" "0"
  1932. write_config_value "API_ALLOWED_IP" ""
  1933. $HESTIA/bin/v-change-sys-api disable
  1934. fi
  1935. #----------------------------------------------------------#
  1936. # Configure File Manager #
  1937. #----------------------------------------------------------#
  1938. echo "[ * ] Configuring File Manager..."
  1939. $HESTIA/bin/v-add-sys-filemanager quiet
  1940. #----------------------------------------------------------#
  1941. # Configure Web terminal #
  1942. #----------------------------------------------------------#
  1943. # Web terminal
  1944. if [ "$webterminal" = 'yes' ]; then
  1945. write_config_value "WEB_TERMINAL" "true"
  1946. systemctl daemon-reload > /dev/null 2>&1
  1947. systemctl enable hestia-web-terminal > /dev/null 2>&1
  1948. systemctl restart hestia-web-terminal > /dev/null 2>&1
  1949. else
  1950. write_config_value "WEB_TERMINAL" "false"
  1951. fi
  1952. #----------------------------------------------------------#
  1953. # Configure dependencies #
  1954. #----------------------------------------------------------#
  1955. echo "[ * ] Configuring PHP dependencies..."
  1956. $HESTIA/bin/v-add-sys-dependencies quiet
  1957. echo "[ * ] Installing Rclone & Update Restic ..."
  1958. curl -s https://rclone.org/install.sh | bash > /dev/null 2>&1
  1959. restic self-update > /dev/null 2>&1
  1960. #----------------------------------------------------------#
  1961. # Configure IP #
  1962. #----------------------------------------------------------#
  1963. # Configuring system IPs
  1964. echo "[ * ] Configuring System IP..."
  1965. $HESTIA/bin/v-update-sys-ip > /dev/null 2>&1
  1966. # Get primary IP
  1967. default_nic="$(ip -d -j route show | jq -r '.[] | if .dst == "default" then .dev else empty end')"
  1968. # IPv4
  1969. primary_ipv4="$(ip -4 -d -j addr show "$default_nic" | jq -r '.[] | select(length > 0) | .addr_info[] | if .scope == "global" then .local else empty end' | head -n1)"
  1970. # IPv6
  1971. #primary_ipv6="$(ip -6 -d -j addr show "$default_nic" | jq -r '.[] | select(length > 0) | .addr_info[] | if .scope == "global" then .local else empty end' | head -n1)"
  1972. ip="$primary_ipv4"
  1973. local_ip="$primary_ipv4"
  1974. # Configuring firewall
  1975. if [ "$iptables" = 'yes' ]; then
  1976. $HESTIA/bin/v-update-firewall
  1977. fi
  1978. # Get public IP
  1979. pub_ipv4="$(curl -fsLm5 --retry 2 --ipv4 https://ip.hestiacp.com/)"
  1980. if [ -n "$pub_ipv4" ] && [ "$pub_ipv4" != "$ip" ]; then
  1981. if [ -e /etc/rc.local ]; then
  1982. sed -i '/exit 0/d' /etc/rc.local
  1983. else
  1984. touch /etc/rc.local
  1985. fi
  1986. check_rclocal=$(cat /etc/rc.local | grep "#!")
  1987. if [ -z "$check_rclocal" ]; then
  1988. echo "#!/bin/sh" >> /etc/rc.local
  1989. fi
  1990. # Fix for Proxmox VE containers where hostname is reset to non-FQDN format on reboot
  1991. check_pve=$(uname -r | grep pve)
  1992. if [ ! -z "$check_pve" ]; then
  1993. echo 'hostname=$(hostname --fqdn)' >> /etc/rc.local
  1994. echo ""$HESTIA/bin/v-change-sys-hostname" "'"$hostname"'"" >> /etc/rc.local
  1995. fi
  1996. echo "$HESTIA/bin/v-update-sys-ip" >> /etc/rc.local
  1997. echo "exit 0" >> /etc/rc.local
  1998. chmod +x /etc/rc.local
  1999. systemctl enable rc-local > /dev/null 2>&1
  2000. $HESTIA/bin/v-change-sys-ip-nat "$ip" "$pub_ipv4" > /dev/null 2>&1
  2001. ip="$pub_ipv4"
  2002. fi
  2003. # Configuring libapache2-mod-remoteip
  2004. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ]; then
  2005. cd /etc/apache2/mods-available
  2006. echo "<IfModule mod_remoteip.c>" > remoteip.conf
  2007. echo " RemoteIPHeader X-Real-IP" >> remoteip.conf
  2008. if [ "$local_ip" != "127.0.0.1" ] && [ "$pub_ipv4" != "127.0.0.1" ]; then
  2009. echo " RemoteIPInternalProxy 127.0.0.1" >> remoteip.conf
  2010. fi
  2011. if [ -n "$local_ip" ] && [ "$local_ip" != "$pub_ipv4" ]; then
  2012. echo " RemoteIPInternalProxy $local_ip" >> remoteip.conf
  2013. fi
  2014. if [ -n "$pub_ipv4" ]; then
  2015. echo " RemoteIPInternalProxy $pub_ipv4" >> remoteip.conf
  2016. fi
  2017. echo "</IfModule>" >> remoteip.conf
  2018. sed -i "s/LogFormat \"%h/LogFormat \"%a/g" /etc/apache2/apache2.conf
  2019. a2enmod remoteip >> $LOG
  2020. systemctl restart apache2
  2021. fi
  2022. # Adding default domain
  2023. $HESTIA/bin/v-add-web-domain "$username" "$servername" "$ip"
  2024. check_result $? "can't create $servername domain"
  2025. # Adding cron jobs
  2026. export SCHEDULED_RESTART="yes"
  2027. min=$(gen_pass '012345' '2')
  2028. hour=$(gen_pass '1234567' '1')
  2029. echo "MAILTO=\"\"" > /var/spool/cron/crontabs/hestiaweb
  2030. echo "CONTENT_TYPE=\"text/plain; charset=utf-8\"" >> /var/spool/cron/crontabs/hestiaweb
  2031. echo "*/2 * * * * sudo /usr/local/hestia/bin/v-update-sys-queue restart" >> /var/spool/cron/crontabs/hestiaweb
  2032. echo "10 00 * * * sudo /usr/local/hestia/bin/v-update-sys-queue daily" >> /var/spool/cron/crontabs/hestiaweb
  2033. echo "15 02 * * * sudo /usr/local/hestia/bin/v-update-sys-queue disk" >> /var/spool/cron/crontabs/hestiaweb
  2034. echo "10 00 * * * sudo /usr/local/hestia/bin/v-update-sys-queue traffic" >> /var/spool/cron/crontabs/hestiaweb
  2035. echo "30 03 * * * sudo /usr/local/hestia/bin/v-update-sys-queue webstats" >> /var/spool/cron/crontabs/hestiaweb
  2036. echo "*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-queue backup" >> /var/spool/cron/crontabs/hestiaweb
  2037. echo "10 05 * * * sudo /usr/local/hestia/bin/v-backup-users" >> /var/spool/cron/crontabs/hestiaweb
  2038. echo "20 00 * * * sudo /usr/local/hestia/bin/v-update-user-stats" >> /var/spool/cron/crontabs/hestiaweb
  2039. echo "*/5 * * * * sudo /usr/local/hestia/bin/v-update-sys-rrd" >> /var/spool/cron/crontabs/hestiaweb
  2040. echo "$min $hour * * * sudo /usr/local/hestia/bin/v-update-letsencrypt-ssl" >> /var/spool/cron/crontabs/hestiaweb
  2041. echo "41 4 * * * sudo /usr/local/hestia/bin/v-update-sys-hestia-all" >> /var/spool/cron/crontabs/hestiaweb
  2042. chmod 600 /var/spool/cron/crontabs/hestiaweb
  2043. chown hestiaweb:hestiaweb /var/spool/cron/crontabs/hestiaweb
  2044. # Enable automatic updates
  2045. $HESTIA/bin/v-add-cron-hestia-autoupdate apt
  2046. # Building initial rrd images
  2047. $HESTIA/bin/v-update-sys-rrd
  2048. # Enabling file system quota
  2049. if [ "$quota" = 'yes' ]; then
  2050. $HESTIA/bin/v-add-sys-quota
  2051. fi
  2052. # Set backend port
  2053. $HESTIA/bin/v-change-sys-port $port > /dev/null 2>&1
  2054. # Create default configuration files
  2055. $HESTIA/bin/v-update-sys-defaults
  2056. # Update remaining packages since repositories have changed
  2057. echo -ne "[ * ] Installing remaining software updates..."
  2058. apt-get -qq update
  2059. apt-get -y upgrade >> $LOG &
  2060. BACK_PID=$!
  2061. echo
  2062. # Starting Hestia service
  2063. update-rc.d hestia defaults
  2064. systemctl start hestia
  2065. check_result $? "hestia start failed"
  2066. chown hestiaweb:hestiaweb $HESTIA/data/sessions
  2067. # Create backup folder and set correct permission
  2068. mkdir -p /backup/
  2069. chmod 755 /backup/
  2070. # Create cronjob to generate ssl
  2071. echo "@reboot root sleep 10 && rm /etc/cron.d/hestia-ssl && PATH='/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:' && /usr/local/hestia/bin/v-add-letsencrypt-host" > /etc/cron.d/hestia-ssl
  2072. #----------------------------------------------------------#
  2073. # Set hestia.conf default values #
  2074. #----------------------------------------------------------#
  2075. echo "[ * ] Updating configuration files..."
  2076. BIN="$HESTIA/bin"
  2077. source $HESTIA/func/syshealth.sh
  2078. syshealth_repair_system_config
  2079. # Add /usr/local/hestia/bin/ to path variable
  2080. echo 'if [ "${PATH#*/usr/local/hestia/bin*}" = "$PATH" ]; then
  2081. . /etc/profile.d/hestia.sh
  2082. fi' >> /root/.bashrc
  2083. #----------------------------------------------------------#
  2084. # Hestia Access Info #
  2085. #----------------------------------------------------------#
  2086. # Comparing hostname and IP
  2087. host_ip=$(host $servername | head -n 1 | awk '{print $NF}')
  2088. if [ "$host_ip" = "$ip" ]; then
  2089. ip="$servername"
  2090. fi
  2091. echo -e "\n"
  2092. echo "===================================================================="
  2093. echo -e "\n"
  2094. # Sending notification to admin email
  2095. echo -e "Congratulations!
  2096. You have successfully installed Hestia Control Panel on your server.
  2097. Ready to get started? Log in using the following credentials:
  2098. Admin URL: https://$servername:$port" > $tmpfile
  2099. if [ "$host_ip" != "$ip" ]; then
  2100. echo " Backup URL: https://$ip:$port" >> $tmpfile
  2101. fi
  2102. echo -e -n " Username: $username
  2103. Password: $displaypass
  2104. Thank you for choosing Hestia Control Panel to power your full stack web server,
  2105. we hope that you enjoy using it as much as we do!
  2106. Please feel free to contact us at any time if you have any questions,
  2107. or if you encounter any bugs or problems:
  2108. Documentation: https://docs.hestiacp.com/
  2109. Forum: https://forum.hestiacp.com/
  2110. GitHub: https://www.github.com/hestiacp/hestiacp
  2111. Note: Automatic updates are enabled by default. If you would like to disable them,
  2112. please log in and navigate to Server > Updates to turn them off.
  2113. Help support the Hestia Control Panel project by donating via PayPal:
  2114. https://www.hestiacp.com/donate
  2115. --
  2116. Sincerely yours,
  2117. The Hestia Control Panel development team
  2118. Made with love & pride by the open-source community around the world.
  2119. " >> $tmpfile
  2120. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  2121. cat $tmpfile | $send_mail -s "Hestia Control Panel" $email
  2122. # Congrats
  2123. echo
  2124. cat $tmpfile
  2125. rm -f $tmpfile
  2126. # Add welcome message to notification panel
  2127. $HESTIA/bin/v-add-user-notification "$username" 'Welcome to Hestia Control Panel!' '<p>You are now ready to begin adding <a href="/add/user/">user accounts</a> and <a href="/add/web/">domains</a>. For help and assistance, <a href="https://hestiacp.com/docs/" target="_blank">view the documentation</a> or <a href="https://forum.hestiacp.com/" target="_blank">visit our forum</a>.</p><p>Please <a href="https://github.com/hestiacp/hestiacp/issues" target="_blank">report any issues via GitHub</a>.</p><p class="u-text-bold">Have a wonderful day!</p><p><i class="fas fa-heart icon-red"></i> The Hestia Control Panel development team</p>'
  2128. # Clean-up
  2129. # Sort final configuration file
  2130. sort_config_file
  2131. if [ "$interactive" = 'yes' ]; then
  2132. echo "[ ! ] IMPORTANT: The system will now reboot to complete the installation process."
  2133. read -n 1 -s -r -p "Press any key to continue"
  2134. reboot
  2135. else
  2136. echo "[ ! ] IMPORTANT: You must restart the system before continuing!"
  2137. fi
  2138. # EOF