hst-install-debian.sh 85 KB

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