Skip to content

Commit f390a80

Browse files
author
Kristan Kenney
authored
Merge pull request hestiacp#284 from Lupul/feature-compile-from-src
Feature compile from src
2 parents 16ed34e + e27ce93 commit f390a80

File tree

2 files changed

+141
-27
lines changed

2 files changed

+141
-27
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
*.zip
33
*.gzip
44
*.gz
5+
*.bz2
56
.vscode
67
.DS_Store

src/hst_autocompile.sh

Lines changed: 140 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,68 @@
1+
#!/bin/bash
2+
3+
# set -e
14
# Autocompile Script for HestiaCP deb Files.
5+
# For building from local source folder use "~localsrc" keyword as hesia branch name,
6+
# and the script will not try to download the arhive from github, since '~' char is
7+
# not accepted in branch name.
8+
# -> ./hst_autocompile.sh --hestia '~localsrc' 'n'
29

310
# Clear previous screen output
411
clear
512

613
# Define download function
714
download_file() {
8-
wget $1 -q --show-progress --progress=bar:force
15+
local url=$1
16+
local destination=$2
17+
local force=$3
18+
19+
# Default destination is the curent working directory
20+
local dstopt=""
21+
22+
if [ ! -z "$(echo "$url" | grep -E "\.(gz|gzip|bz2|zip|xz)$")" ]; then
23+
# When an archive file is downloaded it will be first saved localy
24+
dstopt="--directory-prefix=$ARCHIVE_DIR"
25+
local is_archive="true"
26+
local filename="${url##*/}"
27+
if [ -z "$filename" ]; then
28+
>&2 echo "[!] No filename was found in url, exiting ($url)"
29+
exit 1
30+
fi
31+
if [ ! -z "$force" ] && [ -f "$ARCHIVE_DIR/$filename" ]; then
32+
rm -f $ARCHIVE_DIR/$filename
33+
fi
34+
elif [ ! -z "$destination" ]; then
35+
# Plain files will be written to specified location
36+
dstopt="-O $destination"
37+
fi
38+
# check for corrupted archive
39+
if [ -f "$ARCHIVE_DIR/$filename" ] && [ "$is_archive" = "true" ]; then
40+
tar -tzf "$ARCHIVE_DIR/$filename" > /dev/null 2>&1
41+
if [ $? -ne 0 ]; then
42+
>&2 echo "[!] Archive $ARCHIVE_DIR/$filename is corrupted, redownloading"
43+
rm -f $ARCHIVE_DIR/$filename
44+
fi
45+
fi
46+
47+
if [ ! -f "$ARCHIVE_DIR/$filename" ]; then
48+
wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
49+
fi
50+
51+
if [ ! -z "$destination" ] && [ "$is_archive" = "true" ]; then
52+
if [ "$destination" = "-" ]; then
53+
cat "$ARCHIVE_DIR/$filename"
54+
elif [ -d "$(dirname $destination)" ]; then
55+
cp "$ARCHIVE_DIR/$filename" "$destination"
56+
fi
57+
fi
958
}
1059

1160
# Set compiling directory
1261
BUILD_DIR='/tmp/hestiacp-src/'
1362
DEB_DIR="$BUILD_DIR/debs/"
1463
INSTALL_DIR='/usr/local/hestia'
64+
SRC_DIR="$(cd "$(dirname "$0")/.." && pwd)"
65+
ARCHIVE_DIR="$SRC_DIR/src/archive/"
1566

1667
# Set Version for compiling
1768
HESTIA_V='0.10.0-190430_amd64'
@@ -24,6 +75,7 @@ PHP_V='7.3.5'
2475
# Create build directories
2576
rm -rf $BUILD_DIR
2677
mkdir -p $DEB_DIR
78+
mkdir -p $ARCHIVE_DIR
2779

2880
# Set package dependencies for compiling
2981
SOFTWARE='build-essential libxml2-dev libz-dev libcurl4-gnutls-dev unzip openssl libssl-dev pkg-config'
@@ -88,6 +140,11 @@ for arg; do
88140
esac
89141
done
90142

