forked from hestiacp/hestiacp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhst_autocompile.sh
More file actions
executable file
·650 lines (548 loc) · 22.7 KB
/
hst_autocompile.sh
File metadata and controls
executable file
·650 lines (548 loc) · 22.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
#!/bin/bash
# set -e
# Autocompile Script for HestiaCP package Files.
# For building from local source folder use "~localsrc" keyword as hesia branch name,
# and the script will not try to download the arhive from github, since '~' char is
# not accepted in branch name.
# Compile but dont install -> ./hst_autocompile.sh --hestia --noinstall --keepbuild '~localsrc'
# Compilea and install -> ./hst_autocompile.sh --hestia --install '~localsrc'
# Clear previous screen output
clear
# Define download function
download_file() {
local url=$1
local destination=$2
local force=$3
[ "$HESTIA_DEBUG" ] && >&2 echo DEBUG: Downloading file "$url" to "$destination"
# Default destination is the curent working directory
local dstopt=""
if [ ! -z "$(echo "$url" | grep -E "\.(gz|gzip|bz2|zip|xz)$")" ]; then
# When an archive file is downloaded it will be first saved localy
dstopt="--directory-prefix=$ARCHIVE_DIR"
local is_archive="true"
local filename="${url##*/}"
if [ -z "$filename" ]; then
>&2 echo "[!] No filename was found in url, exiting ($url)"
exit 1
fi
if [ ! -z "$force" ] && [ -f "$ARCHIVE_DIR/$filename" ]; then
rm -f $ARCHIVE_DIR/$filename
fi
elif [ ! -z "$destination" ]; then
# Plain files will be written to specified location
dstopt="-O $destination"
fi
# check for corrupted archive
if [ -f "$ARCHIVE_DIR/$filename" ] && [ "$is_archive" = "true" ]; then
tar -tzf "$ARCHIVE_DIR/$filename" > /dev/null 2>&1
if [ $? -ne 0 ]; then
>&2 echo "[!] Archive $ARCHIVE_DIR/$filename is corrupted, redownloading"
rm -f $ARCHIVE_DIR/$filename
fi
fi
if [ ! -f "$ARCHIVE_DIR/$filename" ]; then
[ "$HESTIA_DEBUG" ] && >&2 echo DEBUG: wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
wget $url -q $dstopt --show-progress --progress=bar:force --limit-rate=3m
fi
if [ ! -z "$destination" ] && [ "$is_archive" = "true" ]; then
if [ "$destination" = "-" ]; then
cat "$ARCHIVE_DIR/$filename"
elif [ -d "$(dirname $destination)" ]; then
cp "$ARCHIVE_DIR/$filename" "$destination"
fi
fi
}
get_branch_file() {
local filename=$1
local destination=$2
[ "$HESTIA_DEBUG" ] && >&2 echo DEBUG: Get branch file "$filename" to "$destination"
if [ "$use_src_folder" == 'true' ]; then
if [ -z "$destination" ]; then
[ "$HESTIA_DEBUG" ] && >&2 echo DEBUG: cp -f "$SRC_DIR/$filename" ./
cp -f "$SRC_DIR/$filename" ./
else
[ "$HESTIA_DEBUG" ] && >&2 echo DEBUG: cp -f "$SRC_DIR/$filename" "$destination"
cp -f "$SRC_DIR/$filename" "$destination"
fi
else
download_file "https://raw.githubusercontent.com/$REPO/$branch/$filename" "$destination" $3
fi
}
usage() {
echo "Usage:"
echo " $0 (--all|--hestia|--nginx|--php) [options] [branch] [Y]"
echo ""
echo " --all Build all hestia packages."
echo " --hestia Build only the Control Panel package."
echo " --nginx Build only the backend nginx engine package."
echo " --php Build only the backend php engine package"
echo " Options:"
echo " --install Install generated packages"
echo " --keepbuild Don't delete downloaded source and build folders"
echo " --debug Debug mode"
echo ""
echo "For automated builds and installations, you may specify the branch"
echo "after one of the above flags. To install the packages, specify 'Y'"
echo "following the branch name."
echo ""
echo "Example: bash hst_autocompile.sh --hestia develop Y"
echo "This would install a Hestia Control Panel package compiled with the"
echo "develop branch code."
}
# Set compiling directory
REPO='hestiacp/hestiacp'
BUILD_DIR='/tmp/hestiacp-src'
INSTALL_DIR='/usr/local/hestia'
SRC_DIR="$(cd "$(dirname "$0")/.." && pwd)"
ARCHIVE_DIR="$SRC_DIR/src/archive/"
RPM_DIR="$BUILD_DIR/rpm/"
DEB_DIR="$BUILD_DIR/deb/"
if [ -f '/etc/redhat-release' ]; then
BUILD_RPM=true
BUILD_DEB=false
OSTYPE='rhel'
else
BUILD_RPM=false
BUILD_DEB=true
OSTYPE='debian'
fi
# Set packages to compile
for i in $*; do
case "$i" in
--all)
NGINX_B='true'
PHP_B='true'
HESTIA_B='true'
;;
--nginx)
NGINX_B='true'
;;
--php)
PHP_B='true'
;;
--hestia)
HESTIA_B='true'
;;
--debug)
HESTIA_DEBUG='true'
;;
--install|Y)
install='true'
;;
--noinstall|N)
install='false'
;;
--keepbuild)
KEEPBUILD='true'
;;
--help|-h)
usage
exit 1
;;
--dontinstalldeps)
dontinstalldeps='true'
;;
*)
branch="$i"
;;
esac
done
if [[ $# -eq 0 ]]; then
usage
exit 1
fi
# Clear previous screen output
clear
# Set command variables
if [ -z $branch ]; then
echo -n "Please enter the name of the branch to build from (e.g. main): "
read branch
fi
if [ $(echo "$branch" | grep '^~localsrc') ]; then
branch=$(echo "$branch" | sed 's/^~//');
use_src_folder='true'
else
use_src_folder='false'
fi
if [ -z $install ]; then
echo -n 'Would you like to install the compiled packages? [y/N] '
read install
fi
# Set Version for compiling
if [ -f "$SRC_DIR/src/deb/hestia/control" ] && [ "$use_src_folder" == 'true' ]; then
BUILD_VER=$(cat $SRC_DIR/src/deb/hestia/control |grep "Version:" |cut -d' ' -f2)
NGINX_V=$(cat $SRC_DIR/src/deb/nginx/control |grep "Version:" |cut -d' ' -f2)
PHP_V=$(cat $SRC_DIR/src/deb/php/control |grep "Version:" |cut -d' ' -f2)
else
BUILD_VER=$(curl -s https://raw.githubusercontent.com/$REPO/$branch/src/deb/hestia/control |grep "Version:" |cut -d' ' -f2)
NGINX_V=$(curl -s https://raw.githubusercontent.com/$REPO/$branch/src/deb/nginx/control |grep "Version:" |cut -d' ' -f2)
PHP_V=$(curl -s https://raw.githubusercontent.com/$REPO/$branch/src/deb/php/control |grep "Version:" |cut -d' ' -f2)
fi
if [ -z "$BUILD_VER" ]; then
echo "Error: Branch invalid, could not detect version"
exit 1
fi
echo "Build version $BUILD_VER, with Nginx version $NGINX_V and PHP version $PHP_V"
BUILD_ARCH='amd64'
HESTIA_V="${BUILD_VER}_${BUILD_ARCH}"
OPENSSL_V='1.1.1j'
PCRE_V='8.44'
ZLIB_V='1.2.11'
# Create build directories
if [ "$KEEPBUILD" != 'true' ]; then
rm -rf $BUILD_DIR
fi
mkdir -p $BUILD_DIR
mkdir -p $DEB_DIR
mkdir -p $RPM_DIR
mkdir -p $ARCHIVE_DIR
# Define a timestamp function
timestamp() {
date +%s
}
if [ "$dontinstalldeps" != 'true' ]; then
# Install needed software
if [ "$OSTYPE" = 'rhel' ]; then
# Set package dependencies for compiling
SOFTWARE='gcc gcc-c++ make libxml2-devel zlib-devel libzip-devel gmp-devel libcurl-devel gnutls-devel unzip openssl openssl-devel pkg-config sqlite-devel oniguruma-devel rpm-build wget tar git curl'
echo "Updating system DNF repositories..."
dnf install -y -q 'dnf-command(config-manager)'
dnf install -y -q dnf-plugins-core
dnf config-manager --set-enabled powertools > /dev/null 2>&1
dnf config-manager --set-enabled PowerTools > /dev/null 2>&1
dnf upgrade -y -q
echo "Installing dependencies for compilation..."
dnf install -y -q $SOFTWARE
else
# Set package dependencies for compiling
SOFTWARE='build-essential libxml2-dev libz-dev libzip-dev libgmp-dev libcurl4-gnutls-dev unzip openssl libssl-dev pkg-config libsqlite3-dev libonig-dev rpm'
echo "Updating system APT repositories..."
apt-get -qq update > /dev/null 2>&1
echo "Installing dependencies for compilation..."
apt-get -qq install -y $SOFTWARE > /dev/null 2>&1
# Fix for Debian PHP Envroiment
if [ ! -e /usr/local/include/curl ]; then
ln -s /usr/include/x86_64-linux-gnu/curl /usr/local/include/curl
fi
fi
fi
# Get system cpu cores
NUM_CPUS=$(grep "^cpu cores" /proc/cpuinfo | uniq | awk '{print $4}')
if [ "$HESTIA_DEBUG" ]; then
if [ "$OSTYPE" = 'rhel' ]; then
echo "OS type : RHEL / CentOS / Fedora"
else
echo "OS type : Debian / Ubuntu"
fi
echo "Branch : $branch"
echo "Install : $install"
echo "Build RPM : $BUILD_RPM"
echo "Build DEB : $BUILD_DEB"
echo "Hestia version : $BUILD_VER"
echo "Nginx version : $NGINX_V"
echo "PHP version : $PHP_V"
echo "Debug mode : $HESTIA_DEBUG"
echo "Source directory : $SRC_DIR"
fi
# Generate Links for sourcecode
HESTIA_ARCHIVE_LINK='https://github.com/hestiacp/hestiacp/archive/'$branch'.tar.gz'
NGINX='https://nginx.org/download/nginx-'$(echo $NGINX_V |cut -d"~" -f1)'.tar.gz'
OPENSSL='https://www.openssl.org/source/openssl-'$OPENSSL_V'.tar.gz'
PCRE='https://ftp.pcre.org/pub/pcre/pcre-'$PCRE_V'.tar.gz'
ZLIB='https://www.zlib.net/zlib-'$ZLIB_V'.tar.gz'
PHP='http://de2.php.net/distributions/php-'$(echo $PHP_V |cut -d"~" -f1)'.tar.gz'
# Forward slashes in branchname are replaced with dashes to match foldername in github archive.
branch_dash=$(echo "$branch" |sed 's/\//-/g');
#################################################################################
#
# Building hestia-nginx
#
#################################################################################
if [ "$NGINX_B" = true ] ; then
echo "Building hestia-nginx package..."
# Change to build directory
cd $BUILD_DIR
BUILD_DIR_HESTIANGINX=$BUILD_DIR/hestia-nginx_$NGINX_V
BUILD_DIR_NGINX=$BUILD_DIR/nginx-$(echo $NGINX_V |cut -d"~" -f1)
if [ "$KEEPBUILD" != 'true' ] || [ ! -d "$BUILD_DIR_HESTIANGINX" ]; then
# Check if target directory exist
if [ -d "$BUILD_DIR_HESTIANGINX" ]; then
#mv $BUILD_DIR/hestia-nginx_$NGINX_V $BUILD_DIR/hestia-nginx_$NGINX_V-$(timestamp)
rm -r "$BUILD_DIR_HESTIANGINX"
fi
# Create directory
mkdir -p $BUILD_DIR_HESTIANGINX
# Download and unpack source files
download_file $NGINX '-' | tar xz
download_file $OPENSSL '-' | tar xz
download_file $PCRE '-' | tar xz
download_file $ZLIB '-' | tar xz
# Change to nginx directory
cd $BUILD_DIR_NGINX
# configure nginx
./configure --prefix=/usr/local/hestia/nginx \
--with-http_ssl_module \
--with-openssl=../openssl-$OPENSSL_V \
--with-openssl-opt=enable-ec_nistp_64_gcc_128 \
--with-openssl-opt=no-nextprotoneg \
--with-openssl-opt=no-weak-ssl-ciphers \
--with-openssl-opt=no-ssl3 \
--with-pcre=../pcre-$PCRE_V \
--with-pcre-jit \
--with-zlib=../zlib-$ZLIB_V
fi
# Change to nginx directory
cd $BUILD_DIR_NGINX
# Check install directory and remove if exists
if [ -d "$BUILD_DIR$INSTALL_DIR" ]; then
rm -r "$BUILD_DIR$INSTALL_DIR"
fi
# Copy local hestia source files
if [ "$use_src_folder" == 'true' ] && [ -d $SRC_DIR ]; then
cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
fi
# Create the files and install them
make -j $NUM_CPUS && make DESTDIR=$BUILD_DIR install
# Clear up unused files
if [ "$KEEPBUILD" != 'true' ]; then
rm -r $BUILD_DIR_NGINX $BUILD_DIR/openssl-$OPENSSL_V $BUILD_DIR/pcre-$PCRE_V $BUILD_DIR/zlib-$ZLIB_V
fi
cd $BUILD_DIR_HESTIANGINX
# Move nginx directory
mkdir -p $BUILD_DIR_HESTIANGINX/usr/local/hestia
rm -rf $BUILD_DIR_HESTIANGINX/usr/local/hestia/nginx
mv $BUILD_DIR/usr/local/hestia/nginx $BUILD_DIR_HESTIANGINX/usr/local/hestia/
# Remove original nginx.conf (will use custom)
rm -f $BUILD_DIR_HESTIANGINX/usr/local/hestia/nginx/conf/nginx.conf
# copy binary
cp $BUILD_DIR_HESTIANGINX/usr/local/hestia/nginx/sbin/nginx $BUILD_DIR_HESTIANGINX/usr/local/hestia/nginx/sbin/hestia-nginx
# change permission and build the package
cd $BUILD_DIR
chown -R root:root $BUILD_DIR_HESTIANGINX
if [ "$BUILD_DEB" = true ]; then
# Get Debian package files
mkdir -p $BUILD_DIR_HESTIANGINX/DEBIAN
get_branch_file 'src/deb/nginx/control' "$BUILD_DIR_HESTIANGINX/DEBIAN/control"
get_branch_file 'src/deb/nginx/copyright' "$BUILD_DIR_HESTIANGINX/DEBIAN/copyright"
get_branch_file 'src/deb/nginx/postinst' "$BUILD_DIR_HESTIANGINX/DEBIAN/postinst"
get_branch_file 'src/deb/nginx/postrm' "$BUILD_DIR_HESTIANGINX/DEBIAN/portrm"
chmod +x "$BUILD_DIR_HESTIANGINX/DEBIAN/postinst"
chmod +x "$BUILD_DIR_HESTIANGINX/DEBIAN/portrm"
# Init file
mkdir -p $BUILD_DIR_HESTIANGINX/etc/init.d
get_branch_file 'src/deb/nginx/hestia' "$BUILD_DIR_HESTIANGINX/etc/init.d/hestia"
chmod +x "$BUILD_DIR_HESTIANGINX/etc/init.d/hestia"
# Custom config
get_branch_file 'src/deb/nginx/nginx.conf' "${BUILD_DIR_HESTIANGINX}/usr/local/hestia/nginx/conf/nginx.conf"
# Build the package
echo Building Nginx DEB
dpkg-deb --build $BUILD_DIR_HESTIANGINX $DEB_DIR
fi
if [ "$BUILD_RPM" = true ]; then
# Get RHEL package files
get_branch_file 'src/rpm/nginx/hestia-nginx.spec' "${BUILD_DIR_HESTIANGINX}/hestia-nginx.spec"
sed -i "s/%HESTIA-NGINX-VERSION%/${NGINX_V}/g" "${BUILD_DIR_HESTIANGINX}/hestia-nginx.spec"
get_branch_file 'src/rpm/nginx/hestia-nginx.service' "${BUILD_DIR_HESTIANGINX}/hestia-nginx.service"
# Custom config
get_branch_file 'src/rpm/nginx/nginx.conf' "${BUILD_DIR_HESTIANGINX}/usr/local/hestia/nginx/conf/nginx.conf"
# Build the package
mkdir -p $BUILD_DIR/rpmbuild
echo Building Nginx RPM
rpmbuild -bb --define "sourcedir $BUILD_DIR_HESTIANGINX" --buildroot=$BUILD_DIR/rpmbuild/ ${BUILD_DIR_HESTIANGINX}/hestia-nginx.spec > ${BUILD_DIR_HESTIANGINX}.rpm.log
cp ~/rpmbuild/RPMS/x86_64/hestia-nginx-*.rpm $RPM_DIR
rm ~/rpmbuild/RPMS/x86_64/hestia-nginx-*.rpm
rm -rf $BUILD_DIR/rpmbuild
fi
rm -r $BUILD_DIR/usr
if [ "$KEEPBUILD" != 'true' ]; then
# Clean up the source folder
rm -r hestia-nginx_$NGINX_V
rm -rf $BUILD_DIR/rpmbuild
if [ "$use_src_folder" == 'true' ] && [ -d $BUILD_DIR/hestiacp-$branch_dash ]; then
rm -r $BUILD_DIR/hestiacp-$branch_dash
fi
fi
fi
#################################################################################
#
# Building hestia-php
#
#################################################################################
if [ "$PHP_B" = true ] ; then
echo "Building hestia-php package..."
BUILD_DIR_HESTIAPHP=$BUILD_DIR/hestia-php_$PHP_V
BUILD_DIR_PHP=$BUILD_DIR/php-$(echo $PHP_V |cut -d"~" -f1)
if [ "$KEEPBUILD" != 'true' ] || [ ! -d "$BUILD_DIR_HESTIAPHP" ]; then
# Check if target directory exist
if [ -d $BUILD_DIR_HESTIAPHP ]; then
rm -r $BUILD_DIR_HESTIAPHP
fi
# Create directory
mkdir -p $BUILD_DIR_HESTIAPHP
# Download and unpack source files
cd $BUILD_DIR
download_file $PHP '-' | tar xz
# Change to untarred php directory
cd $BUILD_DIR_PHP
# Configure PHP
./configure --prefix=/usr/local/hestia/php \
--enable-fpm \
--with-fpm-user=admin \
--with-fpm-group=admin \
--with-libdir=lib/x86_64-linux-gnu \
--with-mysqli \
--with-gettext \
--with-curl \
--with-zip \
--with-gmp \
--enable-intl \
--enable-mbstring
fi
cd $BUILD_DIR_PHP
# Create the files and install them
make -j $NUM_CPUS && make INSTALL_ROOT=$BUILD_DIR install
# Copy local hestia source files
if [ "$use_src_folder" == 'true' ] && [ -d $SRC_DIR ]; then
[ "$HESTIA_DEBUG" ] && echo DEBUG: cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
fi
# Set permission
#chmod +x postinst
# Move php directory
[ "$HESTIA_DEBUG" ] && echo DEBUG: mkdir -p $BUILD_DIR_HESTIAPHP/usr/local/hestia
mkdir -p $BUILD_DIR_HESTIAPHP/usr/local/hestia
[ "$HESTIA_DEBUG" ] && echo DEBUG: rm -r $BUILD_DIR_HESTIAPHP/usr/local/hestia/php
if [ -d $BUILD_DIR_HESTIAPHP/usr/local/hestia/php ]; then
rm -r $BUILD_DIR_HESTIAPHP/usr/local/hestia/php
fi
[ "$HESTIA_DEBUG" ] && echo DEBUG: mv ${BUILD_DIR}/usr/local/hestia/php ${BUILD_DIR_HESTIAPHP}/usr/local/hestia/
mv ${BUILD_DIR}/usr/local/hestia/php ${BUILD_DIR_HESTIAPHP}/usr/local/hestia/
# copy binary
[ "$HESTIA_DEBUG" ] && echo DEBUG: cp $BUILD_DIR_HESTIAPHP/usr/local/hestia/php/sbin/php-fpm $BUILD_DIR_HESTIAPHP/usr/local/hestia/php/sbin/hestia-php
cp $BUILD_DIR_HESTIAPHP/usr/local/hestia/php/sbin/php-fpm $BUILD_DIR_HESTIAPHP/usr/local/hestia/php/sbin/hestia-php
# Change permissions and build the package
chown -R root:root $BUILD_DIR_HESTIAPHP
if [ "$BUILD_DEB" = true ]; then
# Get Debian package files
[ "$HESTIA_DEBUG" ] && echo DEBUG: mkdir -p $BUILD_DIR_HESTIAPHP/DEBIAN
mkdir -p $BUILD_DIR_HESTIAPHP/DEBIAN
get_branch_file 'src/deb/php/control' "$BUILD_DIR_HESTIAPHP/DEBIAN/control"
get_branch_file 'src/deb/php/copyright' "$BUILD_DIR_HESTIAPHP/DEBIAN/copyright"
# Get custom config
get_branch_file 'src/deb/php/php-fpm.conf' "${BUILD_DIR_HESTIAPHP}/usr/local/hestia/php/etc/php-fpm.conf"
get_branch_file 'src/deb/php/php.ini' "${BUILD_DIR_HESTIAPHP}/usr/local/hestia/php/lib/php.ini"
# Build the package
echo Building PHP DEB
[ "$HESTIA_DEBUG" ] && echo DEBUG: dpkg-deb --build $BUILD_DIR_HESTIAPHP $DEB_DIR
dpkg-deb --build $BUILD_DIR_HESTIAPHP $DEB_DIR
fi
if [ "$BUILD_RPM" = true ]; then
# Get RHEL package files
get_branch_file 'src/rpm/php/hestia-php.spec' "${BUILD_DIR_HESTIAPHP}/hestia-php.spec"
sed -i "s/%HESTIA-PHP-VERSION%/${PHP_V}/g" "${BUILD_DIR_HESTIAPHP}/hestia-php.spec"
get_branch_file 'src/rpm/php/hestia-php.service' "${BUILD_DIR_HESTIAPHP}/hestia-php.service"
# Get custom config
get_branch_file 'src/rpm/php/php-fpm.conf' "${BUILD_DIR_HESTIAPHP}/usr/local/hestia/php/etc/php-fpm.conf"
get_branch_file 'src/rpm/php/php.ini' "${BUILD_DIR_HESTIAPHP}/usr/local/hestia/php/lib/php.ini"
# Build RPM package
mkdir -p $BUILD_DIR/rpmbuild
echo Building PHP RPM
rpmbuild -bb --define "sourcedir $BUILD_DIR_HESTIAPHP" --buildroot=$BUILD_DIR/rpmbuild/ ${BUILD_DIR_HESTIAPHP}/hestia-php.spec > ${BUILD_DIR_HESTIAPHP}.rpm.log
cp ~/rpmbuild/RPMS/x86_64/hestia-php-*.rpm $RPM_DIR
rm ~/rpmbuild/RPMS/x86_64/hestia-php-*.rpm
rm -rf $BUILD_DIR/rpmbuild
fi
rm -r $BUILD_DIR/usr
# clear up the source folder
if [ "$KEEPBUILD" != 'true' ]; then
rm -r $BUILD_DIR/php-$PHP_V
rm -r $BUILD_DIR_HESTIAPHP
if [ "$use_src_folder" == 'true' ] && [ -d $BUILD_DIR/hestiacp-$branch_dash ]; then
rm -r $BUILD_DIR/hestiacp-$branch_dash
fi
fi
fi
#################################################################################
#
# Building hestia
#
#################################################################################
if [ "$HESTIA_B" = true ]; then
echo "Building Hestia Control Panel package..."
BUILD_DIR_HESTIA=$BUILD_DIR/hestia_$HESTIA_V
# Change to build directory
cd $BUILD_DIR
if [ "$KEEPBUILD" != 'true' ] || [ ! -d "$BUILD_DIR_HESTIA" ]; then
# Check if target directory exist
if [ -d $BUILD_DIR_HESTIA ]; then
rm -r $BUILD_DIR_HESTIA
fi
# Create directory
mkdir -p $BUILD_DIR_HESTIA
fi
cd $BUILD_DIR
rm -rf $BUILD_DIR/hestiacp-$branch_dash
# Download and unpack source files
if [ "$use_src_folder" == 'true' ]; then
[ "$HESTIA_DEBUG" ] && echo DEBUG: cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
cp -rf "$SRC_DIR/" $BUILD_DIR/hestiacp-$branch_dash
elif [ -d $SRC_DIR ]; then
download_file $HESTIA_ARCHIVE_LINK '-' 'fresh' | tar xz
fi
mkdir -p $BUILD_DIR_HESTIA/usr/local/hestia
# Move needed directories
cd $BUILD_DIR/hestiacp-$branch_dash
cp -rf bin func install web $BUILD_DIR_HESTIA/usr/local/hestia/
# Set permissions
find $BUILD_DIR_HESTIA/usr/local/hestia/ -type f -exec chmod -x {} \;
chmod +x $BUILD_DIR_HESTIA/usr/local/hestia/bin/*
chown -R root:root $BUILD_DIR_HESTIA
if [ "$BUILD_DEB" = true ]; then
# Get Debian package files
mkdir -p $BUILD_DIR_HESTIA/DEBIAN
get_branch_file 'src/deb/hestia/control' "$BUILD_DIR_HESTIA/DEBIAN/control"
get_branch_file 'src/deb/hestia/copyright' "$BUILD_DIR_HESTIA/DEBIAN/copyright"
get_branch_file 'src/deb/hestia/postinst' "$BUILD_DIR_HESTIA/DEBIAN/postinst"
chmod +x $BUILD_DIR_HESTIA/DEBIAN/postinst
echo Building Hestia DEB
dpkg-deb --build $BUILD_DIR_HESTIA $DEB_DIR
fi
if [ "$BUILD_RPM" = true ]; then
# Get RHEL package files
get_branch_file 'src/rpm/hestia/hestia.spec' "${BUILD_DIR_HESTIA}/hestia.spec"
sed -i "s/%HESTIA-VERSION%/${HESTIA_V}/g" "${BUILD_DIR_HESTIA}/hestia.spec"
get_branch_file 'src/rpm/hestia/hestia.service' "${BUILD_DIR_HESTIA}/hestia.service"
# Build RPM package
mkdir -p $BUILD_DIR/rpmbuild
echo Building Hestia RPM
rpmbuild -bb --define "sourcedir $BUILD_DIR_HESTIA" --buildroot=$BUILD_DIR/rpmbuild/ ${BUILD_DIR_HESTIA}/hestia.spec > ${BUILD_DIR_HESTIA}.rpm.log
cp ~/rpmbuild/RPMS/x86_64/hestia-*.rpm $RPM_DIR
rm ~/rpmbuild/RPMS/x86_64/hestia-*.rpm
rm -rf $BUILD_DIR/rpmbuild
fi
# clear up the source folder
if [ "$KEEPBUILD" != 'true' ]; then
rm -r $BUILD_DIR_HESTIA
rm -rf hestiacp-$branch_dash
fi
cd $BUILD_DIR/hestiacp-$branch_dash
fi
#################################################################################
#
# Install Packages
#
#################################################################################
if [ "$install" = 'yes' ] || [ "$install" = 'y' ] || [ "$install" = 'true' ]; then
# Install all available packages
echo "Installing packages..."
if [ "$OSTYPE" = 'rhel' ]; then
for i in $RPM_DIR/*.rpm; do
dnf -y install $i
done
else
for i in $DEB_DIR/*.deb; do
dpkg -i $i
done
fi
unset $answer
fi