hst-install-debian.sh 75 KB

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