hst-install-debian.sh 86 KB

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