hst-install-debian.sh 75 KB

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