hst-install-debian.sh 69 KB

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