hst-install-debian.sh 65 KB

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