@@ -27,21 +27,35 @@ SRC_ROOT=${DIR}
2727ZBM_ROOT=${SRC_ROOT} /../zfsbootmenu
2828RECIPES_ROOT=${RECIPES_ROOT:- ${SRC_ROOT} / recipes}
2929
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+
3441# 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+
3648INPUT=/input
3749OUTPUT=/output
3850ADD_LOADER=
3951MKINIT_VERBOSE=
4052KERNEL_BOOT=
4153ENGINE=
4254OBJCOPY=
55+ DU=
4356FIND=
4457YG=
58+ STAT=
4559NOASK=0
4660DEBUG=0
4761ENTER=0
@@ -101,10 +115,10 @@ check() {
101115 fi
102116 fi
103117 if [[ $1 == docker || $1 == podman ]]; then
104- if command -v docker & > /dev/null; then
118+ if [ -z " $ENGINE " ] && command -v docker & > /dev/null; then
105119 ENGINE=docker
106120 return 0
107- elif command -v podman & > /dev/null; then
121+ elif [ -z " $ENGINE " ] && command -v podman & > /dev/null; then
108122 ENGINE=podman
109123 return 0
110124 fi
@@ -142,17 +156,6 @@ check() {
142156 OBJCOPY=objcopy
143157 fi
144158 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
156159 if [[ $1 == find ]] && [[ -z " ${FIND} " ]]; then
157160 if command -v gfind & > /dev/null; then
158161 FIND=" gfind"
@@ -168,6 +171,47 @@ check() {
168171 exit 1
169172 fi
170173 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
171215}
172216
173217# This will build the main ZquickInit Builder OCI image
@@ -197,6 +241,7 @@ builder() {
197241 echo
198242 cmd=(" $ENGINE " build .
199243 -t " $RECIPE_BUILDER "
244+ --label org.opencontainers.image.source=" ${ZQUICKINIT_REPO} "
200245 --build-arg KERNELS=linux6.6
201246 --build-arg " PACKAGES=${packages[*]} "
202247 --build-arg ZBM_COMMIT_HASH=" ${ZBM_COMMIT_HASH} "
@@ -225,6 +270,7 @@ tailscale() {
225270make_zquick_initramfs () {
226271 check gum gum
227272 check mkinitcpio mkinitcpio
273+ check stat stat
228274
229275 gum style --bold --border double --align center \
230276 --width 50 --margin " 1 2" --padding " 0 2" " Welcome to ZQuickInit make initramfs"
@@ -234,13 +280,13 @@ make_zquick_initramfs() {
234280 local hash
235281 echo " Downloading zquickinit"
236282 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} "
238284 hash=$( cat /etc/zquickinit-commit-hash || echo ' ' )
239285 if [[ -n " ${hash} " ]]; then
240286 (cd " ${INPUT} " && git fetch --depth 1 origin " $hash " && git checkout FETCH_HEAD)
241287 fi
242288 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) )" )
244290
245291 if [[ ! -f " ${ZBM} /bin/generate-zbm" ]]; then
246292 echo " Downloading latest zfsbootmenu"
@@ -576,9 +622,9 @@ make_zquick_initramfs() {
576622 )
577623 chmod o+rw -R " ${OUTPUT} " /*
578624 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 " ) "
582628 find " ${OUTPUT} " -name ' zquickinit*.img' | sort -r | tail -n +4 | xargs -r rm
583629 find " ${OUTPUT} " -name ' zquickinit*.efi' | sort -r | tail -n +4 | xargs -r rm
584630 find " ${OUTPUT} " -name ' zquickinit*.vmlinuz-*' | sort -r | tail -n +4 | xargs -r rm
@@ -631,7 +677,7 @@ getefi() {
631677 echo " No image found, finding latest release..."
632678 local version=' ' download=' '
633679 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"
635681 source=" ${tmp} /zquickinit-${version} .efi"
636682 echo " Downloading from ${download} to ${source} ..."
637683 curl -o " $source " --progress-bar -L " ${download} "
@@ -736,6 +782,7 @@ inject() {
736782 check bsdtar " libarchive-tools"
737783 check objcopy binutils
738784 check truncate coreutils
785+ check stat coreutils
739786 check find findutils
740787
741788 echo " Secrets were injected, appending '_injected' to name"
@@ -753,7 +800,7 @@ inject() {
753800 # To append an additional initrd segment, the new archive must aligned to a
754801 # 4-byte boundary: https://unix.stackexchange.com/a/737219
755802
756- initrd_size=$( stat -c ' %s' " ${initrd} " )
803+ initrd_size=$( ${STAT} -c ' %s' " ${initrd} " )
757804 initrd_size=$(( (initrd_size + 3 ) / 4 * 4 ))
758805 truncate -s " ${initrd_size} " " ${initrd} "
759806
@@ -829,6 +876,7 @@ iso() {
829876 check xorriso xorriso
830877 check truncate coreutils
831878 check find findutils
879+ check du coreutils
832880
833881 local target=${1:- zquickinit.iso}
834882 local source=${2:- }
@@ -844,7 +892,7 @@ iso() {
844892 local isoroot=" ${tmp} /iso"
845893 mkdir -p " ${isoroot} "
846894 local size
847- read -ra size <<< " $(du --apparent-size --block-size=1M " $source " )"
895+ read -ra size <<< " $(${DU} --apparent-size --block-size=1M " $source " )"
848896 local padded=$(( size[0 ] + 12 ))
849897 local part_img=" ${tmp} /efs_partition.img"
850898 rm -rf " ${part_img} "
@@ -878,6 +926,7 @@ playground() {
878926 check truncate coreutils
879927 check qemu-system-x86_64 qemu
880928 check find findutils
929+ check nproc coreutils
881930
882931 # shellcheck disable=SC2155
883932 local tmp=$( tmpdir)
@@ -1101,6 +1150,12 @@ if [[ $(type -t "$command") == function ]]; then
11011150 shift
11021151 fi
11031152 ;;
1153+ --engine)
1154+ if [[ -n ${2:- } ]]; then
1155+ ENGINE=$2
1156+ shift
1157+ fi
1158+ ;;
11041159 --no-container)
11051160 NOCONTAINER=1
11061161 ;;
@@ -1188,6 +1243,7 @@ else
11881243 echo " --no-container Do not use containers to build initramfs"
11891244 echo " --release Do not add QEMU debug, or any secrets"
11901245 echo " --secrets <dir> Use this folder for secrets."
1246+ echo " --engine <docker|podman> Override automatic detection to use specific engine."
11911247 echo " -d,--debug Advanced: Turn on tracing"
11921248 echo " -e,--enter Advanced: Do not build an image. Execute bash and"
11931249 echo " enter the builder image."
0 commit comments