hst-install-ubuntu.sh 84 KB

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