hst-install-debian.sh 77 KB

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