1+ #! /bin/bash
2+
13# Autocompile Script for HestiaCP deb Files.
24
35# Define download function
46download_file () {
5- wget $1 -q --show-progress --progress=bar:force
7+ local url=$1
8+ local destination=$2
9+ local force=$3
10+
11+ # Default destination is the curent working directory
12+ local dstopt=" "
13+
14+ if [ ! -z " $( echo " $url " | grep -E " \.(gz|gzip|bz2|zip|xz)$" ) " ]; then
15+ # When an archive file is downloaded it will be first saved localy
16+ dstopt=" --directory-prefix=$ARCHIVE_DIR "
17+ local is_archive=" true"
18+ local filename=" ${url##*/ } "
19+ if [ -z " $filename " ]; then
20+ >&2 echo " [!] No filename was found in url, exiting ($url )"
21+ exit 1
22+ fi
23+ if [ ! -z " $force " ] && [ -f " $ARCHIVE_DIR /$filename " ]; then
24+ rm -f $ARCHIVE_DIR /$filename
25+ fi
26+ elif [ ! -z " $destination " ]; then
27+ # Plain files will be written to specified location
28+ dstopt=" -O $destination "
29+ fi
30+ # check for corrupted archive
31+ if [ -f " $ARCHIVE_DIR /$filename " ] && [ " $is_archive " = " true" ]; then
32+ tar -tzf " $ARCHIVE_DIR /$filename " > /dev/null 2>&1
33+ if [ $? -ne 0 ]; then
34+ >&2 echo " [!] Archive $ARCHIVE_DIR /$filename is corrupted, redownloading"
35+ rm -f $ARCHIVE_DIR /$filename
36+ fi
37+ fi
38+
39+ if [ ! -f " $ARCHIVE_DIR /$filename " ]; then
40+ wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
41+ fi
42+
43+ if [ ! -z " $destination " ] && [ " $is_archive " = " true" ]; then
44+ if [ " $destination " = " -" ]; then
45+ cat " $ARCHIVE_DIR /$filename "
46+ elif [ -d " $( dirname $destination ) " ]; then
47+ cp " $ARCHIVE_DIR /$filename " " $destination "
48+ fi
49+ fi
650}
751
852# Set compiling directory
@@ -11,7 +55,9 @@ DEB_DIR="$BUILD_DIR/debs/"
1155INSTALL_DIR=' /usr/local/hestia'
1256
1357# Set Version for compiling
14- HESTIA_V='0.10.0-190430_amd64'
58+ BUILD_VER=$( curl -s https://raw.githubusercontent.com/hestiacp/hestiacp/$branch /src/deb/hestia/control | grep " Version:" | cut -d' ' -f2)
59+ BUILD_ARCH=' amd64'
60+ HESTIA_V=" ${BUILD_VER} _${BUILD_ARCH} "
1561NGINX_V=' 1.16.0'
1662OPENSSL_V=' 1.1.1b'
1763PCRE_V=' 8.43'
@@ -30,12 +76,18 @@ timestamp() {
3076 date +%s
3177}
3278
33- branch=$2
34- install=$3
79+ branch=$1
80+ install=$2
3581
3682# Set install flags
3783if [ ! -z " $1 " ]; then
38- branch=$1
84+ branch_check=$( curl -s --head -w %{http_code} https://raw.githubusercontent.com/hestiacp/hestiacp/$branch /src/deb/hestia/control -o /dev/null)
85+ if [ $branch_check -ne " 200" ]; then
86+ echo " Error: invalid branch name specified."
87+ exit 1
88+ else
89+ branch=$1
90+ fi
3991else
4092 source /usr/local/hestia/conf/hestia.conf
4193 branch=$RELEASE_BRANCH
4799 install=" y"
48100fi
49101
102+
50103# Install needed software
51104echo " Updating system APT repositories..."
52105apt-get -qq update > /dev/null 2>&1
0 commit comments