143+
if [ $(echo "$branch" | grep '^~localsrc') ]; then
144+
branch=$(echo "$branch" | sed 's/^~//');
145+
use_src_folder='true'
146+
fi
147+
91148
if [[ $# -eq 0 ]] ; then
92149
echo "ERROR: Invalid compilation flag specified. Valid flags include:"
93150
echo "--all: Build all hestia packages."
@@ -109,7 +166,7 @@ fi
109166
GIT_REP='https://raw.githubusercontent.com/hestiacp/hestiacp/'$branch'/src/deb'
110167

111168
# Generate Links for sourcecode
112-
HESTIA='https://github.com/hestiacp/hestiacp/archive/'$branch'.zip'
169+
HESTIA='https://github.com/hestiacp/hestiacp/archive/'$branch'.tar.gz'
113170
NGINX='https://nginx.org/download/nginx-'$NGINX_V'.tar.gz'
114171
OPENSSL='https://www.openssl.org/source/openssl-'$OPENSSL_V'.tar.gz'
115172
PCRE='https://ftp.pcre.org/pub/pcre/pcre-'$PCRE_V'.tar.gz'
@@ -139,10 +196,10 @@ if [ "$NGINX_B" = true ] ; then
139196
mkdir $BUILD_DIR/hestia-nginx_$NGINX_V
140197

141198
# Download and unpack source files
142-
download_file $NGINX | tar xz
143-
download_file $OPENSSL | tar xz
144-
download_file $PCRE | tar xz
145-
download_file $ZLIB | tar xz
199+
download_file $NGINX '-' | tar xz
200+
download_file $OPENSSL '-' | tar xz
201+
download_file $PCRE '-' | tar xz
202+
download_file $ZLIB '-' | tar xz
146203

147204
# Change to nginx directory
148205
cd nginx-$NGINX_V
@@ -164,6 +221,11 @@ if [ "$NGINX_B" = true ] ; then
164221
rm -r "$BUILD_DIR$INSTALL_DIR"
165222
fi
166223

224+
# Copy local hestia source files
225+
if [ ! -z "$use_src_folder" ] && [ -d $SRC_DIR ]; then
226+
cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch
227+
fi
228+
167229
# Create the files and install them
168230
make -j $NUM_CPUS && make DESTDIR=$BUILD_DIR install
169231

@@ -177,10 +239,17 @@ if [ "$NGINX_B" = true ] ; then
177239

178240
# Download control, postinst and postrm files
179241
cd DEBIAN
180-
download_file $GIT_REP/nginx/control
181-
download_file $GIT_REP/nginx/copyright
182-
download_file $GIT_REP/nginx/postinst
183-
download_file $GIT_REP/nginx/postrm
242+
if [ -z "$use_src_folder" ]; then
243+
download_file $GIT_REP/nginx/control
244+
download_file $GIT_REP/nginx/copyright
245+
download_file $GIT_REP/nginx/postinst
246+
download_file $GIT_REP/nginx/postrm
247+
else
248+
cp $BUILD_DIR/hestiacp-$branch/src/deb/nginx/control ./
249+
cp $BUILD_DIR/hestiacp-$branch/src/deb/nginx/copyright ./
250+
cp $BUILD_DIR/hestiacp-$branch/src/deb/nginx/postinst ./
251+
cp $BUILD_DIR/hestiacp-$branch/src/deb/nginx/postrm ./
252+
fi
184253

185254
# Set permission
186255
chmod +x postinst postrm
@@ -191,13 +260,23 @@ if [ "$NGINX_B" = true ] ; then
191260

192261
# Get Service File
193262
cd etc/init.d
194-
download_file $GIT_REP/nginx/hestia
263+
if [ -z "$use_src_folder" ]; then
264+
download_file $GIT_REP/nginx/hestia
265+
else
266+
cp $BUILD_DIR/hestiacp-$branch/src/deb/nginx/hestia ./
267+
fi
195268
chmod +x hestia
196269

197270
# Get nginx.conf
198271
cd ../../
199272
rm usr/local/hestia/nginx/conf/nginx.conf
200-
download_file $GIT_REP/nginx/nginx.conf -O usr/local/hestia/nginx/conf/nginx.conf
273+
274+
if [ -z "$use_src_folder" ]; then
275+
download_file $GIT_REP/nginx/nginx.conf "usr/local/hestia/nginx/conf/nginx.conf"
276+
else
277+
cp $BUILD_DIR/hestiacp-$branch/src/deb/nginx/nginx.conf "usr/local/hestia/nginx/conf/nginx.conf"
278+
fi
279+
201280

202281
# copy binary
203282
cp usr/local/hestia/nginx/sbin/nginx usr/local/hestia/nginx/sbin/hestia-nginx
@@ -210,6 +289,10 @@ if [ "$NGINX_B" = true ] ; then
210289

211290
# clear up the source folder
212291
rm -r hestia-nginx_$NGINX_V
292+
rm -rf usr/
293+
if [ ! -z "$use_src_folder" ] && [ -d $$BUILD_DIR/hestiacp-$branch ]; then
294+
rm -r $BUILD_DIR/hestiacp-$branch
295+
fi
213296
fi
214297

215298

@@ -234,7 +317,7 @@ if [ "$PHP_B" = true ] ; then
234317
mkdir ${BUILD_DIR}/hestia-php_$PHP_V
235318

236319
# Download and unpack source files
237-
download_file $PHP | tar xz
320+
download_file $PHP '-' | tar xz
238321

239322
# Change to php directory
240323
cd php-$PHP_V
@@ -252,6 +335,11 @@ if [ "$PHP_B" = true ] ; then
252335
# Create the files and install them
253336
make -j $NUM_CPUS && make INSTALL_ROOT=$BUILD_DIR install
254337

338+
# Copy local hestia source files
339+
if [ ! -z "$use_src_folder" ] && [ -d $SRC_DIR ]; then
340+
cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch
341+
fi
342+
255343
# Cleare up unused files
256344
cd $BUILD_DIR
257345
rm -r php-$PHP_V
@@ -262,18 +350,30 @@ if [ "$PHP_B" = true ] ; then
262350

263351
# Download control, postinst and postrm files
264352
cd DEBIAN
265-
download_file $GIT_REP/php/control
266-
download_file $GIT_REP/php/copyright
353+
if [ -z "$use_src_folder" ]; then
354+
download_file $GIT_REP/php/control
355+
download_file $GIT_REP/php/copyright
356+
else
357+
cp $BUILD_DIR/hestiacp-$branch/src/deb/php/control ./
358+
cp $BUILD_DIR/hestiacp-$branch/src/deb/php/copyright ./
359+
fi
267360

268361
# Move php directory
269362
cd ..
270363
mv ${BUILD_DIR}/usr/local/hestia/php usr/local/hestia/
271364

272-
# Get php-fpm.conf
273-
download_file $GIT_REP/php/php-fpm.conf -O usr/local/hestia/php/etc/php-fpm.conf
365+
if [ -z "$use_src_folder" ]; then
366+
# Get php-fpm.conf
367+
download_file "$GIT_REP/php/php-fpm.conf" "usr/local/hestia/php/etc/php-fpm.conf"
368+
369+
# Get php.ini
370+
download_file "$GIT_REP/php/php.ini" "usr/local/hestia/php/lib/php.ini"
371+
else
372+
cp $BUILD_DIR/hestiacp-$branch/src/deb/php/php-fpm.conf "usr/local/hestia/php/etc/php-fpm.conf"
373+
cp $BUILD_DIR/hestiacp-$branch/src/deb/php/php.ini "usr/local/hestia/php/lib/php.ini"
374+
fi
375+
274376

275-
# Get php.ini
276-
download_file $GIT_REP/php/php.ini -O usr/local/hestia/php/lib/php.ini
277377

278378
# copy binary
279379
cp usr/local/hestia/php/sbin/php-fpm usr/local/hestia/php/sbin/hestia-php
@@ -286,6 +386,10 @@ if [ "$PHP_B" = true ] ; then
286386

287387
# clear up the source folder
288388
rm -r hestia-php_$PHP_V
389+
rm -rf usr/
390+
if [ ! -z "$use_src_folder" ] && [ -d $$BUILD_DIR/hestiacp-$branch ]; then
391+
rm -r $BUILD_DIR/hestiacp-$branch
392+
fi
289393
fi
290394

291395

@@ -310,25 +414,34 @@ if [ "$HESTIA_B" = true ] ; then
310414
mkdir $BUILD_DIR/hestia_$HESTIA_V
311415

312416
# Download and unpack source files
313-
download_file $HESTIA
314-
unzip -q $branch.zip
315-
rm $branch.zip
417+
if [ -z "$use_src_folder" ]; then
418+
download_file $HESTIA '-' 'fresh' | tar xz
419+
elif [ -d $SRC_DIR ]; then
420+
cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch
421+
fi
316422

317423
# Prepare Deb Package Folder Structure
318424
cd hestia_$HESTIA_V/
319425
mkdir -p usr/local/hestia DEBIAN
320426

321427
# Download control, postinst and postrm files
322428
cd DEBIAN
323-
download_file $GIT_REP/hestia/control
324-
download_file $GIT_REP/hestia/copyright
325-
download_file $GIT_REP/hestia/postinst
429+
if [ -z "$use_src_folder" ]; then
430+
download_file $GIT_REP/hestia/control
431+
download_file $GIT_REP/hestia/copyright
432+
download_file $GIT_REP/hestia/postinst
433+
else
434+
cp $BUILD_DIR/hestiacp-$branch/src/deb/hestia/control ./
435+
cp $BUILD_DIR/hestiacp-$branch/src/deb/hestia/copyright ./
436+
cp $BUILD_DIR/hestiacp-$branch/src/deb/hestia/postinst ./
437+
fi
438+
326439

327440
# Set permission
328441
chmod +x postinst
329442

330443
# Move needed directories
331-
cd ../../hestiacp-$branch
444+
cd $BUILD_DIR/hestiacp-$branch
332445
mv bin func install web ../hestia_$HESTIA_V/usr/local/hestia/
333446

334447
# Set permission
@@ -343,7 +456,7 @@ if [ "$HESTIA_B" = true ] ; then
343456

344457
# clear up the source folder
345458
rm -r hestia_$HESTIA_V
346-
rm -r hestiacp-$branch
459+
rm -rf hestiacp-$branch
347460
fi
348461

349462

0 commit comments

Comments
 (0)