hst-install-ubuntu.sh 67 KB

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