hst-install-debian.sh 75 KB

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