hst-install-ubuntu.sh 59 KB

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