hst-install-debian.sh 64 KB

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