hst-install-debian.sh 62 KB

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