@@ -27,21 +27,35 @@ SRC_ROOT=${DIR}
27
27
ZBM_ROOT=${SRC_ROOT} /../zfsbootmenu
28
28
RECIPES_ROOT=${RECIPES_ROOT:- ${SRC_ROOT} / recipes}
29
29
30
- RECIPE_BUILDER=" ghcr.io/midzelis/zquickinit"
31
- ZQUICKEFI_URL=" https://github.com/midzelis/zquickinit/releases/latest"
32
- # if empty, use latest release tag
33
- ZBM_TAG=
30
+ RECIPE_BUILDER=" ${RECIPE_BUILDER:- ghcr.io/ midzelis/ zquickinit} "
31
+ ZQUICKINIT_REPO=" ${ZQUICKINIT_REPO:- https:// github.com/ midzelis/ zquickinit} "
32
+ ZQUICKEFI_URL=" ${ZQUICKEFI_URL:- ${ZQUICKINIT_REPO} / releases/ latest} "
33
+
34
+ # provide default stable, latest ZBM_TAG if not specified
35
+ ZBM_TAG=" ${ZBM_TAG:- v3.0.1} "
36
+ # if empty, then unset to get latest release
37
+ if [[ -z " $ZBM_TAG " ]]; then
38
+ ZBM_TAG=" "
39
+ fi
40
+
34
41
# if specified, takes precedence over ZBM_TAG
35
- ZBM_COMMIT_HASH=db78c980f40937f3b4de8d85e7430f6553a39972
42
+ ZBM_COMMIT_HASH=" ${ZBM_COMMIT_HASH:- } "
43
+ # if ZBM_COMMIT_HASH is specified, unset ZBM_TAG
44
+ if [[ -n " $ZBM_COMMIT_HASH " ]]; then
45
+ ZBM_TAG=" "
46
+ fi
47
+
36
48
INPUT=/input
37
49
OUTPUT=/output
38
50
ADD_LOADER=
39
51
MKINIT_VERBOSE=
40
52
KERNEL_BOOT=
41
53
ENGINE=
42
54
OBJCOPY=
55
+ DU=
43
56
FIND=
44
57
YG=
58
+ STAT=
45
59
NOASK=0
46
60
DEBUG=0
47
61
ENTER=0
@@ -101,10 +115,10 @@ check() {
101
115
fi
102
116
fi
103
117
if [[ $1 == docker || $1 == podman ]]; then
104
- if command -v docker & > /dev/null; then
118
+ if [ -z " $ENGINE " ] && command -v docker & > /dev/null; then
105
119
ENGINE=docker
106
120
return 0
107
- elif command -v podman & > /dev/null; then
121
+ elif [ -z " $ENGINE " ] && command -v podman & > /dev/null; then
108
122
ENGINE=podman
109
123
return 0
110
124
fi
@@ -142,17 +156,6 @@ check() {
142
156
OBJCOPY=objcopy
143
157
fi
144
158
fi
145
- if ! command -v " $1 " & > /dev/null; then
146
- echo " $1 not found. usually part of the $2 package"
147
- if [[ $1 == " gum" && -f " /etc/debian_version" ]]; then
148
- echo " To install, try:"
149
- echo ' sudo mkdir -p /etc/apt/keyrings'
150
- echo ' curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg'
151
- echo ' echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list'
152
- echo ' sudo apt update && sudo apt install gum'
153
- fi
154
- exit 1
155
- fi
156
159
if [[ $1 == find ]] && [[ -z " ${FIND} " ]]; then
157
160
if command -v gfind & > /dev/null; then
158
161
FIND=" gfind"
@@ -168,6 +171,47 @@ check() {
168
171
exit 1
169
172
fi
170
173
fi
174
+ if [[ $1 == du ]] && [[ -z " ${DU} " ]]; then
175
+ if command -v gdu & > /dev/null; then
176
+ DU=" gdu"
177
+ else
178
+ DU=" du"
179
+ fi
180
+ if [[ ! " $( ${DU} --version 2>&1 | head -n1) " == * GNU* ]]; then
181
+ echo " du must be GNU flavored. Update or install coreutils package. "
182
+ if [[ " $OSTYPE " == " darwin" * ]]; then
183
+ echo " On MacOS, use brew to install coreutils"
184
+ echo " Note: brew uses /usr/local/bin on Intel, and /opt/homebrew/bin on Apple"
185
+ fi
186
+ exit 1
187
+ fi
188
+ fi
189
+ if [[ $1 == stat ]] && [[ -z " ${STAT} " ]]; then
190
+ if command -v gstat & > /dev/null; then
191
+ STAT=" gstat"
192
+ else
193
+ STAT=" stat"
194
+ fi
195
+ if [[ ! " $( ${STAT} --version 2>&1 | head -n1) " == * GNU* ]]; then
196
+ echo " stat must be GNU flavored. Update or install coreutils package. "
197
+ if [[ " $OSTYPE " == " darwin" * ]]; then
198
+ echo " On MacOS, use brew to install coreutils"
199
+ echo " Note: brew uses /usr/local/bin on Intel, and /opt/homebrew/bin on Apple"
200
+ fi
201
+ exit 1
202
+ fi
203
+ fi
204
+ if ! command -v " $1 " & > /dev/null; then
205
+ echo " $1 not found. usually part of the $2 package"
206
+ if [[ $1 == " gum" && -f " /etc/debian_version" ]]; then
207
+ echo " To install, try:"
208
+ echo ' sudo mkdir -p /etc/apt/keyrings'
209
+ echo ' curl -fsSL https://repo.charm.sh/apt/gpg.key | sudo gpg --dearmor -o /etc/apt/keyrings/charm.gpg'
210
+ echo ' echo "deb [signed-by=/etc/apt/keyrings/charm.gpg] https://repo.charm.sh/apt/ * *" | sudo tee /etc/apt/sources.list.d/charm.list'
211
+ echo ' sudo apt update && sudo apt install gum'
212
+ fi
213
+ exit 1
214
+ fi
171
215
}
172
216
173
217
# This will build the main ZquickInit Builder OCI image
@@ -197,6 +241,7 @@ builder() {
197
241
echo
198
242
cmd=(" $ENGINE " build .
199
243
-t " $RECIPE_BUILDER "
244
+ --label org.opencontainers.image.source=" ${ZQUICKINIT_REPO} "
200
245
--build-arg KERNELS=linux6.6
201
246
--build-arg " PACKAGES=${packages[*]} "
202
247
--build-arg ZBM_COMMIT_HASH=" ${ZBM_COMMIT_HASH} "
@@ -225,6 +270,7 @@ tailscale() {
225
270
make_zquick_initramfs () {
226
271
check gum gum
227
272
check mkinitcpio mkinitcpio
273
+ check stat stat
228
274
229
275
gum style --bold --border double --align center \
230
276
--width 50 --margin " 1 2" --padding " 0 2" " Welcome to ZQuickInit make initramfs"
@@ -234,13 +280,13 @@ make_zquick_initramfs() {
234
280
local hash
235
281
echo " Downloading zquickinit"
236
282
rm -rf " ${INPUT} "
237
- git clone --quiet --depth 1 https://github.com/midzelis/zquickinit.git " ${INPUT} "
283
+ git clone --quiet --depth 1 " ${ZQUICKINIT_REPO} " " ${INPUT} "
238
284
hash=$( cat /etc/zquickinit-commit-hash || echo ' ' )
239
285
if [[ -n " ${hash} " ]]; then
240
286
(cd " ${INPUT} " && git fetch --depth 1 origin " $hash " && git checkout FETCH_HEAD)
241
287
fi
242
288
fi
243
- [[ -x /etc/zquickinit-commit-hash ]] && (cd " ${INPUT} " && git config --global --add safe.directory " ${INPUT} " && /etc/zquickinit-commit-hash && git rev-parse HEAD > /etc/zquickinit-commit-hash && echo " ZQuickInit (https://github.com/midzelis/zquickinit ) commit hash: $( git rev-parse --short HEAD) ($( git rev-parse HEAD) )" )
289
+ [[ -x /etc/zquickinit-commit-hash ]] && (cd " ${INPUT} " && git config --global --add safe.directory " ${INPUT} " && /etc/zquickinit-commit-hash && git rev-parse HEAD > /etc/zquickinit-commit-hash && echo " ZQuickInit (${ZQUICKINIT_REPO} ) commit hash: $( git rev-parse --short HEAD) ($( git rev-parse HEAD) )" )
244
290
245
291
if [[ ! -f " ${ZBM} /bin/generate-zbm" ]]; then
246
292
echo " Downloading latest zfsbootmenu"
@@ -576,9 +622,9 @@ make_zquick_initramfs() {
576
622
)
577
623
chmod o+rw -R " ${OUTPUT} " /*
578
624
chmod g+rw -R " ${OUTPUT} " /*
579
- env LC_ALL=en_US.UTF-8 printf " Kernel size: \t\t%'.0f bytes\n" " $( stat -c ' %s' " ${OUTPUT} /zquickinit-$build_time .vmlinuz-$kernel " ) "
580
- env LC_ALL=en_US.UTF-8 printf " initramfs size: \t%'.0f bytes\n" " $( stat -c ' %s' " $output_img " ) "
581
- env LC_ALL=en_US.UTF-8 printf " EFI size: \t\t%'.0f bytes\n" " $( stat -c ' %s' " $output_uki " ) "
625
+ env LC_ALL=en_US.UTF-8 printf " Kernel size: \t\t%'.0f bytes\n" " $( ${STAT} -c ' %s' " ${OUTPUT} /zquickinit-$build_time .vmlinuz-$kernel " ) "
626
+ env LC_ALL=en_US.UTF-8 printf " initramfs size: \t%'.0f bytes\n" " $( ${STAT} -c ' %s' " $output_img " ) "
627
+ env LC_ALL=en_US.UTF-8 printf " EFI size: \t\t%'.0f bytes\n" " $( ${STAT} -c ' %s' " $output_uki " ) "
582
628
find " ${OUTPUT} " -name ' zquickinit*.img' | sort -r | tail -n +4 | xargs -r rm
583
629
find " ${OUTPUT} " -name ' zquickinit*.efi' | sort -r | tail -n +4 | xargs -r rm
584
630
find " ${OUTPUT} " -name ' zquickinit*.vmlinuz-*' | sort -r | tail -n +4 | xargs -r rm
@@ -631,7 +677,7 @@ getefi() {
631
677
echo " No image found, finding latest release..."
632
678
local version=' ' download=' '
633
679
version=$( curl --silent -qI " ${ZQUICKEFI_URL} " | awk -F ' /' ' /^location/ {print substr($NF, 1, length($NF)-1)}' )
634
- download=" https://github.com/midzelis/zquickinit /releases/download/$version /zquickinit.efi"
680
+ download=" ${ZQUICKINIT_REPO} /releases/download/$version /zquickinit.efi"
635
681
source=" ${tmp} /zquickinit-${version} .efi"
636
682
echo " Downloading from ${download} to ${source} ..."
637
683
curl -o " $source " --progress-bar -L " ${download} "
@@ -736,6 +782,7 @@ inject() {
736
782
check bsdtar " libarchive-tools"
737
783
check objcopy binutils
738
784
check truncate coreutils
785
+ check stat coreutils
739
786
check find findutils
740
787
741
788
echo " Secrets were injected, appending '_injected' to name"
@@ -753,7 +800,7 @@ inject() {
753
800
# To append an additional initrd segment, the new archive must aligned to a
754
801
# 4-byte boundary: https://unix.stackexchange.com/a/737219
755
802
756
- initrd_size=$( stat -c ' %s' " ${initrd} " )
803
+ initrd_size=$( ${STAT} -c ' %s' " ${initrd} " )
757
804
initrd_size=$(( (initrd_size + 3 ) / 4 * 4 ))
758
805
truncate -s " ${initrd_size} " " ${initrd} "
759
806
@@ -829,6 +876,7 @@ iso() {
829
876
check xorriso xorriso
830
877
check truncate coreutils
831
878
check find findutils
879
+ check du coreutils
832
880
833
881
local target=${1:- zquickinit.iso}
834
882
local source=${2:- }
@@ -844,7 +892,7 @@ iso() {
844
892
local isoroot=" ${tmp} /iso"
845
893
mkdir -p " ${isoroot} "
846
894
local size
847
- read -ra size <<< " $(du --apparent-size --block-size=1M " $source " )"
895
+ read -ra size <<< " $(${DU} --apparent-size --block-size=1M " $source " )"
848
896
local padded=$(( size[0 ] + 12 ))
849
897
local part_img=" ${tmp} /efs_partition.img"
850
898
rm -rf " ${part_img} "
@@ -878,6 +926,7 @@ playground() {
878
926
check truncate coreutils
879
927
check qemu-system-x86_64 qemu
880
928
check find findutils
929
+ check nproc coreutils
881
930
882
931
# shellcheck disable=SC2155
883
932
local tmp=$( tmpdir)
@@ -1101,6 +1150,12 @@ if [[ $(type -t "$command") == function ]]; then
1101
1150
shift
1102
1151
fi
1103
1152
;;
1153
+ --engine)
1154
+ if [[ -n ${2:- } ]]; then
1155
+ ENGINE=$2
1156
+ shift
1157
+ fi
1158
+ ;;
1104
1159
--no-container)
1105
1160
NOCONTAINER=1
1106
1161
;;
@@ -1188,6 +1243,7 @@ else
1188
1243
echo " --no-container Do not use containers to build initramfs"
1189
1244
echo " --release Do not add QEMU debug, or any secrets"
1190
1245
echo " --secrets <dir> Use this folder for secrets."
1246
+ echo " --engine <docker|podman> Override automatic detection to use specific engine."
1191
1247
echo " -d,--debug Advanced: Turn on tracing"
1192
1248
echo " -e,--enter Advanced: Do not build an image. Execute bash and"
1193
1249
echo " enter the builder image."
0 commit comments