hst-install-debian.sh 78 KB

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