hst-install-debian.sh 86 KB

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