hst-install-debian.sh 87 KB

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