-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.sh
executable file
·1498 lines (1369 loc) · 50.8 KB
/
make.sh
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
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/sh
# DSAS - Tinycore
# Copyright (C) 2021-2022 Electricite de France
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Shellcheck configuration to test for POSIX shell plus the Busybox/ASH extensions I use
# Allow process subsitution with "<()"
# shellcheck disable=SC3001
# Allow echo flags
# shellcheck disable=SC3037
# Allow "read -d"
# shellcheck disable=SC3045
# Allow string indexing like "${1:3}"
# shellcheck disable=SC3057
# If not running as root and/or running /bin/dash restart as root with a compatible shell
readlink /proc/$$/exe | grep -q dash && _shell="/bin/bash"
[ "$(id -u)" -ne 0 ] && _asroot="sudo -E"
if [ -n "$_shell" ]; then
$_asroot "$_shell" "$0" "$@"
exit $?
elif [ -n "$_asroot" ]; then
$_asroot "$0" "$@"
exit $?
fi
# Set LANG so that perl doesn't complain
LANG="C"
# Get default architecture
arch="32"
[ "$(uname -m)" = "x86_64" ] && arch="64"
# Parse commandline args
rebuild=0
forcedownload=0
keep=0
testcode=0
vmtools=0
cmd=""
pkgs=""
while [ "$#" -gt 0 ]; do
case $1 in
-r|--rebuild) rebuild=1; ;;
-f|--download) forcedownload=1; ;;
-k|--keep) keep=1; ;;
-t|--test) testcode=1; ;;
-v|--vmtools) vmtools=1; ;;
-32) arch="32"; ;;
-64) arch="64"; ;;
-h|--help)
echo "Usage: $(basename "$0") [Options] [Command]"
echo "Build DSAS packages and distributions. Valid commands are"
echo " build pkg Build the package 'pkg' from source code"
echo " source Package DSAS source code"
echo " docker Build a docker distribution package"
echo " clean Remove the distribution files"
echo " realclean Remove all files, leaving a clean build tree"
echo " check Run test code to test correct function of checkfiles"
echo " iso Build the DSAS ISO file. This the default command"
echo " static Run static analysis on the DSAS source code"
echo " upgrade Upgrade the TCZ packages to their latest version"
echo " work Set the work directory"
echo "Valid options are"
echo " -r|--rebuild Force the rebuild of source packages"
echo " -f|--download Force the source packages to be re-downloaded"
echo " -t|--test Include test code in DSAS build"
echo " -k|--keep Keep intermediate build files for debugging"
echo " -v|--vmtools Install open-vm-tools in image"
echo " -32 Force the build for 32 bit architectures"
echo " -64 Force the build for 64 bit architectures"
echo " -h|--help Print this help"
exit 0
;;
*)
if [ -z "$cmd" ]; then
cmd=$1
else
pkgs="$pkgs $1"
fi
;;
esac
shift
done
# local hosts package directory on Tinycore for package reuse if possible
[ "$arch" = 64 ] && [ "$(uname -m)" = "x86_64" ] && \
[ -d "/etc/sysconfig/tcedir/optional" ] && tce_dir="/etc/sysconfig/tcedir/optional"
[ "$arch" = 32 ] && [ "$(uname -m)" = "i686" ] && \
[ -d "/etc/sysconfig/tcedir/optional" ] && tce_dir="/etc/sysconfig/tcedir/optional"
# Can't build 64-bit DSAS on 32-bit host
[ "$arch" = 64 ] && [ "$(uname -m)" = "i686" ] && { echo "Can not build 64-bit DSAS on 32-bit host"; exit 1; }
# Longer curl timeout
curl_cmd="curl --connect-timeout 300"
# tiny core related
if [ "$arch" != "64" ]; then
livecd_url=http://tinycorelinux.net/15.x/x86/release/Core-current.iso
tcz_url=http://tinycorelinux.net/15.x/x86/tcz
tcz_src=http://tinycorelinux.net/15.x/x86/release/src
else
livecd_url=http://tinycorelinux.net/15.x/x86_64/release/CorePure64-current.iso
tcz_url=http://tinycorelinux.net/15.x/x86_64/tcz
tcz_src=http://tinycorelinux.net/15.x/x86_64/release/src
fi
export tcz_src
# internally used dirs and paths
work=./work
tcz_dir=$work/tcz$arch
livecd0=$work/livecd$arch.iso
newiso=$work/newiso
src_dir=$work/src
pkg_dir=./pkg
destdir=/home/tc/dest
builddir=/home/tc/build
if [ "$arch" != "64" ]; then
squashfs=$newiso/boot/core.gz
else
squashfs=$newiso/boot/corepure64.gz
fi
mnt=$work/mnt
image=$work/extract
build=$work/build
append=./append
testdir=./test
dsascd=$work/dsas.iso
rootfs64=$work/rootfs64
docker=$work/docker
dockimage=$work/docker.tgz
source=$work/dsas.tgz
service_pass_len=24
# Force the umask
umask 0022
# If not on tinycore, the user "tc" doesn't exist
if grep -q "tc:" /etc/passwd; then
tc=tc
staff=staff
else
tc=1001
staff=50
fi
msg() {
echo "[*]" "$@"
}
cmd() {
echo "[cmd]" "$@"
# Yes I want word-splitting here
# shellcheck disable=SC2068
$@
}
error() {
echo "[E]" "$@"
exit 1
}
exit_if_nonroot() {
test "$(id -u)" = 0 || error this script needs to run as root
}
pwgen() {
pass=$(< /dev/random tr -dc _A-Z-a-z-0-9 | head -c "$1"; echo;)
}
get_tcz() {
mkdir -pv $tcz_dir
for package; do
package=$(echo "$package" | sed -e "s/-KERNEL/-$_kern/g")
target=$tcz_dir/$package.tcz
dep=$target.dep
# If the PKG file exists and is newer than the TCZ file, rebuild
if test -f "$target" && test -f "$pkg_dir/$package.pkg"; then
[ "$(stat -c '%Y' "$pkg_dir/$package.pkg")" -gt "$(stat -c '%Y' "$target")" ] && rm -f "$target"
fi
if test ! -f "$target"; then
if test -f "$pkg_dir/$package.pkg"; then
# In a new shell so that build doesn't modify local variables
_old=$extract
extract="$build"
( build_pkg "$package"; ) || exit 1
extract="$_old"
elif test -f "$tce_dir/$package.tcz"; then
msg "fetching package $package ..."
cp "$tce_dir/$package.tcz" "$target"
if ! test -f "$tce_dir/$package/tcz.dep"; then
touch "$tce_dir/$package.tcz.dep"
else
cp "$tce_dir/$package.tcz.dep" "$target"
fi
if ! test -f "$tce_dir/$package/tcz.md5.txt"; then
md5sum "$tcz_dir/$package.tcz" | sed -e "s: $tcz_dir/$package.tcz$::g" > "$tcz_dir/$package.tcz.md5.txt"
else
cp "$tce_dir/$package.tcz.md5.txt" "$target"
fi
else
msg "fetching package $package ..."
$curl_cmd -o "$target" "$tcz_url/$package.tcz" || exit 1
md5sum "$tcz_dir/$package.tcz" | sed -e "s: $tcz_dir/$package.tcz$::g" > "$tcz_dir/$package.tcz.md5.txt"
fi
fi
if test ! -f "$dep"; then
msg "fetching dep list of $package ..."
if test -f "$tce_dir/$package.tcz.dep"; then
cp "$tce_dir/$package.tcz.dep" "$dep"
else
$curl_cmd -o "$dep" "$tcz_url/$package.tcz.dep" || touch "$dep"
fi
grep -q 404 "$dep" && cp /dev/null "$dep"
# Want word splitting on arg to get_tcz
# shellcheck disable=SC2046
get_tcz $(sed -e s/.tcz$// "$dep")
fi
done
}
install_tcz() {
# Want array splitting here
# shellcheck disable=SC2068
get_tcz $@
exit_if_nonroot
for package; do
package=$(echo "$package" | sed -e "s/-KERNEL/-$_kern/g")
target=$tcz_dir/$package.tcz
tce_marker=$extract/usr/local/tce.installed/$package
if ! test -f "$tce_marker"; then
msg "installing package $package ..."
unsquashfs -f -d "$extract" "$target"
if test -s "$tce_marker"; then
msg "post-install script $package"
chroot "$extract" env LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib "/usr/local/tce.installed/$package"
else
mkdir -p "$extract/usr/local/tce.installed"
touch "$tce_marker"
fi
dep=$target.dep
if test -s "$dep"; then
# Want word splitting on arg to get_tcz
# shellcheck disable=SC2046
install_tcz $(sed -e s/.tcz$// "$dep")
fi
fi
done
}
build_pkg_cache() {
msg "setting up package cache dir for SNMP"
[ "$#" -ge 1 ] && _snmpdir="$1" || _snmpdir="/var/cache/hrmib"
_snmpdir="$extract/$_snmpdir"
mkdir -p "$_snmpdir"
while IFS= read -r -d '' _file; do
_pkg=$(basename "$_file")
if test -f "$pkg_dir/$_pkg.pkg"; then
_version="_$(grep _version "$pkg_dir/$_pkg.pkg" | cut -d= -f2)"
elif [ "$_pkg" = "dsas_js" ]; then
# Special case
_version="_$(grep "dsasVersion =" ./js/src/DsasHelp.js | sed -e "s:^.* = \"\([0-9.]*\).*$:\1:")"
else
[ -f "$tcz_dir/$_pkg.tcz.info" ] || $curl_cmd -s -o "$tcz_dir/$_pkg.tcz.info" "$tcz_url/$_pkg.tcz.info"
_version=$(grep -i version: "$tcz_dir/$_pkg.tcz.info" | cut -d: -f2 | xargs | tr "/" ".")
[ -z "$_version" ] || _version="_$_version"
fi
# Use amd64 for architecture for coherence with other distributions
if [ "$arch" = "64" ]; then
touch -r "$_file" "$_snmpdir/$_pkg${_version}_amd64"
else
touch -r "$_file" "$_snmpdir/$_pkg${_version}_x86"
fi
done < <(find "$extract/usr/local/tce.installed" -type "f" -print0)
}
get() {
[ "$#" -gt 2 ] && _sourc=$3
[ "$#" -gt 2 ] || _sourc=$(basename "$1")
msg "Downloading $_sourc"
$curl_cmd -L -o "$2/$_sourc" "$1" || exit 1
}
download() {
if [ "$1" = "-f" ]; then
shift
noext="true"
fi
[ "$#" -gt 2 ] && _source=$3
[ "$#" -gt 2 ] || _source=$(basename "$1")
if [ "$forcedownload" -eq 0 ]; then
if [ ! -f "$2/$_source" ]; then
if [ "$noext" = "true" ]; then
# Ignore extension
get "$@"
else
case $(echo "$1" | sed -e "s/.*\(\..*\)$/\1/g") in
.jar|.tgz|.tbz|.tar|.gz|.bz2|.xz) get "$@"; ;;
*) error "Unknown file extension $1"; ;;
esac
fi
fi
else
get "$@"
fi
}
unpack() {
msg "Unpacking $1 to $2"
case $(echo "$1" | sed -e "s/.*\(\..*\)$/\1/g") in
.tgz) tar xzCf "$2" "$1" || return 1; ;;
.tbz) tar xjCf "$2" "$1" || return 1; ;;
.tar) tar xCf "$2" "$1" || return 1; ;;
.gz)
if [ "${1: -7}" = ".tar.gz" ]; then
tar xzCf "$2" "$1" || return 1
else
error "An archive can not be a gzip"
fi
;;
.bz2)
if [ "${1: -8}" = ".tar.bz2" ]; then
tar xjCf "$2" "$1" || return 1
else
error "An archive can not be a bzip2"
fi
;;
.xz)
if [ "${1: -7}" = ".tar.xz" ]; then
tar xJCf "$2" "$1" || return 1
else
error "An archive can not be a xz"
fi
;;
*)
error "Unknown file extension $1"
;;
esac
}
disksize(){
_d="$1"
while [ ! -e "$_d" ]; do _d=$(dirname "$_d"); done
df --block-size=1G "$_d" | tail -1 | xargs | cut -d' ' -f4
}
build_pkg() {
for pkg in $1; do
pkg_file=$pkg_dir/${pkg%%-dev}.pkg
# Remove old TCZ if PKG is newer
[ -f "$pkg_file" ] && [ -f "$tcz_dir/$pkg.tcz" ] \
&& [ "$(stat -c '%Y' "$pkg_file")" -gt "$(stat -c '%Y' "$tcz_dir/$pkg.tcz")" ] \
&& rm -f "$tcz_dir/$pkg.tcz"
# Don't rebuild if forced rebuild and TCZ date is later than the start time of the
# build script. Prevent mutliple builds of the same package
if [ ! -f "$tcz_dir/$pkg.tcz" ] || { [ $rebuild -eq "1" ] && \
[ "$startdate" -gt "$(date -r "$tcz_dir/$pkg.tcz" +%s)" ]; } then
if [ -f "$pkg_file" ]; then
msg "Building $pkg_file"
# Unset build variables before sourcing package file
unset _build_dep _conf_cmd _dep _install_cmd _make_cmd _pkg _pkg_path _pkgs \
_post_build _post_install _pre_config _uri _src _version _disk_needed
# Use Linux-PAM.pkg as a non trivial source file to test with
# shellcheck source=pkg/Linux-PAM.pkg
. "$pkg_file"
[ -n "$_disk_needed" ] && [ "$(disksize "$extract")" -lt "$_disk_needed" ] && \
error "insufficent disk for package '$pkg' (needed ${_disk_needed}GB)"
[ -z "$_src" ] && _src=$(basename "$_uri")
for dep in $_build_dep; do
# () needed to create new environment
(build_pkg "$dep") || error "Building package $dep"
done
msg "Creating build image"
if [ -d "$extract" ]; then
if [ -d "$extract/tmp/tcloop" ]; then
while IFS= read -r -d '' _dir; do
umount "$_dir"
done < <(find "$extract/tmp/tcloop" -type "d" -print0)
fi
[ -d "$extract/proc" ] && [ "$(ls -A "$extract/proc")" != "" ] && umount "$extract/proc"
rm -fr "$extract"
fi
mkdir -p "$extract"
zcat "$squashfs" | { cd "$extract" || exit 1; cpio -i -H newc -d; }
mount -t proc /proc "$extract/proc"
# FIXME : Fix missing links
# It appears that certain links are missings with the base intsall
# and they need to be forced
( cd "$extract/usr/lib" || exit 1; [ -e "libpthread.so" ] || ln -s ../../lib/libpthread.so.0 libpthread.so; )
( cd "$extract/usr/lib" || exit 1; [ -e "libdl.so" ] || ln -s ../../lib/libdl.so.2 libdl.so; )
# Force install of coreutils as always needed for install_tcz
install_tcz coreutils
# shellcheck disable=SC2086
install_tcz $_build_dep
# Copy /etc/resolv.conf file
mkdir -p "$extract/etc"
cp -p /etc/resolv.conf "$extract/etc/resolv.conf"
msg "Building $_pkg.tcz"
mkdir -p "$src_dir"
download "$_uri" "$src_dir" "$_src"
mkdir -p "$extract/home/tc"
mkdir -p "$extract/$builddir"
mkdir -p "$extract/$destdir"
unpack "$src_dir/$_src" "$extract/$builddir" || error "Can not unpack $_src"
chroot "$extract" chown -R ${tc}:${staff} /home/tc
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
export HOME=/home/tc
$_pre_config
exit \$?
EOF
chmod a+x "$extract/tmp/script"
[ -z "$_pre_config" ] || chroot "$extract" /tmp/script || { umount "$extract/proc"; error "Unexpected error ($?) in configuration"; }
msg "Configuring $_pkg"
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
export HOME=/home/tc
cd $builddir/$_pkg_path
$_conf_cmd
exit \$?
EOF
chmod a+x "$extract/tmp/script"
[ -z "$_conf_cmd" ] || chroot --userspec=${tc} "$extract" /tmp/script || { umount "$extract/proc"; error "Unexpected error ($?) in configuration"; }
msg "Building $_pkg"
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
export HOME=/home/tc
cd $builddir/$_pkg_path
$_make_cmd
exit \$?
EOF
chmod a+x "$extract/tmp/script"
[ -z "$_make_cmd" ] || chroot --userspec=${tc} "$extract" /tmp/script $_make_cmd || { umount "$extract/proc"; error "Unexpected error ($?) in build"; }
msg "Installing $_pkg"
cat << EOF > "$extract/tmp/script"
export DESTDIR=$destdir
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
export HOME=/home/tc
cd $builddir/$_pkg_path
$_install_cmd$destdir
exit \$?
EOF
chmod a+x "$extract/tmp/script"
[ -z "$_install_cmd" ] || chroot "$extract" /tmp/script || { umount "$extract/proc"; error "Unexpected error ($?) in install"; }
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
export HOME=/home/tc
destdir=$destdir
builddir=$builddir
_pkg_path=$_pkg_path
cd $destdir
$_post_build
exit \$?
EOF
chmod a+x "$extract/tmp/script"
[ -z "$_post_build" ] || { msg "Post build script"; chroot "$extract" /tmp/script; } || { umount "$extract/proc"; error "Unexpected error ($?) in post build"; }
# Create post-install script if needed
if [ -n "$_post_install" ]; then
msg "Creating post install script"
mkdir -p "$extract$destdir/usr/local/tce.installed"
echo "$_post_install" > "$extract$destdir/usr/local/tce.installed/$_pkg"
chmod 755 "$extract$destdir/usr/local/tce.installed/$_pkg"
fi
# Create the pkgname and shell escaped list of directories/files and then make TCZ
OIFS=$IFS
IFS=";"
[ -z "$_pkgs" ] && _pkgs="main{.}"
for arg in $_pkgs; do
pkg=$(echo "$arg" | sed -e "s/{.*$//" | awk '{$1=$1};1')
IFS=","
dirs=""
set -o noglob
for _dir in $(echo "$arg" | sed -e 's/^.*{\(.*\)}$/\1/'); do
dirs="$dirs $(echo "$_dir" | sed -e 's:^/::')"
done
set +o noglob
IFS=$OIFS
if [ "$pkg" = "main" ]; then
tcz=$_pkg.tcz
[ -z "$_post_install" ] || dirs="$dirs usr/local/tce.installed"
else
tcz=$_pkg-$pkg.tcz
fi
msg "Creating $tcz"
[ -f "$tcz_dir/$tcz" ] && rm "$tcz_dir/$tcz"
tempdir=$(mktemp -d)
chmod 755 "$tempdir"
# shellcheck disable=SC2086
(cd "$extract$destdir" || exit 1; tar -cf - $dirs | tar -C "$tempdir" -x -f -)
mksquashfs "$tempdir" "$tcz_dir/$tcz"
rm -fr "$tempdir"
md5sum "$tcz_dir/$tcz" | sed -e "s: $tcz_dir/$tcz$::g" > "$tcz_dir/$tcz.md5.txt"
if [ "$pkg" = "main" ]; then
echo -n "" > "$tcz_dir/$tcz.dep"
for dep in $_dep; do
echo -n -e "$dep\n" >> "$tcz_dir/$tcz.dep"
done
else
echo "$_pkg" > "$tcz_dir/$tcz.dep"
fi
IFS=";"
done
IFS=$OIFS
umount "$extract/proc"
if [ "$keep" = "0" ]; then
msg "Removing build image"
if [ -d "$extract" ]; then
rm -fr "$extract"
fi
fi
else
# Can't rebuild package try getting the tcz
_old="$extract"
extract="$build"
get_tcz "$pkg"
extract="$_old"
fi
fi
done
}
# Special version for firefox
get_tcz_and_deps() {
_dest=$1
shift
for _pkg; do
[ -f "$_dest/$_pkg.tcz" ] && continue
msg "Copy $_pkg.tcz to $_dest"
cp "$tcz_dir/$_pkg.tcz" "$tcz_dir/$_pkg.tcz.dep" "$_dest"
( cd "$_dest" || exit 1; md5sum "$_pkg.tcz" > "$_pkg.tcz.md5.txt"; ) || exit 1
_dep=$tcz_dir/$_pkg.tcz.dep
if test -s "$_dep"; then
# Want word splitting on arg to
# shellcheck disable=SC2046
get_tcz_and_deps "$_dest" $(sed -e s/.tcz$// "$_dep")
fi
done
}
install_firefox(){
package=firefox
target=$tcz_dir/$package.tcz
dep=$target.dep
latest=firefox_getLatest
if test ! -f "$target"; then
if test -f "$tce_dir/$package.tcz"; then
msg "fetching package $package ..."
cp "$tce_dir/$package.tcz" "$target"
if ! test -f "$tce_dir/$package/tcz.dep"; then
touch "$tce_dir/$package.tcz.dep"
fi
else
_old=$extract
extract="$build"
if [ -d "$extract" ]; then
if [ -d "$extract/tmp/tcloop" ]; then
while IFS= read -r -d '' _dir; do
umount "$_dir"
done < <(find "$extract/tmp/tcloop" -type "d" -print0)
fi
[ -d "$extract/proc" ] && [ "$(ls -A "$extract/proc")" != "" ] && umount "$extract/proc"
rm -fr "$extract"
fi
mkdir -p "$extract"
zcat "$squashfs" | { cd "$extract" || exit 1; cpio -i -H newc -d; }
mount -t proc /proc "$extract/proc"
# FIXME : Fix missing links
# It appears tqhat certain links are missings with the base intsall
# and they need to be forced
( cd "$extract/usr/lib" || exit 1; [ -e "libpthread.so" ] || ln -s ../../lib/libpthread.so.0 libpthread.so; )
( cd "$extract/usr/lib" || exit 1; [ -e "libdl.so" ] || ln -s ../../lib/libdl.so.2 libdl.so; )
# Force install of coreutils as always needed for install_tcz
# In seperate shell to avoid modifiying local variables
( install_tcz coreutils )
( install_tcz "$latest" )
# Find dependencies in "$latest" and install them to allow them to be
# cached and avoid too many downloads. sqfsTools is useds in the eval
# shellcheck disable=SC2034
sqfsTools="squashfs-tools"
# disable wierd sheelcheck warning
# shellcheck disable=SC2046
eval $(sed -n '/deps1="/,/"/p' $extract/usr/local/bin/$latest.sh | sed -e "s:\\\::g" -e "/^\s*else/d" -e "/^\s*echo/d")
mkdir -p $extract/tmp/tce/optional
chown -R $tc:$staff $extract/tmp/tce
chmod 775 $extract/tmp/tce $extract/tmp/tce/optional
# deps1 is defined via the eval above. Yes I want word-splitting
# shellcheck disable=SC2154
# shellcheck disable=SC2086
( install_tcz $deps1 libssh2 )
# Yes I want word-splitting
# shellcheck disable=SC2086
( get_tcz_and_deps "$extract/tmp/tce/optional" $deps1 )
chmod -R 644 "$extract/tmp/tce/optional"
chmod 775 $extract/tmp/tce/optional
chown -R $tc:$staff "$extract/tmp/tce/optional"
# Copy /etc/resolv.conf file
mkdir -p "$extract/etc"
cp -p /etc/resolv.conf "$extract/etc/resolv.conf"
mkdir -p "$extract/home/tc"
chown ${tc}:${staff} "$extract/home/tc"
echo tc > "$extract/etc/sysconfig/tcuser"
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
export USER=tc
sudo tce-setup
sudo update-ca-certificates
$latest.sh -e || exit 1
EOF
chmod a+x "$extract/tmp/script"
msg "Constructing package $package"
HOME=/home/tc chroot --userspec=${tc} "$extract" /tmp/script || error error constructing $package
msg "fetching package $package"
cp "$extract/tmp/tce/optional/$package.tcz" "$target"
if ! test -f "$extract/tmp/tce/optional/$package.tcz.dep"; then
touch "$tce_dir/$package.tcz.dep"
else
cp "$extract/tmp/tce/optional/$package.tcz.dep" "$target.dep"
fi
md5sum "$target" | sed -e "s: $target$::g" > "$target.md5.txt"
if [ -d "$extract/tmp/tcloop" ]; then
while IFS= read -r -d '' _dir; do
umount "$_dir"
done < <(find "$extract/tmp/tcloop" -type "d" -print0)
fi
[ -d "$extract/proc" ] && [ "$(ls -A "$extract/proc")" != "" ] && umount "$extract/proc"
rm -fr "$extract"
extract="$_old"
fi
fi
install_tcz $package
}
install_webdriver(){
package=dsaswebdriver
target=$tcz_dir/$package.tcz
dep=$target.dep
if test ! -f "$target"; then
# Install PHP composer
download -f "https:/getcomposer.org/installer" "$src_dir" "php_composer"
mkdir -p "$extract/home/tc"
chown ${tc}:${staff} "$extract/home/tc"
chmod 750 "$extract/home/tc"
cp "$src_dir/php_composer" "$extract/home/tc"
chmod a+rx "$extract/home/tc/php_composer"
chroot "$extract" chown -R ${tc}:${staff} "/home/tc/"
cp /etc/resolv.conf "$extract/etc/resolv.conf" && msg "copy resolv.conf"
# http_proxy is imported (or not) from the environment. Shellcheck
# complains if we don't force a default value here
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
cd /home/tc
env HOME=/home/tc php php_composer || exit 1
rm php_composer
EOF
chmod a+x "$extract/tmp/script"
msg "Install PHP Composer $extract"
HOME=/home/tc chroot --userspec=${tc} "$extract" /tmp/script || error composer installation failed
# Install Facebook Webdriver
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
cd /home/tc
env HOME=/home/tc php composer.phar require php-webdriver/webdriver
EOF
chmod a+x "$extract/tmp/script"
msg "Install PHP Web driver"
chroot --userspec=${tc} "$extract" /tmp/script
# Remove temporary resolv.conf
rm "$extract/etc/resolv.conf"
# Create the package for next use
msg "Creating $package.tcz"
[ -f "$package" ] && rm "$package"
tempdir=$(mktemp -d)
chmod 755 "$tempdir"
mkdir -p "$tempdir/usr/local/share/dsas"
chmod -R 755 "$tempdir/usr"
# shellcheck disable=SC2086
(cd "$extract/home/tc" || exit 1; tar -cf - vendor | tar -C "$tempdir/usr/local/share/dsas" -x -f -)
mksquashfs "$tempdir" "$target"
rm -fr "$tempdir"
md5sum "$target" | sed -e "s: $target$::g" > "$target.md5.txt"
echo -n "" > "$target.dep"
fi
install_tcz $package
}
install_phpstan(){
package=dsasphpstan
target=$tcz_dir/$package.tcz
dep=$target.dep
if test ! -f "$target"; then
# Install PHP composer
download -f "https:/getcomposer.org/installer" "$src_dir" "php_composer"
mkdir -p "$extract/home/tc"
chown ${tc}:${staff} "$extract/home/tc"
chmod 750 "$extract/home/tc"
cp "$src_dir/php_composer" "$extract/home/tc"
chmod a+rx "$extract/home/tc/php_composer"
chroot "$extract" chown -R ${tc}:${staff} "/home/tc/"
cp /etc/resolv.conf "$extract/etc/resolv.conf" && msg "copy resolv.conf"
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
cd /home/tc
env HOME=/home/tc php php_composer || exit 1
rm php_composer
EOF
chmod a+x "$extract/tmp/script"
msg "Install PHP Composer $extract"
HOME=/home/tc chroot --userspec=${tc} "$extract" /tmp/script || error composer installation failed
# Install PHPSTAN
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
cd /home/tc
env HOME=/home/tc php composer.phar require --dev phpstan/phpstan
EOF
chmod a+x "$extract/tmp/script"
msg "Install PHPStan"
chroot --userspec=${tc} "$extract" /tmp/script
# Remove temporary resolv.conf
rm "$extract/etc/resolv.conf"
# Create the package for next use
msg "Creating $package.tcz"
[ -f "$package" ] && rm "$package"
tempdir=$(mktemp -d)
chmod 755 "$tempdir"
mkdir -p "$tempdir/home/tc"
chmod -R 755 "$tempdir/home"
# shellcheck disable=SC2086
(cd "$extract/home/tc" || exit 1; tar -cf - composer.* vendor | tar -C "$tempdir/home/tc" -x -f -)
mksquashfs "$tempdir" "$target"
rm -fr "$tempdir"
md5sum "$target" | sed -e "s: $target$::g" > "$target.md5.txt"
echo -n "" > "$target.dep"
fi
install_tcz $package
}
install_dsas_js() {
package=dsas_js
target=$tcz_dir/$package.tcz
dep=$target.dep
# Remove old TCZ if JS file is newer
if [ -f "$target" ]; then
while IFS= read -r -d '' file; do
if [ "$(stat -c '%Y' "$target")" -lt "$(stat -c '%Y' "$file")" ]; then
rm -f "$target"
break;
fi
done < <(find ./js -name "*.js" -print0)
fi
if test ! -f "$target"; then
_old=$extract
extract="$build"
if [ -d "$extract" ]; then
while IFS= read -r -d '' _dir; do
umount "$_dir"
done < <(find "$extract/tmp/tcloop" -type "d" -print0)
[ -d "$extract/proc" ] && [ "$(ls -A "$extract/proc")" != "" ] && umount "$extract/proc"
rm -fr "$extract"
fi
mkdir -p "$extract"
zcat "$squashfs" | { cd "$extract" || exit 1; cpio -i -H newc -d; }
mount -t proc /proc "$extract/proc"
# FIXME : Fix missing links
# It appears that certain links are missings with the base intsall
# and they need to be forced
( cd "$extract/usr/lib" || exit 1; [ -e "libpthread.so" ] || ln -s ../../lib/libpthread.so.0 libpthread.so; )
( cd "$extract/usr/lib" || exit 1; [ -e "libdl.so" ] || ln -s ../../lib/libdl.so.2 libdl.so; )
# Force install of coreutils as always needed for install_tcz
# In seperate shell to avoid modifiying local variables
( install_tcz coreutils compiletc curl node )
# Copy /etc/resolv.conf file
mkdir -p "$extract/etc"
cp -p /etc/resolv.conf "$extract/etc/resolv.conf"
# Copy DSAS files to build tree
mkdir -p $extract/home/tc/dsas
tar cf - --exclude tmp --exclude=work --exclude=.git . | tar -C $extract/home/tc/dsas -xvf -
chown -R ${tc}:${staff} $extract/home/tc
if [ "$testcode" = "1" ]; then
maketype="dev"
else
maketype="prod"
fi
mkdir -p "$extract/tmp"
chmod 1777 "$extract/tmp"
cat << EOF > "$extract/tmp/script"
export LD_LIBRARY_PATH=/usr/local/lib:/usr/lib:/lib
export http_proxy=${http_proxy:=}
export https_proxy=${https_proxy:=}
export HOME=/home/tc
export USER=tc
cd /home/tc/dsas/js
make ${maketype}
EOF
chmod a+x "$extract/tmp/script"
msg "Building $package"
HOME=/home/tc chroot --userspec=${tc} "$extract" /tmp/script || error error constructing $package
msg "Constructing package $package"
# Create the package for next use
tempdir=$(mktemp -d)
chmod 755 "$tempdir"
mkdir -p "$tempdir/usr/local/share/www"
chmod -R 755 "$tempdir/usr"
cp "$extract/home/tc/dsas/js/dist/dsas.js" "$tempdir/usr/local/share/www"
mksquashfs "$tempdir" "$target"
rm -fr "$tempdir"
md5sum "$target" | sed -e "s: $target$::g" > "$target.md5.txt"
echo -n "" > "$target.dep"
extract="$_old"
fi
install_tcz $package
}
get_unpack_livecd(){
test -f $livecd0 || msg Downloading $livecd_url
test -f $livecd0 || cmd "$curl_cmd" -o "$livecd0" "$livecd_url" || exit 1
mkdir -pv $mnt
if ! ls $squashfs >/dev/null 2> /dev/null; then
msg Unpacking the ISO $livecd_url
mount | grep $livecd0 > /dev/null || cmd mount $livecd0 $mnt
cmd rsync -av --exclude=boot.cat $mnt/ $newiso/
cmd umount $mnt
fi
# Setup kernel name for package dependencies include "-KERNEL"
# If on tinycore, can get it from $(uname -r), otherwise from
# a tinycore image and find "*lib/modules/KERNEL-tinycore*" directory
if uname -r | grep -q tinycore; then
_kern=$(uname -r)
else
_kern=$(zcat $work/newiso/boot/corepure64.gz | cpio -t 2> /dev/null | grep "/lib/modules/" | head -1 | tr '/' '\n' | grep tinycore)
fi
}
startdate=$(date +%s)
case $cmd in
work)
pkgs=$(echo "$pkgs" | xargs)
if [ -z "$pkgs" ]; then
[ -L "$work" ] && rm "$work"
mkdir -p "$work"
else
[ -d "$pkgs" ] || mkdir "$pkgs"
[ -d "$work" ] && mv "$work" "$work.old"
[ -L "$work" ] && rm "$work"
ln -s "$pkgs" "$work"
fi
;;
source)
tar cvzf $source --exclude=tmp --exclude=work --exclude=.git* .
exit 0
;;
clean)
make -C "$testdir" clean
[ -e $work ] || exit 0
if [ -d "$build/tmp/tcloop" ]; then
while IFS= read -r -d '' _dir; do
umount "$_dir"
done < <(find "$build/tmp/tcloop" -type "d" -print0)
fi
[ -d "$image/proc" ] && [ "$(ls -A "$image/proc")" != "" ] && umount "$image/proc"
[ -d "$build/proc" ] && [ "$(ls -A "$build/proc")" != "" ] && umount "$build/proc"
rm -fr $image $build $newiso $mnt $dsascd $rootfs64 $dsascd.md5 \
$docker $dockimage $source $work/dsas_pass.txt
exit 0
;;
realclean)
make -C "$testdir" realclean
[ -e $work ] || exit 0
rm -fr "${work:?}/?*"
exit 0
;;
upgrade)
[ -e $work ] || error work directory does not exist. run \'./make.sh work ...\'
msg Fetching md5.db.gz
$curl_cmd -o "$tcz_dir/md5.db.gz" "$tcz_url/md5.db.gz" || error failed to download md5.db.gz
gzip -f -d $tcz_dir/md5.db.gz
while IFS= read -r -d '' file; do
_file=${file#"$tcz_dir"/}
pkg_file=$pkg_dir/${_file%.tcz}
pkg_file=${pkg_file%-dev}
pkg_file=${pkg_file%-doc}.pkg
[ -f "$pkg_file" ] && continue # Locally built package
[ "$_file" = "dsastestfiles.tcz" ] && continue # Locally built file
[ "$_file" = "dsasphpstan.tcz" ] && continue # Locally built file
[ "$_file" = "dsas_js.tcz" ] && { msg "Removing $_file"; rm -f "$file"; continue; } # Remove to force rebuild
[ "$_file" = "dsaswebdriver.tcz" ] && { msg "Removing $_file"; rm -f "$file"; continue; } # Remove to force rebuild
[ "$_file" = "firefox.tcz" ] && { msg "Removing $_file"; rm -f "$file"; continue; } # Remove to force a rebuild
read -r hash < "$file.md5.txt"
if ! grep -q "^$hash $_file" $tcz_dir/md5.db; then
# Don't use get_tcz as don't want to use local TCZ files
rm -f "$file"
msg "Fetching package $_file ..."
$curl_cmd -o "$file" "$tcz_url/$_file" || exit 1
$curl_cmd -o "${file}.dep" "$tcz_url/${_file}.dep" || exit 1
[ -f "${file}.info" ] || $curl_cmd -o "${file}.info" "$tcz_url/${_file}.info" || exit 1
md5sum "$file" | sed -e "s: $file$::g" > "$file.md5.txt"
fi
done < <(find $tcz_dir -name "*.tcz" -print0)
;;
static)
extract=$image
# Get the ISO
[ -e $work ] || error work directory does not exit. run \'./make.sh work ...\'
get_unpack_livecd
# Unpack squashfs
if ! ls $extract/proc > /dev/null 2> /dev/null; then
cmd mkdir -p $extract
zcat "$squashfs" | { cd "$extract" || exit 1; cpio -i -H newc -d; }
fi
# Install the needed packages
install_tcz compiletc
install_tcz openssl
install_tcz libxml2
install_tcz libssh2
install_tcz libzip
install_tcz bzip2-lib
install_tcz php-8.2-cgi
install_tcz php-8.2-ext
install_tcz php-pam
install_tcz curl
install_tcz rsync
install_tcz node
[ "$arch" != 64 ] && install_tcz pcre2
[ "$arch" = 64 ] && install_tcz pcre21032
# FIXME Force installation of a PCRE that works with PHP composer
install_tcz pcre21042