hst-install-ubuntu.sh 87 KB

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