hst-install-ubuntu.sh 83 KB

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