hst-install-ubuntu.sh 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741
  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.9.0.1'
  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 acl sysstat"
  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.4/$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/\bnginx\b/ /")
  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. if [ -z $(ls "$withdebs/hestia-php_*.deb" 2>/dev/null) ]; then
  744. apt-get -y install hestia-php > /dev/null 2>&1
  745. else
  746. dpkg -i $withdebs/hestia-php_*.deb
  747. fi
  748. if [ -z $(ls "$withdebs/hestia-nginx_*.deb" 2>/dev/null) ]; then
  749. apt-get -y install hestia-nginx > /dev/null 2>&1
  750. else
  751. dpkg -i $withdebs/hestia-nginx_*.deb
  752. fi
  753. fi
  754. # Restoring autostart policy
  755. rm -f /usr/sbin/policy-rc.d
  756. #----------------------------------------------------------#
  757. # Configure system #
  758. #----------------------------------------------------------#
  759. echo "Configure System"
  760. # Enable SSH password authentication
  761. sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
  762. # Enable SFTP subsystem for SSH
  763. sftp_subsys_enabled=$(grep -iE "^#?.*subsystem.+(sftp )?sftp-server" /etc/ssh/sshd_config)
  764. if [ ! -z "$sftp_subsys_enabled" ]; then
  765. sed -i -E "s/^#?.*Subsystem.+(sftp )?sftp-server/Subsystem sftp internal-sftp/g" /etc/ssh/sshd_config
  766. fi
  767. # Disable SSH suffix broadcast
  768. if [ -z "$(grep "^DebianBanner no" /etc/ssh/sshd_config)" ]; then
  769. echo '' >> /etc/ssh/sshd_config
  770. echo 'DebianBanner no' >> /etc/ssh/sshd_config
  771. fi
  772. # Restart SSH daemon
  773. service ssh restart
  774. # Disable AWStats cron
  775. rm -f /etc/cron.d/awstats
  776. # Set directory color
  777. if [ -z "$(grep 'LS_COLORS="$LS_COLORS:di=00;33"' /etc/profile)" ]; then
  778. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  779. fi
  780. # Registering /usr/sbin/nologin
  781. if [ -z "$(grep nologin /etc/shells)" ]; then
  782. echo "/usr/sbin/nologin" >> /etc/shells
  783. fi
  784. # Configuring NTP
  785. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  786. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  787. chmod 755 /etc/cron.daily/ntpdate
  788. ntpdate -s pool.ntp.org
  789. # Setup rssh
  790. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  791. echo /usr/bin/rssh >> /etc/shells
  792. fi
  793. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  794. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  795. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  796. chmod 755 /usr/bin/rssh
  797. #----------------------------------------------------------#
  798. # Configure Hestia #
  799. #----------------------------------------------------------#
  800. echo "Configure Hestia"
  801. # Installing sudo configuration
  802. mkdir -p /etc/sudoers.d
  803. cp -f $hestiacp/sudo/admin /etc/sudoers.d/
  804. chmod 440 /etc/sudoers.d/admin
  805. # Configuring system env
  806. echo "export HESTIA='$HESTIA'" > /etc/profile.d/hestia.sh
  807. echo 'PATH=$PATH:'$HESTIA'/bin' >> /etc/profile.d/hestia.sh
  808. echo 'export PATH' >> /etc/profile.d/hestia.sh
  809. chmod 755 /etc/profile.d/hestia.sh
  810. source /etc/profile.d/hestia.sh
  811. # Configuring logrotate for Hestia logs
  812. cp -f $hestiacp/logrotate/hestia /etc/logrotate.d/hestia
  813. # Building directory tree and creating some blank files for Hestia
  814. mkdir -p $HESTIA/conf $HESTIA/log $HESTIA/ssl $HESTIA/data/ips \
  815. $HESTIA/data/queue $HESTIA/data/users $HESTIA/data/firewall \
  816. $HESTIA/data/sessions
  817. touch $HESTIA/data/queue/backup.pipe $HESTIA/data/queue/disk.pipe \
  818. $HESTIA/data/queue/webstats.pipe $HESTIA/data/queue/restart.pipe \
  819. $HESTIA/data/queue/traffic.pipe $HESTIA/log/system.log \
  820. $HESTIA/log/nginx-error.log $HESTIA/log/auth.log
  821. chmod 750 $HESTIA/conf $HESTIA/data/users $HESTIA/data/ips $HESTIA/log
  822. chmod -R 750 $HESTIA/data/queue
  823. chmod 660 $HESTIA/log/*
  824. rm -f /var/log/hestia
  825. ln -s $HESTIA/log /var/log/hestia
  826. chmod 770 $HESTIA/data/sessions
  827. # Generating Hestia configuration
  828. rm -f $HESTIA/conf/hestia.conf > /dev/null 2>&1
  829. touch $HESTIA/conf/hestia.conf
  830. chmod 660 $HESTIA/conf/hestia.conf
  831. # Web stack
  832. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  833. echo "WEB_SYSTEM='apache2'" >> $HESTIA/conf/hestia.conf
  834. echo "WEB_RGROUPS='www-data'" >> $HESTIA/conf/hestia.conf
  835. echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
  836. echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  837. echo "WEB_SSL='mod_ssl'" >> $HESTIA/conf/hestia.conf
  838. echo "STATS_SYSTEM='awstats'" >> $HESTIA/conf/hestia.conf
  839. fi
  840. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  841. echo "WEB_SYSTEM='apache2'" >> $HESTIA/conf/hestia.conf
  842. echo "WEB_RGROUPS='www-data'" >> $HESTIA/conf/hestia.conf
  843. echo "WEB_PORT='8080'" >> $HESTIA/conf/hestia.conf
  844. echo "WEB_SSL_PORT='8443'" >> $HESTIA/conf/hestia.conf
  845. echo "WEB_SSL='mod_ssl'" >> $HESTIA/conf/hestia.conf
  846. echo "PROXY_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
  847. echo "PROXY_PORT='80'" >> $HESTIA/conf/hestia.conf
  848. echo "PROXY_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  849. echo "STATS_SYSTEM='awstats'" >> $HESTIA/conf/hestia.conf
  850. fi
  851. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  852. echo "WEB_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
  853. echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
  854. echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  855. echo "WEB_SSL='openssl'" >> $HESTIA/conf/hestia.conf
  856. if [ "$phpfpm" = 'yes' ]; then
  857. echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
  858. fi
  859. echo "STATS_SYSTEM='awstats'" >> $HESTIA/conf/hestia.conf
  860. fi
  861. # FTP stack
  862. if [ "$vsftpd" = 'yes' ]; then
  863. echo "FTP_SYSTEM='vsftpd'" >> $HESTIA/conf/hestia.conf
  864. fi
  865. if [ "$proftpd" = 'yes' ]; then
  866. echo "FTP_SYSTEM='proftpd'" >> $HESTIA/conf/hestia.conf
  867. fi
  868. # DNS stack
  869. if [ "$named" = 'yes' ]; then
  870. echo "DNS_SYSTEM='bind9'" >> $HESTIA/conf/hestia.conf
  871. fi
  872. # Mail stack
  873. if [ "$exim" = 'yes' ]; then
  874. echo "MAIL_SYSTEM='exim4'" >> $HESTIA/conf/hestia.conf
  875. echo "WEBMAIL_ALIAS='webmail'" >> $HESTIA/conf/hestia.conf
  876. if [ "$clamd" = 'yes' ]; then
  877. echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $HESTIA/conf/hestia.conf
  878. fi
  879. if [ "$spamd" = 'yes' ]; then
  880. echo "ANTISPAM_SYSTEM='spamassassin'" >> $HESTIA/conf/hestia.conf
  881. fi
  882. if [ "$dovecot" = 'yes' ]; then
  883. echo "IMAP_SYSTEM='dovecot'" >> $HESTIA/conf/hestia.conf
  884. fi
  885. fi
  886. # Cron daemon
  887. echo "CRON_SYSTEM='cron'" >> $HESTIA/conf/hestia.conf
  888. # Firewall stack
  889. if [ "$iptables" = 'yes' ]; then
  890. echo "FIREWALL_SYSTEM='iptables'" >> $HESTIA/conf/hestia.conf
  891. fi
  892. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  893. echo "FIREWALL_EXTENSION='fail2ban'" >> $HESTIA/conf/hestia.conf
  894. fi
  895. # Disk quota
  896. if [ "$quota" = 'yes' ]; then
  897. echo "DISK_QUOTA='yes'" >> $HESTIA/conf/hestia.conf
  898. fi
  899. # Backups
  900. echo "BACKUP_SYSTEM='local'" >> $HESTIA/conf/hestia.conf
  901. # Language
  902. echo "LANGUAGE='$lang'" >> $HESTIA/conf/hestia.conf
  903. # Version & Release Branch
  904. echo "VERSION='1.0.1'" >> $HESTIA/conf/hestia.conf
  905. echo "RELEASE_BRANCH='release'" >> $HESTIA/conf/hestia.conf
  906. # Installing hosting packages
  907. cp -rf $hestiacp/packages $HESTIA/data/
  908. # Installing templates
  909. cp -rf $hestiacp/templates $HESTIA/data/
  910. mkdir -p /var/www/html
  911. mkdir -p /var/www/document_errors
  912. # Install default success page
  913. cp -rf $hestiacp/templates/web/unassigned/index.html /var/www/html/
  914. cp -rf $hestiacp/templates/web/skel/document_errors/* /var/www/document_errors/
  915. # Installing firewall rules
  916. cp -rf $hestiacp/firewall $HESTIA/data/
  917. # Configuring server hostname
  918. $HESTIA/bin/v-change-sys-hostname $servername > /dev/null 2>&1
  919. # Generating SSL certificate
  920. echo "Generate ssl certificate"
  921. $HESTIA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  922. 'San Francisco' 'Hestia Control Panel' 'IT' > /tmp/hst.pem
  923. # Parsing certificate file
  924. crt_end=$(grep -n "END CERTIFICATE-" /tmp/hst.pem |cut -f 1 -d:)
  925. key_start=$(grep -n "BEGIN RSA" /tmp/hst.pem |cut -f 1 -d:)
  926. key_end=$(grep -n "END RSA" /tmp/hst.pem |cut -f 1 -d:)
  927. # Adding SSL certificate
  928. echo "Add ssl certificate to Hestia"
  929. cd $HESTIA/ssl
  930. sed -n "1,${crt_end}p" /tmp/hst.pem > certificate.crt
  931. sed -n "$key_start,${key_end}p" /tmp/hst.pem > certificate.key
  932. chown root:mail $HESTIA/ssl/*
  933. chmod 660 $HESTIA/ssl/*
  934. rm /tmp/hst.pem
  935. # Adding nologin as a valid system shell
  936. if [ -z "$(grep nologin /etc/shells)" ]; then
  937. echo "/usr/sbin/nologin" >> /etc/shells
  938. fi
  939. #----------------------------------------------------------#
  940. # Configure Nginx #
  941. #----------------------------------------------------------#
  942. if [ "$nginx" = 'yes' ]; then
  943. echo "Configure Nginx Webserver"
  944. rm -f /etc/nginx/conf.d/*.conf
  945. cp -f $hestiacp/nginx/nginx.conf /etc/nginx/
  946. cp -f $hestiacp/nginx/status.conf /etc/nginx/conf.d/
  947. cp -f $hestiacp/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  948. cp -f $hestiacp/nginx/phppgadmin.inc /etc/nginx/conf.d/
  949. cp -f $hestiacp/logrotate/nginx /etc/logrotate.d/
  950. mkdir -p /etc/nginx/conf.d/domains
  951. mkdir -p /var/log/nginx/domains
  952. if [ "$apache" = 'no' ] && [ "$multiphp" = 'yes' ]; then
  953. echo "Configure Nginx MultiPHP"
  954. rm -fr $HESTIA/data/templates/web/nginx/*
  955. for v in "${multiphp_v[@]}"; do
  956. update-rc.d php$v-fpm defaults > /dev/null 2>&1
  957. cp -r /etc/php/$v/ /root/hst_install_backups/php$v/
  958. rm -f /etc/php/$v/fpm/pool.d/*
  959. v_tpl=$(echo "$v" | sed -e 's/[.]//')
  960. cp -f $hestiacp/multiphp/nginx/PHP-$v_tpl.* $HESTIA/data/templates/web/nginx/
  961. cp -f $hestiacp/php-fpm/dummy.conf /etc/php/$v/fpm/pool.d/
  962. sed -i "s/9999/99$v_tpl/g" /etc/php/$v/fpm/pool.d/dummy.conf
  963. done
  964. cp -f $hestiacp/php-fpm/www.conf /etc/php/$fpm_v/fpm/pool.d/
  965. chmod a+x $HESTIA/data/templates/web/nginx/*.sh
  966. fpm_tpl=$(echo "$fpm_v" | sed -e 's/[.]//')
  967. ln -s $HESTIA/data/templates/web/nginx/PHP-$fpm_tpl.sh $HESTIA/data/templates/web/nginx/default.sh
  968. ln -s $HESTIA/data/templates/web/nginx/PHP-$fpm_tpl.tpl $HESTIA/data/templates/web/nginx/default.tpl
  969. ln -s $HESTIA/data/templates/web/nginx/PHP-$fpm_tpl.stpl $HESTIA/data/templates/web/nginx/default.stpl
  970. service php$fpm_v-fpm start >> $LOG
  971. check_result $? "php$fpm_v-fpm start failed"
  972. fi
  973. # Install dhparam.
  974. cp -f $HESTIA/install/deb/ssl/dhparam.pem /etc/ssl
  975. # Update dns servers in nginx.conf
  976. dns_resolver=$(cat /etc/resolv.conf | grep -i '^nameserver' | cut -d ' ' -f2 | tr '\r\n' ' ' | xargs)
  977. for ip in $dns_resolver; do
  978. if [[ $ip =~ ^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
  979. resolver="$ip $resolver"
  980. fi
  981. done
  982. if [ ! -z "$resolver" ]; then
  983. sed -i "s/1.0.0.1 1.1.1.1/$resolver/g" /etc/nginx/nginx.conf
  984. fi
  985. update-rc.d nginx defaults > /dev/null 2>&1
  986. service nginx start >> $LOG
  987. check_result $? "nginx start failed"
  988. fi
  989. #----------------------------------------------------------#
  990. # Configure Apache #
  991. #----------------------------------------------------------#
  992. if [ "$apache" = 'yes' ]; then
  993. echo "Configure Apache Webserver"
  994. cp -f $hestiacp/apache2/apache2.conf /etc/apache2/
  995. cp -f $hestiacp/apache2/status.conf /etc/apache2/mods-enabled/
  996. cp -f $hestiacp/logrotate/apache2 /etc/logrotate.d/
  997. a2enmod rewrite > /dev/null 2>&1
  998. a2enmod suexec > /dev/null 2>&1
  999. a2enmod ssl > /dev/null 2>&1
  1000. a2enmod actions > /dev/null 2>&1
  1001. a2enmod ruid2 > /dev/null 2>&1
  1002. mkdir -p /etc/apache2/conf.d
  1003. mkdir -p /etc/apache2/conf.d/domains
  1004. echo "# Powered by hestia" > /etc/apache2/sites-available/default
  1005. echo "# Powered by hestia" > /etc/apache2/sites-available/default-ssl
  1006. echo "# Powered by hestia" > /etc/apache2/ports.conf
  1007. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  1008. touch /var/log/apache2/access.log /var/log/apache2/error.log
  1009. mkdir -p /var/log/apache2/domains
  1010. chmod a+x /var/log/apache2
  1011. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  1012. chmod 751 /var/log/apache2/domains
  1013. if [ "$multiphp" = 'yes' ] ; then
  1014. echo "Configure Apache MultiPHP"
  1015. a2enmod proxy_fcgi setenvif > /dev/null 2>&1
  1016. for v in "${multiphp_v[@]}"; do
  1017. a2enconf php$v-fpm-fpm > /dev/null 2>&1
  1018. update-rc.d php$v-fpm defaults > /dev/null 2>&1
  1019. cp -r /etc/php/$v/ /root/hst_install_backups/php$v/
  1020. rm -f /etc/php/$v/fpm/pool.d/*
  1021. v_tpl=$(echo "$v" | sed -e 's/[.]//')
  1022. cp -f $hestiacp/multiphp/apache2/PHP-$v_tpl.* $HESTIA/data/templates/web/apache2/
  1023. done
  1024. chmod a+x $HESTIA/data/templates/web/apache2/*.sh
  1025. fi
  1026. update-rc.d apache2 defaults > /dev/null 2>&1
  1027. service apache2 start >> $LOG
  1028. check_result $? "apache2 start failed"
  1029. else
  1030. update-rc.d apache2 disable > /dev/null 2>&1
  1031. service apache2 stop > /dev/null 2>&1
  1032. fi
  1033. #----------------------------------------------------------#
  1034. # Configure PHP-FPM #
  1035. #----------------------------------------------------------#
  1036. if [ "$phpfpm" = 'yes' ]; then
  1037. echo "Configure PHP-FPM"
  1038. cp -f $hestiacp/php-fpm/www.conf /etc/php/$fpm_v/fpm/pool.d/www.conf
  1039. update-rc.d php$fpm_v-fpm defaults > /dev/null 2>&1
  1040. service php$fpm_v-fpm start >> $LOG
  1041. check_result $? "php-fpm start failed"
  1042. fi
  1043. #----------------------------------------------------------#
  1044. # Configure PHP #
  1045. #----------------------------------------------------------#
  1046. echo "Configure PHP Timezone"
  1047. ZONE=$(timedatectl > /dev/null 2>&1|grep Timezone|awk '{print $2}')
  1048. if [ -z "$ZONE" ]; then
  1049. ZONE='UTC'
  1050. fi
  1051. for pconf in $(find /etc/php* -name php.ini); do
  1052. sed -i "s%;date.timezone =%date.timezone = $ZONE%g" $pconf
  1053. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  1054. done
  1055. # Cleanup php session files not changed in the last 7 days (60*24*7 minutes)
  1056. echo '#!/bin/sh' > /etc/cron.daily/php-session-cleanup
  1057. echo "find -O3 /home/*/tmp/ -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin '+10080' -delete > /dev/null 2>&1" >> /etc/cron.daily/php-session-cleanup
  1058. echo "find -O3 $HESTIA/data/sessions/ -ignore_readdir_race -depth -mindepth 1 -name 'sess_*' -type f -cmin '+10080' -delete > /dev/null 2>&1" >> /etc/cron.daily/php-session-cleanup
  1059. chmod 755 /etc/cron.daily/php-session-cleanup
  1060. #----------------------------------------------------------#
  1061. # Configure Vsftpd #
  1062. #----------------------------------------------------------#
  1063. if [ "$vsftpd" = 'yes' ]; then
  1064. echo "Configure Vsftpd"
  1065. cp -f $hestiacp/vsftpd/vsftpd.conf /etc/
  1066. touch /var/log/vsftpd.log
  1067. chown root:adm /var/log/vsftpd.log
  1068. chmod 640 /var/log/vsftpd.log
  1069. touch /var/log/xferlog
  1070. chown root:adm /var/log/xferlog
  1071. chmod 640 /var/log/xferlog
  1072. update-rc.d vsftpd defaults
  1073. service vsftpd start
  1074. check_result $? "vsftpd start failed"
  1075. fi
  1076. #----------------------------------------------------------#
  1077. # Configure ProFTPD #
  1078. #----------------------------------------------------------#
  1079. if [ "$proftpd" = 'yes' ]; then
  1080. echo "Configure ProFTPD server"
  1081. echo "127.0.0.1 $servername" >> /etc/hosts
  1082. cp -f $hestiacp/proftpd/proftpd.conf /etc/proftpd/
  1083. update-rc.d proftpd defaults > /dev/null 2>&1
  1084. service proftpd start >> $LOG
  1085. check_result $? "proftpd start failed"
  1086. fi
  1087. #----------------------------------------------------------#
  1088. # Configure MariaDB #
  1089. #----------------------------------------------------------#
  1090. if [ "$mysql" = 'yes' ]; then
  1091. echo "Configure MariaDB server"
  1092. mycnf="my-small.cnf"
  1093. if [ $memory -gt 1200000 ]; then
  1094. mycnf="my-medium.cnf"
  1095. fi
  1096. if [ $memory -gt 3900000 ]; then
  1097. mycnf="my-large.cnf"
  1098. fi
  1099. # Configuring MariaDB
  1100. cp -f $hestiacp/mysql/$mycnf /etc/mysql/my.cnf
  1101. mysql_install_db >> $LOG
  1102. update-rc.d mysql defaults
  1103. service mysql start >> $LOG
  1104. check_result $? "mariadb start failed"
  1105. # Securing MariaDB installation
  1106. mpass=$(gen_pass)
  1107. mysqladmin -u root password $mpass >> $LOG
  1108. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  1109. chmod 600 /root/.my.cnf
  1110. # Clear MariaDB Test Users and Databases
  1111. mysql -e "DELETE FROM mysql.user WHERE User=''"
  1112. mysql -e "DROP DATABASE test" > /dev/null 2>&1
  1113. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  1114. mysql -e "DELETE FROM mysql.user WHERE user='';"
  1115. mysql -e "DELETE FROM mysql.user WHERE password='' AND authentication_string='';"
  1116. # Configuring phpMyAdmin
  1117. if [ "$apache" = 'yes' ]; then
  1118. cp -f $hestiacp/pma/apache.conf /etc/phpmyadmin/
  1119. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  1120. fi
  1121. cp -f $hestiacp/pma/config.inc.php /etc/phpmyadmin/
  1122. chmod 777 /var/lib/phpmyadmin/tmp
  1123. fi
  1124. #----------------------------------------------------------#
  1125. # Configure phpMyAdmin #
  1126. #----------------------------------------------------------#
  1127. if [ "$mysql" = 'yes' ]; then
  1128. # Display upgrade information
  1129. echo "Installing phpMyAdmin version v$pma_v..."
  1130. # Download latest phpmyadmin release
  1131. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  1132. # Unpack files
  1133. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  1134. # Delete file to prevent error
  1135. rm -fr /usr/share/phpmyadmin/doc/html
  1136. # Overwrite old files
  1137. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  1138. # Set config and log directory
  1139. sed -i "s|define('CONFIG_DIR', '');|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  1140. sed -i "s|define('TEMP_DIR', './tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  1141. # Create temporary folder and change permission
  1142. mkdir /usr/share/phpmyadmin/tmp
  1143. chmod 777 /usr/share/phpmyadmin/tmp
  1144. # Clear Up
  1145. rm -fr phpMyAdmin-$pma_v-all-languages
  1146. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  1147. fi
  1148. #----------------------------------------------------------#
  1149. # Configure PostgreSQL #
  1150. #----------------------------------------------------------#
  1151. if [ "$postgresql" = 'yes' ]; then
  1152. echo "Configure PostgreSQL database server"
  1153. ppass=$(gen_pass)
  1154. cp -f $hestiacp/postgresql/pg_hba.conf /etc/postgresql/*/main/
  1155. service postgresql restart
  1156. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  1157. # Configuring phpPgAdmin
  1158. if [ "$apache" = 'yes' ]; then
  1159. cp -f $hestiacp/pga/phppgadmin.conf /etc/apache2/conf.d/
  1160. fi
  1161. cp -f $hestiacp/pga/config.inc.php /etc/phppgadmin/
  1162. fi
  1163. #----------------------------------------------------------#
  1164. # Configure Bind #
  1165. #----------------------------------------------------------#
  1166. if [ "$named" = 'yes' ]; then
  1167. echo "Configure Bind DNS server"
  1168. cp -f $hestiacp/bind/named.conf /etc/bind/
  1169. cp -f $hestiacp/bind/named.conf.options /etc/bind/
  1170. chown root:bind /etc/bind/named.conf
  1171. chown root:bind /etc/bind/named.conf.options
  1172. chown bind:bind /var/cache/bind
  1173. chmod 640 /etc/bind/named.conf
  1174. chmod 640 /etc/bind/named.conf.options
  1175. aa-complain /usr/sbin/named > /dev/null 2>&1
  1176. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2> /dev/null
  1177. if ! grep --quiet lxc /proc/1/environ; then
  1178. service apparmor status > /dev/null 2>&1
  1179. if [ $? -ne 0 ]; then
  1180. service apparmor restart
  1181. fi
  1182. fi
  1183. update-rc.d bind9 defaults
  1184. service bind9 start
  1185. check_result $? "bind9 start failed"
  1186. # Workaround for OpenVZ/Virtuozzo
  1187. if [ -e "/proc/vz/veinfo" ]; then
  1188. sed -i "s/^exit 0/service bind9 restart\nexit 0/" /etc/rc.local
  1189. fi
  1190. fi
  1191. #----------------------------------------------------------#
  1192. # Configure Exim #
  1193. #----------------------------------------------------------#
  1194. if [ "$exim" = 'yes' ]; then
  1195. echo "Configure Exim mail server"
  1196. gpasswd -a Debian-exim mail > /dev/null 2>&1
  1197. cp -f $hestiacp/exim/exim4.conf.template /etc/exim4/
  1198. cp -f $hestiacp/exim/dnsbl.conf /etc/exim4/
  1199. cp -f $hestiacp/exim/spam-blocks.conf /etc/exim4/
  1200. touch /etc/exim4/white-blocks.conf
  1201. if [ "$spamd" = 'yes' ]; then
  1202. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  1203. fi
  1204. if [ "$clamd" = 'yes' ]; then
  1205. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  1206. fi
  1207. chmod 640 /etc/exim4/exim4.conf.template
  1208. rm -rf /etc/exim4/domains
  1209. mkdir -p /etc/exim4/domains
  1210. rm -f /etc/alternatives/mta
  1211. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  1212. update-rc.d -f sendmail remove > /dev/null 2>&1
  1213. service sendmail stop > /dev/null 2>&1
  1214. update-rc.d -f postfix remove > /dev/null 2>&1
  1215. service postfix stop > /dev/null 2>&1
  1216. update-rc.d exim4 defaults
  1217. service exim4 start
  1218. check_result $? "exim4 start failed"
  1219. fi
  1220. #----------------------------------------------------------#
  1221. # Configure Dovecot #
  1222. #----------------------------------------------------------#
  1223. if [ "$dovecot" = 'yes' ]; then
  1224. echo "Configure Dovecot"
  1225. gpasswd -a dovecot mail > /dev/null 2>&1
  1226. cp -rf $hestiacp/dovecot /etc/
  1227. cp -f $hestiacp/logrotate/dovecot /etc/logrotate.d/
  1228. if [ "$release" = '18.04' ]; then
  1229. rm -f /etc/dovecot/conf.d/15-mailboxes.conf
  1230. fi
  1231. chown -R root:root /etc/dovecot*
  1232. update-rc.d dovecot defaults
  1233. service dovecot start
  1234. check_result $? "dovecot start failed"
  1235. fi
  1236. #----------------------------------------------------------#
  1237. # Configure ClamAV #
  1238. #----------------------------------------------------------#
  1239. if [ "$clamd" = 'yes' ]; then
  1240. gpasswd -a clamav mail > /dev/null 2>&1
  1241. gpasswd -a clamav Debian-exim > /dev/null 2>&1
  1242. cp -f $hestiacp/clamav/clamd.conf /etc/clamav/
  1243. update-rc.d clamav-daemon defaults
  1244. echo -ne "Installing ClamAV anti-virus definitions... "
  1245. /usr/bin/freshclam >> $LOG &
  1246. BACK_PID=$!
  1247. spin_i=1
  1248. while kill -0 $BACK_PID > /dev/null 2>&1 ; do
  1249. printf "\b${spinner:spin_i++%${#spinner}:1}"
  1250. sleep 0.5
  1251. done
  1252. echo
  1253. service clamav-daemon start
  1254. check_result $? "clamav-daemon start failed"
  1255. fi
  1256. #----------------------------------------------------------#
  1257. # Configure SpamAssassin #
  1258. #----------------------------------------------------------#
  1259. if [ "$spamd" = 'yes' ]; then
  1260. echo "Configure SpamAssassin"
  1261. update-rc.d spamassassin defaults > /dev/null 2>&1
  1262. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  1263. service spamassassin start >> $LOG
  1264. check_result $? "spamassassin start failed"
  1265. unit_files="$(systemctl list-unit-files |grep spamassassin)"
  1266. if [[ "$unit_files" =~ "disabled" ]]; then
  1267. systemctl enable spamassassin > /dev/null 2>&1
  1268. fi
  1269. fi
  1270. #----------------------------------------------------------#
  1271. # Configure Roundcube #
  1272. #----------------------------------------------------------#
  1273. if [ "$dovecot" = 'yes' ] && [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1274. echo "Configure Roundcube"
  1275. if [ "$apache" = 'yes' ]; then
  1276. cp -f $hestiacp/roundcube/apache.conf /etc/roundcube/
  1277. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  1278. fi
  1279. if [ "$nginx" = 'yes' ]; then
  1280. cp -f $hestiacp/nginx/webmail.inc /etc/nginx/conf.d/
  1281. fi
  1282. cp -f $hestiacp/roundcube/main.inc.php /etc/roundcube/config.inc.php
  1283. cp -f $hestiacp/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  1284. cp -f $hestiacp/roundcube/config.inc.php /etc/roundcube/plugins/password/
  1285. cp -f $hestiacp/roundcube/hestia.php /usr/share/roundcube/plugins/password/drivers/
  1286. touch /var/log/roundcube/errors
  1287. chmod 640 /etc/roundcube/config.inc.php
  1288. chown root:www-data /etc/roundcube/config.inc.php
  1289. chmod 640 /etc/roundcube/debian-db-roundcube.php
  1290. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1291. chmod 640 /var/log/roundcube/errors
  1292. chown www-data:adm /var/log/roundcube/errors
  1293. r="$(gen_pass)"
  1294. mysql -e "CREATE DATABASE roundcube"
  1295. mysql -e "GRANT ALL ON roundcube.*
  1296. TO roundcube@localhost IDENTIFIED BY '$r'"
  1297. sed -i "s/%password%/$r/g" /etc/roundcube/debian-db-roundcube.php
  1298. sed -i "s/localhost/$servername/g" /etc/roundcube/plugins/password/config.inc.php
  1299. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  1300. # Configure webmail alias
  1301. echo "WEBMAIL_ALIAS='webmail'" >> $HESTIA/conf/hestia.conf
  1302. phpenmod mcrypt > /dev/null 2>&1
  1303. # Restart services
  1304. if [ "$apache" = 'yes' ]; then
  1305. service apache2 restart
  1306. fi
  1307. if [ "$nginx" = 'yes' ]; then
  1308. service nginx restart
  1309. fi
  1310. fi
  1311. #----------------------------------------------------------#
  1312. # Configure Fail2Ban #
  1313. #----------------------------------------------------------#
  1314. if [ "$fail2ban" = 'yes' ]; then
  1315. echo "Configure Fail2ban"
  1316. cp -rf $hestiacp/fail2ban /etc/
  1317. if [ "$dovecot" = 'no' ]; then
  1318. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1319. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1320. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1321. fi
  1322. if [ "$exim" = 'no' ]; then
  1323. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1324. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1325. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1326. fi
  1327. if [ "$vsftpd" = 'yes' ]; then
  1328. #Create vsftpd Log File
  1329. if [ ! -f "/var/log/vsftpd.log" ]; then
  1330. touch /var/log/vsftpd.log
  1331. fi
  1332. fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1333. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1334. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1335. fi
  1336. update-rc.d fail2ban defaults
  1337. service fail2ban start
  1338. check_result $? "fail2ban start failed"
  1339. fi
  1340. #----------------------------------------------------------#
  1341. # Configure API #
  1342. #----------------------------------------------------------#
  1343. if [ "$api" = 'yes' ]; then
  1344. echo "API='yes'" >> $HESTIA/conf/hestia.conf
  1345. else
  1346. rm -r $HESTIA/web/api
  1347. echo "API='no'" >> $HESTIA/conf/hestia.conf
  1348. fi
  1349. #----------------------------------------------------------#
  1350. # Fix phpmyadmin #
  1351. #----------------------------------------------------------#
  1352. # Special thanks to Pavel Galkin (https://skurudo.ru)
  1353. # https://github.com/skurudo/phpmyadmin-fixer
  1354. if [ "$mysql" = 'yes' ]; then
  1355. source $hestiacp/phpmyadmin/pma.sh > /dev/null 2>&1
  1356. fi
  1357. #----------------------------------------------------------#
  1358. # Configure Admin User #
  1359. #----------------------------------------------------------#
  1360. # Deleting old admin user
  1361. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1362. chattr -i /home/admin/conf > /dev/null 2>&1
  1363. userdel -f admin > /dev/null 2>&1
  1364. chattr -i /home/admin/conf > /dev/null 2>&1
  1365. mv -f /home/admin $hst_backups/home/ > /dev/null 2>&1
  1366. rm -f /tmp/sess_* > /dev/null 2>&1
  1367. fi
  1368. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  1369. groupdel admin > /dev/null 2>&1
  1370. fi
  1371. # Enable sftp jail
  1372. $HESTIA/bin/v-add-sys-sftp-jail > /dev/null 2>&1
  1373. check_result $? "can't enable sftp jail"
  1374. # Adding Hestia admin account
  1375. $HESTIA/bin/v-add-user admin $vpass $email default System Administrator
  1376. check_result $? "can't create admin user"
  1377. $HESTIA/bin/v-change-user-shell admin nologin
  1378. $HESTIA/bin/v-change-user-language admin $lang
  1379. # Configuring system IPs
  1380. $HESTIA/bin/v-update-sys-ip > /dev/null 2>&1
  1381. # Get main IP
  1382. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1383. # Configuring firewall
  1384. if [ "$iptables" = 'yes' ]; then
  1385. $HESTIA/bin/v-update-firewall
  1386. fi
  1387. # Get public IP
  1388. pub_ip=$(curl --ipv4 -s https://ip.hestiacp.com/)
  1389. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1390. echo "$HESTIA/bin/v-update-sys-ip" >> /etc/rc.local
  1391. $HESTIA/bin/v-change-sys-ip-nat $ip $pub_ip > /dev/null 2>&1
  1392. ip=$pub_ip
  1393. fi
  1394. # Configuring MariaDB host
  1395. if [ "$mysql" = 'yes' ]; then
  1396. $HESTIA/bin/v-add-database-host mysql localhost root $mpass
  1397. fi
  1398. # Configuring PostgreSQL host
  1399. if [ "$postgresql" = 'yes' ]; then
  1400. $HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
  1401. fi
  1402. # Adding default domain
  1403. $HESTIA/bin/v-add-web-domain admin $servername
  1404. check_result $? "can't create $servername domain"
  1405. # Adding cron jobs
  1406. command="sudo $HESTIA/bin/v-update-sys-queue disk"
  1407. $HESTIA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1408. command="sudo $HESTIA/bin/v-update-sys-queue traffic"
  1409. $HESTIA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1410. command="sudo $HESTIA/bin/v-update-sys-queue webstats"
  1411. $HESTIA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1412. command="sudo $HESTIA/bin/v-update-sys-queue backup"
  1413. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1414. command="sudo $HESTIA/bin/v-backup-users"
  1415. $HESTIA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1416. command="sudo $HESTIA/bin/v-update-user-stats"
  1417. $HESTIA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1418. command="sudo $HESTIA/bin/v-update-sys-rrd"
  1419. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1420. service cron restart
  1421. # Building initital rrd images
  1422. $HESTIA/bin/v-update-sys-rrd
  1423. # Enabling file system quota
  1424. if [ "$quota" = 'yes' ]; then
  1425. $HESTIA/bin/v-add-sys-quota
  1426. fi
  1427. # Set backend port
  1428. $HESTIA/bin/v-change-sys-port $port
  1429. # Starting Hestia service
  1430. update-rc.d hestia defaults
  1431. service hestia start
  1432. check_result $? "hestia start failed"
  1433. chown admin:admin $HESTIA/data/sessions
  1434. #----------------------------------------------------------#
  1435. # Hestia Access Info #
  1436. #----------------------------------------------------------#
  1437. # Comparing hostname and IP
  1438. host_ip=$(host $servername| head -n 1 |awk '{print $NF}')
  1439. if [ "$host_ip" = "$ip" ]; then
  1440. ip="$servername"
  1441. fi
  1442. # Sending notification to admin email
  1443. echo -e "Congratulations!
  1444. You have successfully installed Hestia Control Panel on your server.
  1445. Ready to get started? Log in using the following credentials:
  1446. Admin URL: https://$ip:$port
  1447. Username: admin
  1448. Password: $vpass
  1449. Thank you for choosing Hestia Control Panel to power your full stack web server,
  1450. we hope that you enjoy using it as much as we do!
  1451. Please feel free to contact us at any time if you have any questions,
  1452. or if you encounter any bugs or problems:
  1453. E-mail: [email protected]
  1454. Web: https://www.hestiacp.com/
  1455. Forum: https://forum.hestiacp.com/
  1456. GitHub: https://www.github.com/hestiacp/hestiacp
  1457. Want to join our beta test program? Please email us at
  1458. [email protected] or join in on GitHub to start contributing today.
  1459. Help support the Hestia Contol Panel project by donating via PayPal:
  1460. https://www.hestiacp.com/donate
  1461. --
  1462. Sincerely yours,
  1463. The Hestia Control Panel development team
  1464. Made with love & pride by the open-source community around the world.
  1465. " > $tmpfile
  1466. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  1467. cat $tmpfile | $send_mail -s "Hestia Control Panel" $email
  1468. # Congrats
  1469. echo
  1470. cat $tmpfile
  1471. rm -f $tmpfile
  1472. # Add welcome message to notification panel
  1473. $HESTIA/bin/v-add-user-notification admin 'Welcome!' 'For more information on how to use Hestia Control Panel, click on the Help icon in the top right corner of the toolbar.<br><br>Please report any bugs or issues on GitHub at<br>https://github.com/hestiacp/hestiacp/Issues<br><br>Have a great day!'
  1474. echo "(!) IMPORTANT: You must logout or restart the server before continuing."
  1475. echo ""
  1476. if [ "$interactive" = 'yes' ]; then
  1477. echo -n " Do you want to logout now? [Y/N] "
  1478. read resetshell
  1479. if [ "$resetshell" = "Y" ] || [ "$resetshell" = "y" ]; then
  1480. exit
  1481. fi
  1482. fi
  1483. # EOF