11#! /bin/bash
22
3+ # set -e
34# 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'
49
510# Clear previous screen output
611clear
914download_file () {
1015 local url=$1
1116 local destination=$2
17+ local force=$3
1218
13- # default destionation is the curent working directory
19+ # Default destination is the curent working directory
1420 local dstopt=" "
1521
1622 if [ ! -z " $( echo " $url " | grep -E " \.(gz|gzip|bz2|zip|xz)$" ) " ]; then
17- # when a archive file is downloaded it will be first saved localy
18- dstopt=" --directory-prefix=$ARHIVE_DIR "
23+ # When an archive file is downloaded it will be first saved localy
24+ dstopt=" --directory-prefix=$ARCHIVE_DIR "
1925 local is_archive=" true"
2026 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
2134 elif [ ! -z " $destination " ]; then
2235 # Plain files will be written to specified location
2336 dstopt=" -O $destination "
2437 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
2546
26- if [ ! -f " $ARHIVE_DIR /$filename " ]; then
27- wget $url -q $dstopt --show-progress --progress=bar:force
47+ if [ ! -f " $ARCHIVE_DIR /$filename " ]; then
48+ wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
2849 fi
2950
3051 if [ ! -z " $destination " ] && [ " $is_archive " = " true" ]; then
3152 if [ " $destination " = " -" ]; then
32- cat " $ARHIVE_DIR /$filename "
33- elif [ -d $( basename $destination ) ]; then
34- cp " $ARHIVE_DIR /$filename " " $destination "
53+ cat " $ARCHIVE_DIR /$filename "
54+ elif [ -d " $( dirname $destination ) " ]; then
55+ cp " $ARCHIVE_DIR /$filename " " $destination "
3556 fi
3657 fi
3758}
@@ -41,7 +62,7 @@ BUILD_DIR='/tmp/hestiacp-src/'
4162DEB_DIR=" $BUILD_DIR /debs/"
4263INSTALL_DIR=' /usr/local/hestia'
4364SRC_DIR=" $( cd " $( dirname " $0 " ) /.." && pwd) "
44- ARHIVE_DIR =" $SRC_DIR /src/archive/"
65+ ARCHIVE_DIR =" $SRC_DIR /src/archive/"
4566
4667# Set Version for compiling
4768HESTIA_V=' 0.10.0-190430_amd64'
@@ -54,7 +75,7 @@ PHP_V='7.3.5'
5475# Create build directories
5576rm -rf $BUILD_DIR
5677mkdir -p $DEB_DIR
57- mkdir -p $ARHIVE_DIR
78+ mkdir -p $ARCHIVE_DIR
5879
5980# Set package dependencies for compiling
6081SOFTWARE=' build-essential libxml2-dev libz-dev libcurl4-gnutls-dev unzip openssl libssl-dev pkg-config'
@@ -119,6 +140,11 @@ for arg; do
119140 esac
120141done
121142
143+ if [ $( echo " $branch " | grep ' ^~localsrc' ) ]; then
144+ branch=$( echo " $branch " | sed ' s/^~//' ) ;
145+ use_src_folder=' true'
146+ fi
147+
122148if [[ $# -eq 0 ]] ; then
123149 echo " ERROR: Invalid compilation flag specified. Valid flags include:"
124150 echo " --all: Build all hestia packages."
@@ -195,6 +221,11 @@ if [ "$NGINX_B" = true ] ; then
195221 rm -r " $BUILD_DIR$INSTALL_DIR "
196222 fi
197223
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+
198229 # Create the files and install them
199230 make -j $NUM_CPUS && make DESTDIR=$BUILD_DIR install
200231
@@ -208,10 +239,17 @@ if [ "$NGINX_B" = true ] ; then
208239
209240 # Download control, postinst and postrm files
210241 cd DEBIAN
211- download_file $GIT_REP /nginx/control
212- download_file $GIT_REP /nginx/copyright
213- download_file $GIT_REP /nginx/postinst
214- 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
215253
216254 # Set permission
217255 chmod +x postinst postrm
@@ -222,13 +260,23 @@ if [ "$NGINX_B" = true ] ; then
222260
223261 # Get Service File
224262 cd etc/init.d
225- 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
226268 chmod +x hestia
227269
228270 # Get nginx.conf
229271 cd ../../
230272 rm usr/local/hestia/nginx/conf/nginx.conf
231- download_file " $GIT_REP /nginx/nginx.conf" " 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+
232280
233281 # copy binary
234282 cp usr/local/hestia/nginx/sbin/nginx usr/local/hestia/nginx/sbin/hestia-nginx
@@ -241,6 +289,10 @@ if [ "$NGINX_B" = true ] ; then
241289
242290 # clear up the source folder
243291 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
244296fi
245297
246298
@@ -283,6 +335,11 @@ if [ "$PHP_B" = true ] ; then
283335 # Create the files and install them
284336 make -j $NUM_CPUS && make INSTALL_ROOT=$BUILD_DIR install
285337
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+
286343 # Cleare up unused files
287344 cd $BUILD_DIR
288345 rm -r php-$PHP_V
@@ -293,18 +350,30 @@ if [ "$PHP_B" = true ] ; then
293350
294351 # Download control, postinst and postrm files
295352 cd DEBIAN
296- download_file $GIT_REP /php/control
297- 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
298360
299361 # Move php directory
300362 cd ..
301363 mv ${BUILD_DIR} /usr/local/hestia/php usr/local/hestia/
302364
303- # Get php-fpm.conf
304- download_file " $GIT_REP /php/php-fpm.conf" " 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+
305376
306- # Get php.ini
307- download_file " $GIT_REP /php/php.ini" " usr/local/hestia/php/lib/php.ini"
308377
309378 # copy binary
310379 cp usr/local/hestia/php/sbin/php-fpm usr/local/hestia/php/sbin/hestia-php
@@ -317,6 +386,10 @@ if [ "$PHP_B" = true ] ; then
317386
318387 # clear up the source folder
319388 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
320393fi
321394
322395
@@ -341,23 +414,34 @@ if [ "$HESTIA_B" = true ] ; then
341414 mkdir $BUILD_DIR /hestia_$HESTIA_V
342415
343416 # Download and unpack source files
344- download_file $HESTIA ' -' | tar xz
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
345422
346423 # Prepare Deb Package Folder Structure
347424 cd hestia_$HESTIA_V /
348425 mkdir -p usr/local/hestia DEBIAN
349426
350427 # Download control, postinst and postrm files
351428 cd DEBIAN
352- download_file $GIT_REP /hestia/control
353- download_file $GIT_REP /hestia/copyright
354- 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+
355439
356440 # Set permission
357441 chmod +x postinst
358442
359443 # Move needed directories
360- cd ../.. /hestiacp-$branch
444+ cd $BUILD_DIR /hestiacp-$branch
361445 mv bin func install web ../hestia_$HESTIA_V /usr/local/hestia/
362446
363447 # Set permission
@@ -372,7 +456,7 @@ if [ "$HESTIA_B" = true ] ; then
372456
373457 # clear up the source folder
374458 rm -r hestia_$HESTIA_V
375- rm -r hestiacp-$branch
459+ rm -rf hestiacp-$branch
376460fi
377461
378462
0 commit comments