hst-install-debian.sh 69 KB

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