hst-install-debian.sh 66 KB

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