hst-install-ubuntu.sh 78 KB

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