hst-install-ubuntu.sh 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485
  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/$(date +%s).log"
  13. memory=$(grep 'MemTotal' /proc/meminfo |tr ' ' '\n' |grep [0-9])
  14. hst_backups="/root/hst_install_backups/$(date +%s)"
  15. arch=$(uname -i)
  16. os='ubuntu'
  17. release="$(lsb_release -s -r)"
  18. codename="$(lsb_release -s -c)"
  19. hestiacp="$HESTIA/install/$VERSION/$release"
  20. pma_v='4.8.3'
  21. # Defining software pack for all distros
  22. software="apache2 apache2.2-common apache2-suexec-custom apache2-utils
  23. apparmor-utils awstats bc bind9 bsdmainutils bsdutils clamav-daemon
  24. cron curl dnsutils dovecot-imapd dovecot-pop3d e2fslibs e2fsprogs exim4
  25. exim4-daemon-heavy expect fail2ban flex ftp git idn imagemagick
  26. libapache2-mod-fcgid libapache2-mod-php libapache2-mod-rpaf
  27. libapache2-mod-ruid2 lsof mc mariadb-client mariadb-common mariadb-server nginx
  28. ntpdate php-cgi php-common php-curl phpmyadmin php-mysql phppgadmin
  29. php-pgsql postgresql postgresql-contrib proftpd-basic quota roundcube-core
  30. roundcube-mysql roundcube-plugins rrdtool rssh spamassassin sudo hestia
  31. hestia-nginx hestia-php vim-common vsftpd webalizer whois zip"
  32. # Defining help function
  33. help() {
  34. echo "Usage: $0 [OPTIONS]
  35. -a, --apache Install Apache [yes|no] default: yes
  36. -n, --nginx Install Nginx [yes|no] default: yes
  37. -w, --phpfpm Install PHP-FPM [yes|no] default: no
  38. -o, --multiphp Install Multi-PHP [yes|no] default: no
  39. -v, --vsftpd Install Vsftpd [yes|no] default: yes
  40. -j, --proftpd Install ProFTPD [yes|no] default: no
  41. -k, --named Install Bind [yes|no] default: yes
  42. -m, --mysql Install MariaDB [yes|no] default: yes
  43. -g, --postgresql Install PostgreSQL [yes|no] default: no
  44. -x, --exim Install Exim [yes|no] default: yes
  45. -z, --dovecot Install Dovecot [yes|no] default: yes
  46. -c, --clamav Install ClamAV [yes|no] default: yes
  47. -t, --spamassassin Install SpamAssassin [yes|no] default: yes
  48. -i, --iptables Install Iptables [yes|no] default: yes
  49. -b, --fail2ban Install Fail2ban [yes|no] default: yes
  50. -q, --quota Filesystem Quota [yes|no] default: no
  51. -d, --api Activate API [yes|no] default: yes
  52. -r, --port Change Backend Port default: 8083
  53. -l, --lang Default language default: en
  54. -y, --interactive Interactive install [yes|no] default: yes
  55. -s, --hostname Set hostname
  56. -e, --email Set admin email
  57. -p, --password Set admin password
  58. -f, --force Force installation
  59. -h, --help Print this help
  60. Example: bash $0 -e demo@hestiacp.com -p p4ssw0rd --apache no --phpfpm yes"
  61. exit 1
  62. }
  63. # Defining password-gen function
  64. gen_pass() {
  65. MATRIX='0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
  66. LENGTH=16
  67. while [ ${n:=1} -le $LENGTH ]; do
  68. PASS="$PASS${MATRIX:$(($RANDOM%${#MATRIX})):1}"
  69. let n+=1
  70. done
  71. echo "$PASS"
  72. }
  73. # Defining return code check function
  74. check_result() {
  75. if [ $1 -ne 0 ]; then
  76. echo "Error: $2"
  77. exit $1
  78. fi
  79. }
  80. # Defining function to set default value
  81. set_default_value() {
  82. eval variable=\$$1
  83. if [ -z "$variable" ]; then
  84. eval $1=$2
  85. fi
  86. if [ "$variable" != 'yes' ] && [ "$variable" != 'no' ]; then
  87. eval $1=$2
  88. fi
  89. }
  90. # Defining function to set default language value
  91. set_default_lang() {
  92. if [ -z "$lang" ]; then
  93. eval lang=$1
  94. fi
  95. lang_list="
  96. ar cz el fa hu ja no pt se ua
  97. bs da en fi id ka pl ro tr vi
  98. cn de es fr it nl pt-BR ru tw
  99. bg ko sr th ur"
  100. if !(echo $lang_list |grep -w $lang > /dev/null 2>&1); then
  101. eval lang=$1
  102. fi
  103. }
  104. # Define the default backend port
  105. set_default_port() {
  106. if [ -z "$port" ]; then
  107. eval port=$1
  108. fi
  109. }
  110. #----------------------------------------------------------#
  111. # Verifications #
  112. #----------------------------------------------------------#
  113. # Creating temporary file
  114. tmpfile=$(mktemp -p /tmp)
  115. # Translating argument to --gnu-long-options
  116. for arg; do
  117. delim=""
  118. case "$arg" in
  119. --apache) args="${args}-a " ;;
  120. --nginx) args="${args}-n " ;;
  121. --phpfpm) args="${args}-w " ;;
  122. --vsftpd) args="${args}-v " ;;
  123. --proftpd) args="${args}-j " ;;
  124. --named) args="${args}-k " ;;
  125. --mysql) args="${args}-m " ;;
  126. --postgresql) args="${args}-g " ;;
  127. --exim) args="${args}-x " ;;
  128. --dovecot) args="${args}-z " ;;
  129. --clamav) args="${args}-c " ;;
  130. --spamassassin) args="${args}-t " ;;
  131. --iptables) args="${args}-i " ;;
  132. --fail2ban) args="${args}-b " ;;
  133. --multiphp) args="${args}-o " ;;
  134. --quota) args="${args}-q " ;;
  135. --port) args="${args}-r " ;;
  136. --lang) args="${args}-l " ;;
  137. --interactive) args="${args}-y " ;;
  138. --api) args="${args}-d " ;;
  139. --hostname) args="${args}-s " ;;
  140. --email) args="${args}-e " ;;
  141. --password) args="${args}-p " ;;
  142. --force) args="${args}-f " ;;
  143. --help) args="${args}-h " ;;
  144. *) [[ "${arg:0:1}" == "-" ]] || delim="\""
  145. args="${args}${delim}${arg}${delim} ";;
  146. esac
  147. done
  148. eval set -- "$args"
  149. # Parsing arguments
  150. while getopts "a:n:w:v:j:k:m:g:d:x:z:c:t:i:b:r:o:q:l:y:s:e:p:fh" Option; do
  151. case $Option in
  152. a) apache=$OPTARG ;; # Apache
  153. n) nginx=$OPTARG ;; # Nginx
  154. w) phpfpm=$OPTARG ;; # PHP-FPM
  155. o) multiphp=$OPTARG ;; # Multi-PHP
  156. v) vsftpd=$OPTARG ;; # Vsftpd
  157. j) proftpd=$OPTARG ;; # Proftpd
  158. k) named=$OPTARG ;; # Named
  159. m) mysql=$OPTARG ;; # MariaDB
  160. g) postgresql=$OPTARG ;; # PostgreSQL
  161. x) exim=$OPTARG ;; # Exim
  162. z) dovecot=$OPTARG ;; # Dovecot
  163. c) clamd=$OPTARG ;; # ClamAV
  164. t) spamd=$OPTARG ;; # SpamAssassin
  165. i) iptables=$OPTARG ;; # Iptables
  166. b) fail2ban=$OPTARG ;; # Fail2ban
  167. q) quota=$OPTARG ;; # FS Quota
  168. r) port=$OPTARG ;; # Backend Port
  169. l) lang=$OPTARG ;; # Language
  170. d) api=$OPTARG ;; # Activate API
  171. y) interactive=$OPTARG ;; # Interactive install
  172. s) servername=$OPTARG ;; # Hostname
  173. e) email=$OPTARG ;; # Admin email
  174. p) vpass=$OPTARG ;; # Admin password
  175. f) force='yes' ;; # Force install
  176. h) help ;; # Help
  177. *) help ;; # Print help (default)
  178. esac
  179. done
  180. # Defining default software stack
  181. set_default_value 'nginx' 'yes'
  182. set_default_value 'apache' 'yes'
  183. set_default_value 'phpfpm' 'no'
  184. set_default_value 'multiphp' 'no'
  185. set_default_value 'vsftpd' 'yes'
  186. set_default_value 'proftpd' 'no'
  187. set_default_value 'named' 'yes'
  188. set_default_value 'mysql' 'yes'
  189. set_default_value 'postgresql' 'no'
  190. set_default_value 'exim' 'yes'
  191. set_default_value 'dovecot' 'yes'
  192. if [ $memory -lt 1500000 ]; then
  193. set_default_value 'clamd' 'no'
  194. set_default_value 'spamd' 'no'
  195. else
  196. set_default_value 'clamd' 'yes'
  197. set_default_value 'spamd' 'yes'
  198. fi
  199. set_default_value 'iptables' 'yes'
  200. set_default_value 'fail2ban' 'yes'
  201. set_default_value 'quota' 'no'
  202. set_default_value 'interactive' 'yes'
  203. set_default_value 'api' 'yes'
  204. set_default_port '8083'
  205. set_default_lang 'en'
  206. # Checking software conflicts
  207. if [ "$phpfpm" = 'yes' ]; then
  208. apache='no'
  209. nginx='yes'
  210. fi
  211. if [ "$multiphp" = 'yes' ]; then
  212. phpfpm='no'
  213. fi
  214. if [ "$proftpd" = 'yes' ]; then
  215. vsftpd='no'
  216. fi
  217. if [ "$exim" = 'no' ]; then
  218. clamd='no'
  219. spamd='no'
  220. dovecot='no'
  221. fi
  222. if [ "$iptables" = 'no' ]; then
  223. fail2ban='no'
  224. fi
  225. # Checking root permissions
  226. if [ "x$(id -u)" != 'x0' ]; then
  227. check_result 1 "Script can be run executed only by root"
  228. fi
  229. # Checking admin user account
  230. if [ ! -z "$(grep ^admin: /etc/passwd /etc/group)" ] && [ -z "$force" ]; then
  231. echo 'Please remove admin user account before proceeding.'
  232. echo 'If you want to do it automatically run installer with -f option:'
  233. echo -e "Example: bash $0 --force\n"
  234. check_result 1 "User admin exists"
  235. fi
  236. # Update apt repository
  237. echo "Please wait a few seconds, we update your repository before we start the installation process..."
  238. apt-get -qq update
  239. # Creating backup directory
  240. mkdir -p $hst_backups
  241. # Checking wget
  242. if [ ! -e '/usr/bin/wget' ]; then
  243. echo "Install missing wget..."
  244. apt-get -y install wget >> $LOG
  245. check_result $? "Can't install wget"
  246. fi
  247. # Check if apt-transport-https is installed
  248. if [ ! -e '/usr/lib/apt/methods/https' ]; then
  249. echo "Install missing apt-transport-https..."
  250. apt-get -y install apt-transport-https >> $LOG
  251. check_result $? "Can't install apt-transport-https"
  252. fi
  253. # Check if apt-add-repository is installed
  254. if [ ! -e '/usr/bin/apt-add-repository' ]; then
  255. echo "Install missing apt-add-repository..."
  256. apt-get -y install python-software-properties >> $LOG
  257. check_result $? "Can't install python-software-properties"
  258. fi
  259. # Checking repository availability
  260. wget --quiet "https://$GPG/deb_signing.key" -O /dev/null
  261. check_result $? "No access to Hestia repository"
  262. # Checking installed packages
  263. tmpfile=$(mktemp -p /tmp)
  264. dpkg --get-selections > $tmpfile
  265. for pkg in exim4 mariadb-server apache2 nginx hestia; do
  266. if [ ! -z "$(grep $pkg $tmpfile)" ]; then
  267. conflicts="$pkg $conflicts"
  268. fi
  269. done
  270. rm -f $tmpfile
  271. if [ ! -z "$conflicts" ] && [ -z "$force" ]; then
  272. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  273. echo
  274. echo 'Following packages are already installed:'
  275. echo "$conflicts"
  276. echo
  277. echo 'It is highly recommended to remove them before proceeding.'
  278. echo 'If you want to force installation run this script with -f option:'
  279. echo "Example: bash $0 --force"
  280. echo
  281. echo '!!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!! !!!'
  282. echo
  283. check_result 1 "Control Panel should be installed on clean server."
  284. fi
  285. #----------------------------------------------------------#
  286. # Brief Info #
  287. #----------------------------------------------------------#
  288. # Printing nice ASCII logo
  289. clear
  290. echo
  291. echo ' _ _ _ _ ____ ____ '
  292. echo ' | | | | ___ ___| |_(_) __ _ / ___| _ \ '
  293. echo ' | |_| |/ _ \/ __| __| |/ _` | | | |_) |'
  294. echo ' | _ | __/\__ \ |_| | (_| | |___| __/ '
  295. echo ' |_| |_|\___||___/\__|_|\__,_|\____|_| '
  296. echo
  297. echo ' Hestia Control Panel'
  298. echo -e "\n\n"
  299. echo 'The following software will be installed on your system:'
  300. # Web stack
  301. if [ "$nginx" = 'yes' ]; then
  302. echo ' - Nginx Web Server'
  303. fi
  304. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  305. echo ' - Apache Web Server'
  306. fi
  307. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  308. echo ' - Apache Web Server (as backend)'
  309. fi
  310. if [ "$phpfpm" = 'yes' ]; then
  311. echo ' - PHP-FPM Application Server'
  312. fi
  313. if [ "$multiphp" = 'yes' ]; then
  314. echo ' - Multi-PHP Environment'
  315. fi
  316. # DNS stack
  317. if [ "$named" = 'yes' ]; then
  318. echo ' - Bind DNS Server'
  319. fi
  320. # Mail stack
  321. if [ "$exim" = 'yes' ]; then
  322. echo -n ' - Exim Mail Server'
  323. if [ "$clamd" = 'yes' ] || [ "$spamd" = 'yes' ] ; then
  324. echo -n ' + '
  325. if [ "$clamd" = 'yes' ]; then
  326. echo -n 'ClamAV'
  327. fi
  328. if [ "$spamd" = 'yes' ]; then
  329. echo -n 'SpamAssassin'
  330. fi
  331. fi
  332. echo
  333. if [ "$dovecot" = 'yes' ]; then
  334. echo ' - Dovecot POP3/IMAP Server'
  335. fi
  336. fi
  337. # Database stack
  338. if [ "$mysql" = 'yes' ]; then
  339. echo ' - MariaDB Database Server'
  340. fi
  341. if [ "$postgresql" = 'yes' ]; then
  342. echo ' - PostgreSQL Database Server'
  343. fi
  344. # FTP stack
  345. if [ "$vsftpd" = 'yes' ]; then
  346. echo ' - Vsftpd FTP Server'
  347. fi
  348. if [ "$proftpd" = 'yes' ]; then
  349. echo ' - ProFTPD FTP Server'
  350. fi
  351. # Firewall stack
  352. if [ "$iptables" = 'yes' ]; then
  353. echo -n ' - Iptables Firewall'
  354. fi
  355. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  356. echo -n ' + Fail2Ban'
  357. fi
  358. echo -e "\n\n"
  359. # Asking for confirmation to proceed
  360. if [ "$interactive" = 'yes' ]; then
  361. read -p 'Would you like to continue [y/n]: ' answer
  362. if [ "$answer" != 'y' ] && [ "$answer" != 'Y' ]; then
  363. echo 'Goodbye'
  364. exit 1
  365. fi
  366. # Asking for contact email
  367. if [ -z "$email" ]; then
  368. read -p 'Please enter admin email address: ' email
  369. fi
  370. # Asking to set FQDN hostname
  371. if [ -z "$servername" ]; then
  372. read -p "Please enter FQDN hostname [$(hostname -f)]: " servername
  373. fi
  374. fi
  375. # Generating admin password if it wasn't set
  376. if [ -z "$vpass" ]; then
  377. vpass=$(gen_pass)
  378. fi
  379. # Set hostname if it wasn't set
  380. if [ -z "$servername" ]; then
  381. servername=$(hostname -f)
  382. fi
  383. # Set FQDN if it wasn't set
  384. mask1='(([[:alnum:]](-?[[:alnum:]])*)\.)'
  385. mask2='*[[:alnum:]](-?[[:alnum:]])+\.[[:alnum:]]{2,}'
  386. if ! [[ "$servername" =~ ^${mask1}${mask2}$ ]]; then
  387. if [ ! -z "$servername" ]; then
  388. servername="$servername.example.com"
  389. else
  390. servername="example.com"
  391. fi
  392. echo "127.0.0.1 $servername" >> /etc/hosts
  393. fi
  394. # Set email if it wasn't set
  395. if [ -z "$email" ]; then
  396. email="admin@$servername"
  397. fi
  398. # Defining backup directory
  399. echo "Installation backup directory: $hst_backups"
  400. # Print Log File Path
  401. echo "Installation Log File: $LOG"
  402. # Printing start message and sleeping for 2 seconds
  403. echo -e "\n\nWe will now install HestiaCP and all required packages. The process will take around 10-15 minutes...\n"
  404. sleep 2
  405. #----------------------------------------------------------#
  406. # Checking swap #
  407. #----------------------------------------------------------#
  408. # Checking swap on small instances
  409. if [ -z "$(swapon -s)" ] && [ $memory -lt 1000000 ]; then
  410. fallocate -l 1G /swapfile
  411. chmod 600 /swapfile
  412. mkswap /swapfile
  413. swapon /swapfile
  414. echo "/swapfile none swap sw 0 0" >> /etc/fstab
  415. fi
  416. #----------------------------------------------------------#
  417. # Install repository #
  418. #----------------------------------------------------------#
  419. # Updating system
  420. echo "Upgrade System using apt-get..."
  421. apt-get -y upgrade >> $LOG
  422. check_result $? 'apt-get upgrade failed'
  423. # Define apt conf location
  424. apt=/etc/apt/sources.list.d
  425. # Installing nginx repo
  426. echo "deb http://nginx.org/packages/mainline/$VERSION/ $codename nginx" \
  427. > $apt/nginx.list
  428. wget --quiet http://nginx.org/keys/nginx_signing.key -O /tmp/nginx_signing.key
  429. apt-key add /tmp/nginx_signing.key >> $LOG
  430. if [ "$multiphp" = 'yes' ] || [ "$phpfpm" = 'yes' ]; then
  431. # Installing sury php repo
  432. add-apt-repository -y ppa:ondrej/php >> $LOG
  433. fi
  434. # Installing MariaDB repo
  435. echo "deb http://ams2.mirrors.digitalocean.com/mariadb/repo/10.3/$VERSION $codename main" > $apt/mariadb.list
  436. apt-key adv --recv-keys --keyserver keyserver.ubuntu.com 0xF1656F24C74CD1D8 >> $LOG
  437. # Installing hestia repo
  438. echo "deb https://$RHOST/ $codename main" > $apt/hestia.list
  439. wget --quiet https://gpg.hestiacp.com/deb_signing.key -O /tmp/deb_signing.key
  440. apt-key add /tmp/deb_signing.key >> $LOG
  441. #----------------------------------------------------------#
  442. # Backup #
  443. #----------------------------------------------------------#
  444. # Creating backup directory tree
  445. cd $hst_backups
  446. mkdir nginx apache2 php vsftpd proftpd bind exim4 dovecot clamd
  447. mkdir spamassassin mysql postgresql hestia
  448. # Backup nginx configuration
  449. service nginx stop > /dev/null 2>&1
  450. cp -r /etc/nginx/* $hst_backups/nginx > /dev/null 2>&1
  451. # Backup Apache configuration
  452. service apache2 stop > /dev/null 2>&1
  453. cp -r /etc/apache2/* $hst_backups/apache2 > /dev/null 2>&1
  454. rm -f /etc/apache2/conf.d/* > /dev/null 2>&1
  455. # Backup PHP-FPM configuration
  456. service php*-fpm stop > /dev/null 2>&1
  457. cp -r /etc/php/* $hst_backups/php/ > /dev/null 2>&1
  458. # Backup Bind configuration
  459. service bind9 stop > /dev/null 2>&1
  460. cp -r /etc/bind/* $hst_backups/bind > /dev/null 2>&1
  461. # Backup Vsftpd configuration
  462. service vsftpd stop > /dev/null 2>&1
  463. cp /etc/vsftpd.conf $hst_backups/vsftpd > /dev/null 2>&1
  464. # Backup ProFTPD configuration
  465. service proftpd stop > /dev/null 2>&1
  466. cp /etc/proftpd.conf $hst_backups/proftpd > /dev/null 2>&1
  467. # Backup Exim configuration
  468. service exim4 stop > /dev/null 2>&1
  469. cp -r /etc/exim4/* $hst_backups/exim4 > /dev/null 2>&1
  470. # Backup ClamAV configuration
  471. service clamav-daemon stop > /dev/null 2>&1
  472. cp -r /etc/clamav/* $hst_backups/clamav > /dev/null 2>&1
  473. # Backup SpamAssassin configuration
  474. service spamassassin stop > /dev/null 2>&1
  475. cp -r /etc/spamassassin/* $hst_backups/spamassassin > /dev/null 2>&1
  476. # Backup Dovecot configuration
  477. service dovecot stop > /dev/null 2>&1
  478. cp /etc/dovecot.conf $hst_backups/dovecot > /dev/null 2>&1
  479. cp -r /etc/dovecot/* $hst_backups/dovecot > /dev/null 2>&1
  480. # Backup MySQL/MariaDB configuration and data
  481. service mysql stop > /dev/null 2>&1
  482. killall -9 mysqld > /dev/null 2>&1
  483. mv /var/lib/mysql $hst_backups/mysql/mysql_datadir > /dev/null 2>&1
  484. cp -r /etc/mysql/* $hst_backups/mysql > /dev/null 2>&1
  485. mv -f /root/.my.cnf $hst_backups/mysql > /dev/null 2>&1
  486. # Backup Hestia
  487. service hestia stop > /dev/null 2>&1
  488. cp -r $HESTIA/* $hst_backups/hestia > /dev/null 2>&1
  489. apt-get -y purge hestia hestia-nginx hestia-php > /dev/null 2>&1
  490. rm -rf $HESTIA > /dev/null 2>&1
  491. #----------------------------------------------------------#
  492. # Package Excludes #
  493. #----------------------------------------------------------#
  494. # Excluding packages
  495. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  496. if [ "$nginx" = 'no' ]; then
  497. software=$(echo "$software" | sed -e "s/^nginx//")
  498. fi
  499. if [ "$apache" = 'no' ]; then
  500. software=$(echo "$software" | sed -e "s/apache2 //")
  501. software=$(echo "$software" | sed -e "s/apache2-utils//")
  502. software=$(echo "$software" | sed -e "s/apache2-suexec-custom//")
  503. software=$(echo "$software" | sed -e "s/apache2.2-common//")
  504. software=$(echo "$software" | sed -e "s/libapache2-mod-ruid2//")
  505. software=$(echo "$software" | sed -e "s/libapache2-mod-rpaf//")
  506. software=$(echo "$software" | sed -e "s/libapache2-mod-fcgid//")
  507. software=$(echo "$software" | sed -e "s/libapache2-mod-php7.2//")
  508. software=$(echo "$software" | sed -e "s/libapache2-mod-php//")
  509. fi
  510. if [ "$vsftpd" = 'no' ]; then
  511. software=$(echo "$software" | sed -e "s/vsftpd//")
  512. fi
  513. if [ "$proftpd" = 'no' ]; then
  514. software=$(echo "$software" | sed -e "s/proftpd-basic//")
  515. software=$(echo "$software" | sed -e "s/proftpd-mod-vroot//")
  516. fi
  517. if [ "$named" = 'no' ]; then
  518. software=$(echo "$software" | sed -e "s/bind9//")
  519. fi
  520. if [ "$exim" = 'no' ]; then
  521. software=$(echo "$software" | sed -e "s/exim4 //")
  522. software=$(echo "$software" | sed -e "s/exim4-daemon-heavy//")
  523. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  524. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  525. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  526. software=$(echo "$software" | sed -e "s/spamassassin//")
  527. fi
  528. if [ "$clamd" = 'no' ]; then
  529. software=$(echo "$software" | sed -e "s/clamav-daemon//")
  530. fi
  531. if [ "$spamd" = 'no' ]; then
  532. software=$(echo "$software" | sed -e "s/spamassassin//")
  533. fi
  534. if [ "$dovecot" = 'no' ]; then
  535. software=$(echo "$software" | sed -e "s/dovecot-imapd//")
  536. software=$(echo "$software" | sed -e "s/dovecot-pop3d//")
  537. fi
  538. if [ "$mysql" = 'no' ]; then
  539. software=$(echo "$software" | sed -e 's/mariadb-server//')
  540. software=$(echo "$software" | sed -e 's/mariadb-client//')
  541. software=$(echo "$software" | sed -e 's/mariadb-common//')
  542. software=$(echo "$software" | sed -e 's/php7.2-mysql//')
  543. software=$(echo "$software" | sed -e 's/php-mysql//')
  544. software=$(echo "$software" | sed -e 's/phpMyAdmin//')
  545. software=$(echo "$software" | sed -e 's/phpmyadmin//')
  546. fi
  547. if [ "$postgresql" = 'no' ]; then
  548. software=$(echo "$software" | sed -e 's/postgresql-contrib//')
  549. software=$(echo "$software" | sed -e 's/postgresql//')
  550. software=$(echo "$software" | sed -e 's/php7.2-pgsql//')
  551. software=$(echo "$software" | sed -e 's/php-pgsql//')
  552. software=$(echo "$software" | sed -e 's/phppgadmin//')
  553. fi
  554. if [ "$iptables" = 'no' ] || [ "$fail2ban" = 'no' ]; then
  555. software=$(echo "$software" | sed -e 's/fail2ban//')
  556. fi
  557. #----------------------------------------------------------#
  558. # Package Includes #
  559. #----------------------------------------------------------#
  560. if [ "$multiphp" = 'yes' ]; then
  561. mph="php5.6-apcu php5.6-mbstring php5.6-bcmath php5.6-cli php5.6-curl
  562. php5.6-fpm php5.6-gd php5.6-intl php5.6-mcrypt php5.6-mysql
  563. php5.6-soap php5.6-xml php5.6-zip php7.0-mbstring php7.0-bcmath
  564. php7.0-cli php7.0-curl php7.0-fpm php7.0-gd php7.0-intl php7.0-mcrypt
  565. php7.0-mysql php7.0-soap php7.0-xml php7.0-zip php7.1-mbstring
  566. php7.1-bcmath php7.1-cli php7.1-curl php7.1-fpm php7.1-gd php7.1-intl
  567. php7.1-mcrypt php7.1-mysql php7.1-soap php7.1-xml php7.1-zip
  568. php7.2-mbstring php7.2-bcmath php7.2-cli php7.2-curl php7.2-fpm
  569. php7.2-gd php7.2-intl php7.2-mysql php7.2-soap php7.2-xml
  570. php7.2-zip php7.3-mbstring php7.3-bcmath php7.3-cli php7.3-curl
  571. php7.3-fpm php7.3-gd php7.3-intl php7.3-mysql php7.3-soap php7.3-xml
  572. php7.3-zip"
  573. software="$software $mph"
  574. fi
  575. if [ "$phpfpm" = 'yes' ]; then
  576. fpm="php7.2-mbstring php7.2-bcmath php7.2-cli php7.2-curl php7.2-fpm
  577. php7.2-gd php7.2-intl php7.2-mysql php7.2-soap php7.2-xml
  578. php7.2-zip"
  579. software="$software $fpm"
  580. fi
  581. #----------------------------------------------------------#
  582. # Install packages #
  583. #----------------------------------------------------------#
  584. # Updating system
  585. apt-get -qq update
  586. # Disabling daemon autostart on apt-get install
  587. echo -e '#!/bin/sh\nexit 101' > /usr/sbin/policy-rc.d
  588. chmod a+x /usr/sbin/policy-rc.d
  589. # Installing apt packages
  590. apt-get -y install $software >> $LOG
  591. check_result $? "apt-get install failed"
  592. # Restoring autostart policy
  593. rm -f /usr/sbin/policy-rc.d
  594. #----------------------------------------------------------#
  595. # Configure system #
  596. #----------------------------------------------------------#
  597. # Enable SSH password authentication
  598. sed -i "s/rdAuthentication no/rdAuthentication yes/g" /etc/ssh/sshd_config
  599. # Disable SSH suffix broadcast
  600. echo '' >> /etc/ssh/sshd_config
  601. echo 'DebianBanner no' >> /etc/ssh/sshd_config
  602. service ssh restart
  603. # Disable AWStats cron
  604. rm -f /etc/cron.d/awstats
  605. # Set directory color
  606. echo 'LS_COLORS="$LS_COLORS:di=00;33"' >> /etc/profile
  607. # Registering /usr/sbin/nologin
  608. if [ -z "$(grep nologin /etc/shells)" ]; then
  609. echo "/usr/sbin/nologin" >> /etc/shells
  610. fi
  611. # Configuring NTP
  612. echo '#!/bin/sh' > /etc/cron.daily/ntpdate
  613. echo "$(which ntpdate) -s pool.ntp.org" >> /etc/cron.daily/ntpdate
  614. chmod 755 /etc/cron.daily/ntpdate
  615. ntpdate -s pool.ntp.org
  616. # Adding rssh
  617. if [ -z "$(grep /usr/bin/rssh /etc/shells)" ]; then
  618. echo /usr/bin/rssh >> /etc/shells
  619. fi
  620. sed -i 's/#allowscp/allowscp/' /etc/rssh.conf
  621. sed -i 's/#allowsftp/allowsftp/' /etc/rssh.conf
  622. sed -i 's/#allowrsync/allowrsync/' /etc/rssh.conf
  623. chmod 755 /usr/bin/rssh
  624. #----------------------------------------------------------#
  625. # Configure Hestia #
  626. #----------------------------------------------------------#
  627. # Installing sudo configuration
  628. mkdir -p /etc/sudoers.d
  629. cp -f $hestiacp/sudo/admin /etc/sudoers.d/
  630. chmod 440 /etc/sudoers.d/admin
  631. # Configuring system env
  632. echo "export HESTIA='$HESTIA'" > /etc/profile.d/hestia.sh
  633. echo "export VESTA='$HESTIA'" >> /etc/profile.d/hestia.sh # Vesta compatibility
  634. chmod 755 /etc/profile.d/hestia.sh
  635. source /etc/profile.d/hestia.sh
  636. echo 'PATH=$PATH:'$HESTIA'/bin' >> /root/.bash_profile
  637. echo 'export PATH' >> /root/.bash_profile
  638. source /root/.bash_profile
  639. # Configuring logrotate for Hestia logs
  640. cp -f $hestiacp/logrotate/hestia /etc/logrotate.d/hestia
  641. # Building directory tree and creating some blank files for Hestia
  642. mkdir -p $HESTIA/conf $HESTIA/log $HESTIA/ssl $HESTIA/data/ips \
  643. $HESTIA/data/queue $HESTIA/data/users $HESTIA/data/firewall \
  644. $HESTIA/data/sessions
  645. touch $HESTIA/data/queue/backup.pipe $HESTIA/data/queue/disk.pipe \
  646. $HESTIA/data/queue/webstats.pipe $HESTIA/data/queue/restart.pipe \
  647. $HESTIA/data/queue/traffic.pipe $HESTIA/log/system.log \
  648. $HESTIA/log/nginx-error.log $HESTIA/log/auth.log
  649. chmod 750 $HESTIA/conf $HESTIA/data/users $HESTIA/data/ips $HESTIA/log
  650. chmod -R 750 $HESTIA/data/queue
  651. chmod 660 $HESTIA/log/*
  652. rm -f /var/log/hestia
  653. ln -s $HESTIA/log /var/log/hestia
  654. chmod 770 $HESTIA/data/sessions
  655. # Generating Hestia configuration
  656. rm -f $HESTIA/conf/hestia.conf 2>/dev/null
  657. touch $HESTIA/conf/hestia.conf
  658. chmod 660 $HESTIA/conf/hestia.conf
  659. # Symlink to Vesta for compatibilty
  660. ln -s $HESTIA /usr/local/vesta
  661. ln -s $HESTIA/conf/hestia.conf /usr/local/vesta/conf/vesta.conf
  662. # Web stack
  663. if [ "$apache" = 'yes' ] && [ "$nginx" = 'no' ] ; then
  664. echo "WEB_SYSTEM='apache2'" >> $HESTIA/conf/hestia.conf
  665. echo "WEB_RGROUPS='www-data'" >> $HESTIA/conf/hestia.conf
  666. echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
  667. echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  668. echo "WEB_SSL='mod_ssl'" >> $HESTIA/conf/hestia.conf
  669. echo "STATS_SYSTEM='webalizer,awstats'" >> $HESTIA/conf/hestia.conf
  670. fi
  671. if [ "$apache" = 'yes' ] && [ "$nginx" = 'yes' ] ; then
  672. echo "WEB_SYSTEM='apache2'" >> $HESTIA/conf/hestia.conf
  673. echo "WEB_RGROUPS='www-data'" >> $HESTIA/conf/hestia.conf
  674. echo "WEB_PORT='8080'" >> $HESTIA/conf/hestia.conf
  675. echo "WEB_SSL_PORT='8443'" >> $HESTIA/conf/hestia.conf
  676. echo "WEB_SSL='mod_ssl'" >> $HESTIA/conf/hestia.conf
  677. echo "PROXY_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
  678. echo "PROXY_PORT='80'" >> $HESTIA/conf/hestia.conf
  679. echo "PROXY_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  680. echo "STATS_SYSTEM='webalizer,awstats'" >> $HESTIA/conf/hestia.conf
  681. fi
  682. if [ "$apache" = 'no' ] && [ "$nginx" = 'yes' ]; then
  683. echo "WEB_SYSTEM='nginx'" >> $HESTIA/conf/hestia.conf
  684. echo "WEB_PORT='80'" >> $HESTIA/conf/hestia.conf
  685. echo "WEB_SSL_PORT='443'" >> $HESTIA/conf/hestia.conf
  686. echo "WEB_SSL='openssl'" >> $HESTIA/conf/hestia.conf
  687. if [ "$phpfpm" = 'yes' ]; then
  688. echo "WEB_BACKEND='php-fpm'" >> $HESTIA/conf/hestia.conf
  689. fi
  690. echo "STATS_SYSTEM='webalizer,awstats'" >> $HESTIA/conf/hestia.conf
  691. fi
  692. # FTP stack
  693. if [ "$vsftpd" = 'yes' ]; then
  694. echo "FTP_SYSTEM='vsftpd'" >> $HESTIA/conf/hestia.conf
  695. fi
  696. if [ "$proftpd" = 'yes' ]; then
  697. echo "FTP_SYSTEM='proftpd'" >> $HESTIA/conf/hestia.conf
  698. fi
  699. # DNS stack
  700. if [ "$named" = 'yes' ]; then
  701. echo "DNS_SYSTEM='bind9'" >> $HESTIA/conf/hestia.conf
  702. fi
  703. # Mail stack
  704. if [ "$exim" = 'yes' ]; then
  705. echo "MAIL_SYSTEM='exim4'" >> $HESTIA/conf/hestia.conf
  706. if [ "$clamd" = 'yes' ]; then
  707. echo "ANTIVIRUS_SYSTEM='clamav-daemon'" >> $HESTIA/conf/hestia.conf
  708. fi
  709. if [ "$spamd" = 'yes' ]; then
  710. echo "ANTISPAM_SYSTEM='spamassassin'" >> $HESTIA/conf/hestia.conf
  711. fi
  712. if [ "$dovecot" = 'yes' ]; then
  713. echo "IMAP_SYSTEM='dovecot'" >> $HESTIA/conf/hestia.conf
  714. fi
  715. fi
  716. # Cron daemon
  717. echo "CRON_SYSTEM='cron'" >> $HESTIA/conf/hestia.conf
  718. # Firewall stack
  719. if [ "$iptables" = 'yes' ]; then
  720. echo "FIREWALL_SYSTEM='iptables'" >> $HESTIA/conf/hestia.conf
  721. fi
  722. if [ "$iptables" = 'yes' ] && [ "$fail2ban" = 'yes' ]; then
  723. echo "FIREWALL_EXTENSION='fail2ban'" >> $HESTIA/conf/hestia.conf
  724. fi
  725. # Disk quota
  726. if [ "$quota" = 'yes' ]; then
  727. echo "DISK_QUOTA='yes'" >> $HESTIA/conf/hestia.conf
  728. fi
  729. # Backups
  730. echo "BACKUP_SYSTEM='local'" >> $HESTIA/conf/hestia.conf
  731. # Language
  732. echo "LANGUAGE='$lang'" >> $HESTIA/conf/hestia.conf
  733. # Version
  734. echo "VERSION='0.9.8'" >> $HESTIA/conf/hestia.conf
  735. # Installing hosting packages
  736. cp -rf $hestiacp/packages $HESTIA/data/
  737. # Installing templates
  738. cp -rf $hestiacp/templates $HESTIA/data/
  739. # Copying index.html to default documentroot
  740. cp $HESTIA/data/templates/web/skel/public_html/index.html /var/www/
  741. sed -i 's/%domain%/It worked!/g' /var/www/index.html
  742. # Installing firewall rules
  743. cp -rf $hestiacp/firewall $HESTIA/data/
  744. # Configuring server hostname
  745. $HESTIA/bin/v-change-sys-hostname $servername 2>/dev/null
  746. # Generating SSL certificate
  747. $HESTIA/bin/v-generate-ssl-cert $(hostname) $email 'US' 'California' \
  748. 'San Francisco' 'Hestia Control Panel' 'IT' > /tmp/hst.pem
  749. # Parsing certificate file
  750. crt_end=$(grep -n "END CERTIFICATE-" /tmp/hst.pem |cut -f 1 -d:)
  751. key_start=$(grep -n "BEGIN RSA" /tmp/hst.pem |cut -f 1 -d:)
  752. key_end=$(grep -n "END RSA" /tmp/hst.pem |cut -f 1 -d:)
  753. # Adding SSL certificate
  754. cd $HESTIA/ssl
  755. sed -n "1,${crt_end}p" /tmp/hst.pem > certificate.crt
  756. sed -n "$key_start,${key_end}p" /tmp/hst.pem > certificate.key
  757. chown root:mail $HESTIA/ssl/*
  758. chmod 660 $HESTIA/ssl/*
  759. rm /tmp/hst.pem
  760. # Adding nologin as a valid system shell
  761. if [ -z "$(grep nologin /etc/shells)" ]; then
  762. echo "/usr/sbin/nologin" >> /etc/shells
  763. fi
  764. #----------------------------------------------------------#
  765. # Configure Nginx #
  766. #----------------------------------------------------------#
  767. if [ "$nginx" = 'yes' ]; then
  768. rm -f /etc/nginx/conf.d/*.conf
  769. cp -f $hestiacp/nginx/nginx.conf /etc/nginx/
  770. cp -f $hestiacp/nginx/status.conf /etc/nginx/conf.d/
  771. cp -f $hestiacp/nginx/phpmyadmin.inc /etc/nginx/conf.d/
  772. cp -f $hestiacp/nginx/phppgadmin.inc /etc/nginx/conf.d/
  773. cp -f $hestiacp/nginx/webmail.inc /etc/nginx/conf.d/
  774. cp -f $hestiacp/logrotate/nginx /etc/logrotate.d/
  775. echo > /etc/nginx/conf.d/hestia.conf
  776. mkdir -p /var/log/nginx/domains
  777. if [ "$apache" = 'no' ] && [ "$multiphp" = 'yes' ]; then
  778. update-rc.d php5.6-fpm defaults > /dev/null 2>&1
  779. update-rc.d php7.0-fpm defaults > /dev/null 2>&1
  780. update-rc.d php7.1-fpm defaults > /dev/null 2>&1
  781. update-rc.d php7.2-fpm defaults > /dev/null 2>&1
  782. update-rc.d php7.3-fpm defaults > /dev/null 2>&1
  783. cp -r /etc/php/5.6/ /root/hst_install_backups/php5.6/
  784. rm -f /etc/php/5.6/fpm/pool.d/*
  785. cp -r /etc/php/7.0/ /root/hst_install_backups/php7.0/
  786. rm -f /etc/php/7.0/fpm/pool.d/*
  787. cp -r /etc/php/7.1/ /root/hst_install_backups/php7.1/
  788. rm -f /etc/php/7.1/fpm/pool.d/*
  789. cp -r /etc/php/7.2/ /root/hst_install_backups/php7.2/
  790. rm -f /etc/php/7.2/fpm/pool.d/*
  791. cp -r /etc/php/7.3/ /root/hst_install_backups/php7.3/
  792. rm -f /etc/php/7.3/fpm/pool.d/*
  793. rm -fr $HESTIA/data/templates/web/nginx/*
  794. cp -f $hestiacp/multiphp/nginx/* $HESTIA/data/templates/web/nginx/
  795. cp -f $hestiacp/php-fpm/www.conf /etc/php/7.2/fpm/pool.d/
  796. ln -s $HESTIA/data/templates/web/nginx/PHP-72.sh $HESTIA/data/templates/web/nginx/default.sh
  797. ln -s $HESTIA/data/templates/web/nginx/PHP-72.tpl $HESTIA/data/templates/web/nginx/default.tpl
  798. ln -s $HESTIA/data/templates/web/nginx/PHP-72.stpl $HESTIA/data/templates/web/nginx/default.stpl
  799. chmod a+x $HESTIA/data/templates/web/nginx/*.sh
  800. service php7.2-fpm start > /dev/null 2>&1
  801. check_result $? "php7.2-fpm start failed"
  802. fi
  803. update-rc.d nginx defaults > /dev/null 2>&1
  804. service nginx start >> $LOG
  805. check_result $? "nginx start failed"
  806. fi
  807. #----------------------------------------------------------#
  808. # Configure Apache #
  809. #----------------------------------------------------------#
  810. if [ "$apache" = 'yes' ]; then
  811. cp -f $hestiacp/apache2/apache2.conf /etc/apache2/
  812. cp -f $hestiacp/apache2/status.conf /etc/apache2/mods-enabled/
  813. cp -f $hestiacp/logrotate/apache2 /etc/logrotate.d/
  814. a2enmod rewrite > /dev/null 2>&1
  815. a2enmod suexec > /dev/null 2>&1
  816. a2enmod ssl > /dev/null 2>&1
  817. a2enmod actions > /dev/null 2>&1
  818. a2enmod ruid2 > /dev/null 2>&1
  819. mkdir -p /etc/apache2/conf.d
  820. echo > /etc/apache2/conf.d/hestia.conf
  821. echo "# Powered by hestia" > /etc/apache2/sites-available/default
  822. echo "# Powered by hestia" > /etc/apache2/sites-available/default-ssl
  823. echo "# Powered by hestia" > /etc/apache2/ports.conf
  824. echo -e "/home\npublic_html/cgi-bin" > /etc/apache2/suexec/www-data
  825. touch /var/log/apache2/access.log /var/log/apache2/error.log
  826. mkdir -p /var/log/apache2/domains
  827. chmod a+x /var/log/apache2
  828. chmod 640 /var/log/apache2/access.log /var/log/apache2/error.log
  829. chmod 751 /var/log/apache2/domains
  830. if [ "$multiphp" = 'yes' ] ; then
  831. a2enmod proxy_fcgi setenvif > /dev/null 2>&1
  832. a2enconf php5.6-fpm > /dev/null 2>&1
  833. a2enconf php7.0-fpm > /dev/null 2>&1
  834. a2enconf php7.1-fpm > /dev/null 2>&1
  835. a2enconf php7.2-fpm > /dev/null 2>&1
  836. a2enconf php7.3-fpm > /dev/null 2>&1
  837. update-rc.d php5.6-fpm defaults > /dev/null 2>&1
  838. update-rc.d php7.0-fpm defaults > /dev/null 2>&1
  839. update-rc.d php7.1-fpm defaults > /dev/null 2>&1
  840. update-rc.d php7.2-fpm defaults > /dev/null 2>&1
  841. update-rc.d php7.3-fpm defaults > /dev/null 2>&1
  842. cp -r /etc/php/5.6/ /root/hst_install_backups/php5.6/
  843. rm -f /etc/php/5.6/fpm/pool.d/*
  844. cp -r /etc/php/7.0/ /root/hst_install_backups/php7.0/
  845. rm -f /etc/php/7.0/fpm/pool.d/*
  846. cp -r /etc/php/7.1/ /root/hst_install_backups/php7.1/
  847. rm -f /etc/php/7.1/fpm/pool.d/*
  848. cp -r /etc/php/7.2/ /root/hst_install_backups/php7.2/
  849. rm -f /etc/php/7.2/fpm/pool.d/*
  850. cp -r /etc/php/7.3/ /root/hst_install_backups/php7.3/
  851. rm -f /etc/php/7.3/fpm/pool.d/*
  852. cp -f $hestiacp/multiphp/apache2/* $HESTIA/data/templates/web/apache2/
  853. chmod a+x $HESTIA/data/templates/web/apache2/*.sh
  854. fi
  855. update-rc.d apache2 defaults > /dev/null 2>&1
  856. service apache2 start >> $LOG
  857. check_result $? "apache2 start failed"
  858. else
  859. update-rc.d apache2 disable > /dev/null 2>&1
  860. service apache2 stop >> $LOG
  861. fi
  862. #----------------------------------------------------------#
  863. # Configure PHP-FPM #
  864. #----------------------------------------------------------#
  865. if [ "$phpfpm" = 'yes' ]; then
  866. cp -f $hestiacp/php-fpm/www.conf /etc/php/7.2/fpm/pool.d/www.conf
  867. update-rc.d php7.2-fpm defaults > /dev/null 2>&1
  868. service php7.2-fpm start >> $LOG
  869. check_result $? "php-fpm start failed"
  870. fi
  871. #----------------------------------------------------------#
  872. # Configure PHP #
  873. #----------------------------------------------------------#
  874. ZONE=$(timedatectl 2>/dev/null|grep Timezone|awk '{print $2}')
  875. if [ -z "$ZONE" ]; then
  876. ZONE='UTC'
  877. fi
  878. for pconf in $(find /etc/php* -name php.ini); do
  879. sed -i "s%;date.timezone =%date.timezone = $ZONE%g" $pconf
  880. sed -i 's%_open_tag = Off%_open_tag = On%g' $pconf
  881. done
  882. #----------------------------------------------------------#
  883. # Configure Vsftpd #
  884. #----------------------------------------------------------#
  885. if [ "$vsftpd" = 'yes' ]; then
  886. cp -f $hestiacp/vsftpd/vsftpd.conf /etc/
  887. touch /var/log/vsftpd.log
  888. chown root:adm /var/log/vsftpd.log
  889. chmod 640 /var/log/vsftpd.log
  890. touch /var/log/xferlog
  891. chown root:adm /var/log/xferlog
  892. chmod 640 /var/log/xferlog
  893. update-rc.d vsftpd defaults
  894. service vsftpd start
  895. check_result $? "vsftpd start failed"
  896. fi
  897. #----------------------------------------------------------#
  898. # Configure ProFTPD #
  899. #----------------------------------------------------------#
  900. if [ "$proftpd" = 'yes' ]; then
  901. echo "127.0.0.1 $servername" >> /etc/hosts
  902. cp -f $hestiacp/proftpd/proftpd.conf /etc/proftpd/
  903. update-rc.d proftpd defaults > /dev/null 2>&1
  904. service proftpd start >> $LOG
  905. check_result $? "proftpd start failed"
  906. fi
  907. #----------------------------------------------------------#
  908. # Configure MariaDB #
  909. #----------------------------------------------------------#
  910. if [ "$mysql" = 'yes' ]; then
  911. mycnf="my-small.cnf"
  912. if [ $memory -gt 1200000 ]; then
  913. mycnf="my-medium.cnf"
  914. fi
  915. if [ $memory -gt 3900000 ]; then
  916. mycnf="my-large.cnf"
  917. fi
  918. # Configuring MariaDB
  919. cp -f $hestiacp/mysql/$mycnf /etc/mysql/my.cnf
  920. mysql_install_db >> $LOG
  921. update-rc.d mysql defaults
  922. service mysql start
  923. check_result $? "mariadb start failed"
  924. # Securing MariaDB installation
  925. mpass=$(gen_pass)
  926. mysqladmin -u root password $mpass >> $LOG
  927. echo -e "[client]\npassword='$mpass'\n" > /root/.my.cnf
  928. chmod 600 /root/.my.cnf
  929. # Clear MariaDB Test Users and Databases
  930. mysql -e "DELETE FROM mysql.user WHERE User=''"
  931. mysql -e "DROP DATABASE test" > /dev/null 2>&1
  932. mysql -e "DELETE FROM mysql.db WHERE Db='test' OR Db='test\\_%'"
  933. mysql -e "DELETE FROM mysql.user WHERE user='';"
  934. mysql -e "DELETE FROM mysql.user WHERE password='' AND authentication_string='';"
  935. # Configuring phpMyAdmin
  936. if [ "$apache" = 'yes' ]; then
  937. cp -f $hestiacp/pma/apache.conf /etc/phpmyadmin/
  938. ln -s /etc/phpmyadmin/apache.conf /etc/apache2/conf.d/phpmyadmin.conf
  939. fi
  940. cp -f $hestiacp/pma/config.inc.php /etc/phpmyadmin/
  941. chmod 777 /var/lib/phpmyadmin/tmp
  942. fi
  943. #----------------------------------------------------------#
  944. # Update phpMyAdmin #
  945. #----------------------------------------------------------#
  946. # Display upgrade information
  947. echo "Upgrade phpMyAdmin to v$pma_v..."
  948. # Download latest phpmyadmin release
  949. wget --quiet https://files.phpmyadmin.net/phpMyAdmin/$pma_v/phpMyAdmin-$pma_v-all-languages.tar.gz
  950. # Unpack files
  951. tar xzf phpMyAdmin-$pma_v-all-languages.tar.gz
  952. # Delete file to prevent error
  953. if [ "$pma_v" = '4.8.3' ]; then
  954. rm -fr /usr/share/phpmyadmin/doc/html
  955. fi
  956. # Overwrite old files
  957. cp -rf phpMyAdmin-$pma_v-all-languages/* /usr/share/phpmyadmin
  958. # Set config and log directory
  959. sed -i "s|define('CONFIG_DIR', '');|define('CONFIG_DIR', '/etc/phpmyadmin/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  960. sed -i "s|define('TEMP_DIR', './tmp/');|define('TEMP_DIR', '/var/lib/phpmyadmin/tmp/');|" /usr/share/phpmyadmin/libraries/vendor_config.php
  961. # Create temporary folder and change permission
  962. mkdir /usr/share/phpmyadmin/tmp
  963. chmod 777 /usr/share/phpmyadmin/tmp
  964. # Clear Up
  965. rm -fr phpMyAdmin-$pma_v-all-languages
  966. rm -f phpMyAdmin-$pma_v-all-languages.tar.gz
  967. #----------------------------------------------------------#
  968. # Configure PostgreSQL #
  969. #----------------------------------------------------------#
  970. if [ "$postgresql" = 'yes' ]; then
  971. ppass=$(gen_pass)
  972. cp -f $hestiacp/postgresql/pg_hba.conf /etc/postgresql/*/main/
  973. service postgresql restart
  974. sudo -u postgres psql -c "ALTER USER postgres WITH PASSWORD '$ppass'"
  975. # Configuring phpPgAdmin
  976. if [ "$apache" = 'yes' ]; then
  977. cp -f $hestiacp/pga/phppgadmin.conf /etc/apache2/conf.d/
  978. fi
  979. cp -f $hestiacp/pga/config.inc.php /etc/phppgadmin/
  980. fi
  981. #----------------------------------------------------------#
  982. # Configure Bind #
  983. #----------------------------------------------------------#
  984. if [ "$named" = 'yes' ]; then
  985. cp -f $hestiacp/bind/named.conf /etc/bind/
  986. cp -f $hestiacp/bind/named.conf.options /etc/bind/
  987. chown root:bind /etc/bind/named.conf
  988. chown root:bind /etc/bind/named.conf.options
  989. chmod 640 /etc/bind/named.conf
  990. chmod 640 /etc/bind/named.conf.options
  991. aa-complain /usr/sbin/named > /dev/null 2>&1
  992. echo "/home/** rwm," >> /etc/apparmor.d/local/usr.sbin.named 2>/dev/null
  993. service apparmor status >> $LOG
  994. if [ $? -ne 0 ]; then
  995. service apparmor restart
  996. fi
  997. update-rc.d bind9 defaults
  998. service bind9 start
  999. check_result $? "bind9 start failed"
  1000. # Workaround for OpenVZ/Virtuozzo
  1001. if [ -e "/proc/vz/veinfo" ]; then
  1002. sed -i "s/^exit 0/service bind9 restart\nexit 0/" /etc/rc.local
  1003. fi
  1004. fi
  1005. #----------------------------------------------------------#
  1006. # Configure Exim #
  1007. #----------------------------------------------------------#
  1008. if [ "$exim" = 'yes' ]; then
  1009. gpasswd -a Debian-exim mail > /dev/null 2>&1
  1010. cp -f $hestiacp/exim/exim4.conf.template /etc/exim4/
  1011. cp -f $hestiacp/exim/dnsbl.conf /etc/exim4/
  1012. cp -f $hestiacp/exim/spam-blocks.conf /etc/exim4/
  1013. touch /etc/exim4/white-blocks.conf
  1014. if [ "$spamd" = 'yes' ]; then
  1015. sed -i "s/#SPAM/SPAM/g" /etc/exim4/exim4.conf.template
  1016. fi
  1017. if [ "$clamd" = 'yes' ]; then
  1018. sed -i "s/#CLAMD/CLAMD/g" /etc/exim4/exim4.conf.template
  1019. fi
  1020. chmod 640 /etc/exim4/exim4.conf.template
  1021. rm -rf /etc/exim4/domains
  1022. mkdir -p /etc/exim4/domains
  1023. rm -f /etc/alternatives/mta
  1024. ln -s /usr/sbin/exim4 /etc/alternatives/mta
  1025. update-rc.d -f sendmail remove > /dev/null 2>&1
  1026. service sendmail stop >> $LOG
  1027. update-rc.d -f postfix remove > /dev/null 2>&1
  1028. service postfix stop >> $LOG
  1029. update-rc.d exim4 defaults
  1030. service exim4 start
  1031. check_result $? "exim4 start failed"
  1032. fi
  1033. #----------------------------------------------------------#
  1034. # Configure Dovecot #
  1035. #----------------------------------------------------------#
  1036. if [ "$dovecot" = 'yes' ]; then
  1037. gpasswd -a dovecot mail > /dev/null 2>&1
  1038. cp -rf $hestiacp/dovecot /etc/
  1039. cp -f $hestiacp/logrotate/dovecot /etc/logrotate.d/
  1040. if [ "$release" = '18.04' ]; then
  1041. rm -f /etc/dovecot/conf.d/15-mailboxes.conf
  1042. fi
  1043. chown -R root:root /etc/dovecot*
  1044. update-rc.d dovecot defaults
  1045. service dovecot start
  1046. check_result $? "dovecot start failed"
  1047. fi
  1048. #----------------------------------------------------------#
  1049. # Configure ClamAV #
  1050. #----------------------------------------------------------#
  1051. if [ "$clamd" = 'yes' ]; then
  1052. gpasswd -a clamav mail > /dev/null 2>&1
  1053. gpasswd -a clamav Debian-exim > /dev/null 2>&1
  1054. cp -f $hestiacp/clamav/clamd.conf /etc/clamav/
  1055. update-rc.d clamav-daemon defaults
  1056. echo "Updating ClamAV..."
  1057. /usr/bin/freshclam >> $LOG
  1058. service clamav-daemon start
  1059. check_result $? "clamav-daemon start failed"
  1060. fi
  1061. #----------------------------------------------------------#
  1062. # Configure SpamAssassin #
  1063. #----------------------------------------------------------#
  1064. if [ "$spamd" = 'yes' ]; then
  1065. update-rc.d spamassassin defaults > /dev/null 2>&1
  1066. sed -i "s/ENABLED=0/ENABLED=1/" /etc/default/spamassassin
  1067. service spamassassin start >> $LOG
  1068. check_result $? "spamassassin start failed"
  1069. unit_files="$(systemctl list-unit-files |grep spamassassin)"
  1070. if [[ "$unit_files" =~ "disabled" ]]; then
  1071. systemctl enable spamassassin > /dev/null 2>&1
  1072. fi
  1073. fi
  1074. #----------------------------------------------------------#
  1075. # Configure Roundcube #
  1076. #----------------------------------------------------------#
  1077. if [ "$exim" = 'yes' ] && [ "$mysql" = 'yes' ]; then
  1078. if [ "$apache" = 'yes' ]; then
  1079. cp -f $hestiacp/roundcube/apache.conf /etc/roundcube/
  1080. ln -s /etc/roundcube/apache.conf /etc/apache2/conf.d/roundcube.conf
  1081. fi
  1082. cp -f $hestiacp/roundcube/main.inc.php /etc/roundcube/
  1083. cp -f $hestiacp/roundcube/db.inc.php /etc/roundcube/
  1084. chmod 640 /etc/roundcube/debian-db*
  1085. chown root:www-data /etc/roundcube/debian-db*
  1086. cp -f $hestiacp/roundcube/hestia.php \
  1087. /usr/share/roundcube/plugins/password/drivers/
  1088. cp -f $hestiacp/roundcube/config.inc.php /etc/roundcube/plugins/password/
  1089. r="$(gen_pass)"
  1090. mysql -e "CREATE DATABASE roundcube"
  1091. mysql -e "GRANT ALL ON roundcube.*
  1092. TO roundcube@localhost IDENTIFIED BY '$r'"
  1093. sed -i "s/%password%/$r/g" /etc/roundcube/db.inc.php
  1094. # Send all emails through SMTP and add user information
  1095. sed -i "/\$config\['smtp_server'\]/c\$config\['smtp_server'\] = 'localhost';" /etc/roundcube/defaults.inc.php
  1096. sed -i "/\$config\['smtp_user'\]/c\$config\['smtp_user'\] = '%u';" /etc/roundcube/defaults.inc.php
  1097. sed -i "/\$config\['smtp_pass'\]/c\$config\['smtp_pass'\] = '%p';" /etc/roundcube/defaults.inc.php
  1098. touch /var/log/roundcube/errors
  1099. chmod 640 /var/log/roundcube/errors
  1100. chown www-data:adm /var/log/roundcube/errors
  1101. if [ "$release" = '16.04' ] || [ "$release" = '18.04' ]; then
  1102. mv /etc/roundcube/db.inc.php /etc/roundcube/debian-db-roundcube.php
  1103. mv /etc/roundcube/main.inc.php /etc/roundcube/config.inc.php
  1104. chmod 640 /etc/roundcube/debian-db-roundcube.php
  1105. chown root:www-data /etc/roundcube/debian-db-roundcube.php
  1106. fi
  1107. mysql roundcube < /usr/share/dbconfig-common/data/roundcube/install/mysql
  1108. phpenmod mcrypt 2>/dev/null
  1109. if [ "$apache" = 'yes' ]; then
  1110. service apache2 restart
  1111. fi
  1112. if [ "$nginx" = 'yes' ]; then
  1113. service nginx restart
  1114. fi
  1115. fi
  1116. #----------------------------------------------------------#
  1117. # Configure Fail2Ban #
  1118. #----------------------------------------------------------#
  1119. if [ "$fail2ban" = 'yes' ]; then
  1120. cp -rf $hestiacp/fail2ban /etc/
  1121. if [ "$dovecot" = 'no' ]; then
  1122. fline=$(cat /etc/fail2ban/jail.local |grep -n dovecot-iptables -A 2)
  1123. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1124. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1125. fi
  1126. if [ "$exim" = 'no' ]; then
  1127. fline=$(cat /etc/fail2ban/jail.local |grep -n exim-iptables -A 2)
  1128. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1129. sed -i "${fline}s/true/false/" /etc/fail2ban/jail.local
  1130. fi
  1131. if [ "$vsftpd" = 'yes' ]; then
  1132. #Create vsftpd Log File
  1133. if [ ! -f "/var/log/vsftpd.log" ]; then
  1134. touch /var/log/vsftpd.log
  1135. fi
  1136. fline=$(cat /etc/fail2ban/jail.local |grep -n vsftpd-iptables -A 2)
  1137. fline=$(echo "$fline" |grep enabled |tail -n1 |cut -f 1 -d -)
  1138. sed -i "${fline}s/false/true/" /etc/fail2ban/jail.local
  1139. fi
  1140. update-rc.d fail2ban defaults
  1141. service fail2ban start
  1142. check_result $? "fail2ban start failed"
  1143. fi
  1144. #----------------------------------------------------------#
  1145. # Configure API #
  1146. #----------------------------------------------------------#
  1147. if [ "$api" = 'yes' ]; then
  1148. echo "API='yes'" >> $HESTIA/conf/hestia.conf
  1149. else
  1150. rm -r $HESTIA/web/api
  1151. echo "API='no'" >> $HESTIA/conf/hestia.conf
  1152. fi
  1153. #----------------------------------------------------------#
  1154. # Fix phpmyadmin #
  1155. #----------------------------------------------------------#
  1156. # Special thanks to Pavel Galkin (https://skurudo.ru)
  1157. # https://github.com/skurudo/phpmyadmin-fixer
  1158. source $hestiacp/phpmyadmin/pma.sh >> $LOG
  1159. #----------------------------------------------------------#
  1160. # Configure Admin User #
  1161. #----------------------------------------------------------#
  1162. # Deleting old admin user
  1163. if [ ! -z "$(grep ^admin: /etc/passwd)" ] && [ "$force" = 'yes' ]; then
  1164. chattr -i /home/admin/conf > /dev/null 2>&1
  1165. userdel -f admin > /dev/null 2>&1
  1166. chattr -i /home/admin/conf > /dev/null 2>&1
  1167. mv -f /home/admin $hst_backups/home/ > /dev/null 2>&1
  1168. rm -f /tmp/sess_* > /dev/null 2>&1
  1169. fi
  1170. if [ ! -z "$(grep ^admin: /etc/group)" ] && [ "$force" = 'yes' ]; then
  1171. groupdel admin > /dev/null 2>&1
  1172. fi
  1173. # Adding Hestia admin account
  1174. $HESTIA/bin/v-add-user admin $vpass $email default System Administrator
  1175. check_result $? "can't create admin user"
  1176. $HESTIA/bin/v-change-user-shell admin nologin
  1177. $HESTIA/bin/v-change-user-language admin $lang
  1178. # Configuring system IPs
  1179. $HESTIA/bin/v-update-sys-ip >> $LOG
  1180. # Get main IP
  1181. ip=$(ip addr|grep 'inet '|grep global|head -n1|awk '{print $2}'|cut -f1 -d/)
  1182. # Configuring firewall
  1183. if [ "$iptables" = 'yes' ]; then
  1184. $HESTIA/bin/v-update-firewall
  1185. fi
  1186. # Get public IP
  1187. pub_ip=$(curl --ipv4 -s https://www.hestiacp.com/what-is-my-ip/)
  1188. if [ ! -z "$pub_ip" ] && [ "$pub_ip" != "$ip" ]; then
  1189. echo "$HESTIA/bin/v-update-sys-ip" >> /etc/rc.local
  1190. $HESTIA/bin/v-change-sys-ip-nat $ip $pub_ip >> $LOG
  1191. ip=$pub_ip
  1192. fi
  1193. # Configuring MariaDB host
  1194. if [ "$mysql" = 'yes' ]; then
  1195. $HESTIA/bin/v-add-database-host mysql localhost root $mpass
  1196. fi
  1197. # Configuring PostgreSQL host
  1198. if [ "$postgresql" = 'yes' ]; then
  1199. $HESTIA/bin/v-add-database-host pgsql localhost postgres $ppass
  1200. fi
  1201. # Adding default domain
  1202. $HESTIA/bin/v-add-web-domain admin $servername
  1203. check_result $? "can't create $servername domain"
  1204. # Adding cron jobs
  1205. command="sudo $HESTIA/bin/v-update-sys-queue disk"
  1206. $HESTIA/bin/v-add-cron-job 'admin' '15' '02' '*' '*' '*' "$command"
  1207. command="sudo $HESTIA/bin/v-update-sys-queue traffic"
  1208. $HESTIA/bin/v-add-cron-job 'admin' '10' '00' '*' '*' '*' "$command"
  1209. command="sudo $HESTIA/bin/v-update-sys-queue webstats"
  1210. $HESTIA/bin/v-add-cron-job 'admin' '30' '03' '*' '*' '*' "$command"
  1211. command="sudo $HESTIA/bin/v-update-sys-queue backup"
  1212. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1213. command="sudo $HESTIA/bin/v-backup-users"
  1214. $HESTIA/bin/v-add-cron-job 'admin' '10' '05' '*' '*' '*' "$command"
  1215. command="sudo $HESTIA/bin/v-update-user-stats"
  1216. $HESTIA/bin/v-add-cron-job 'admin' '20' '00' '*' '*' '*' "$command"
  1217. command="sudo $HESTIA/bin/v-update-sys-rrd"
  1218. $HESTIA/bin/v-add-cron-job 'admin' '*/5' '*' '*' '*' '*' "$command"
  1219. service cron restart
  1220. # Building initital rrd images
  1221. $HESTIA/bin/v-update-sys-rrd
  1222. # Enabling file system quota
  1223. if [ "$quota" = 'yes' ]; then
  1224. $HESTIA/bin/v-add-sys-quota
  1225. fi
  1226. # Set backend port
  1227. $HESTIA/bin/v-change-sys-port $port
  1228. # Starting Hestia service
  1229. update-rc.d hestia defaults
  1230. service hestia start
  1231. check_result $? "hestia start failed"
  1232. chown admin:admin $HESTIA/data/sessions
  1233. # Adding cronjob for autoupdates
  1234. $HESTIA/bin/v-add-cron-hestia-autoupdate
  1235. #----------------------------------------------------------#
  1236. # Hestia Access Info #
  1237. #----------------------------------------------------------#
  1238. # Comparing hostname and IP
  1239. host_ip=$(host $servername| head -n 1 |awk '{print $NF}')
  1240. if [ "$host_ip" = "$ip" ]; then
  1241. ip="$servername"
  1242. fi
  1243. # Sending notification to admin email
  1244. echo -e "Congratulations, you have just successfully installed \
  1245. Hestia Control Panel
  1246. https://$ip:$port
  1247. username: admin
  1248. password: $vpass
  1249. We hope that you enjoy your installation of Hestia. Please \
  1250. feel free to contact us anytime if you have any questions.
  1251. Thank you.
  1252. --
  1253. Sincerely yours
  1254. hestiacp.com team
  1255. " > $tmpfile
  1256. send_mail="$HESTIA/web/inc/mail-wrapper.php"
  1257. cat $tmpfile | $send_mail -s "Hestia Control Panel" $email
  1258. # Congrats
  1259. echo
  1260. cat $tmpfile
  1261. rm -f $tmpfile
  1262. # EOF