Skip to content

Commit eb20eee

Browse files
committed
refactor(just): rewrite the qcow2 disk layout check for readability
1 parent de22d09 commit eb20eee

1 file changed

Lines changed: 13 additions & 51 deletions

File tree

Justfile

Lines changed: 13 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -161,67 +161,29 @@ package edition="workstation" format="all":
161161
}
162162
163163
check_qcow2_disk_layout() {
164-
local image="$1"
165-
local ctr=""
166-
local rootfs=""
164+
local image="$1" ctr rootfs boot_fstype
167165
local disk_yaml="/usr/lib/image-builder/bootc/disk.yaml"
168-
local status=0
169166
170167
[[ "$image" == localhost/* ]] || return 0
171168
172169
ctr="$(sudo buildah from --pull=never "${image}")"
173170
rootfs="$(sudo buildah mount "${ctr}")"
174171
175-
if [ ! -f "${rootfs}${disk_yaml}" ]; then
176-
echo "Missing ${disk_yaml} inside ${image}" >&2
177-
status=1
178-
else
179-
set +e
180-
sudo awk '
181-
BEGIN {
182-
code = 12
183-
}
184-
/payload:/ {
185-
in_payload = 1
186-
fs = ""
187-
}
188-
in_payload && /^[[:space:]]+type:/ {
189-
fs = $2
190-
gsub(/"/, "", fs)
191-
}
192-
in_payload && /^[[:space:]]+mountpoint:[[:space:]]+"\/boot"$/ {
193-
if (fs == "ext4") {
194-
code = 0
195-
exit 0
196-
}
197-
if (fs == "btrfs") {
198-
code = 10
199-
exit 10
200-
}
201-
code = 11
202-
exit 11
203-
}
204-
END {
205-
exit code
206-
}
207-
' "${rootfs}${disk_yaml}"
208-
status=$?
209-
set -e
210-
fi
211-
212-
if [ "${status}" != "0" ]; then
213-
if [ "${status}" = "10" ]; then
214-
echo "${image} still has /boot as btrfs in ${disk_yaml}." >&2
215-
echo "Rebuild the workstation image before packaging qcow2:" >&2
216-
echo " LOS_TAG=${package_tag} just build workstation" >&2
217-
else
218-
echo "Unable to validate /boot ext4 in ${image}:${disk_yaml}" >&2
219-
fi
220-
fi
172+
# /boot must stay ext4: image-builder qcow2 generation rejects btrfs there.
173+
boot_fstype="$(sudo awk '
174+
/^[[:space:]]+type: "(ext4|btrfs)"$/ { t = $2; gsub(/"/, "", t) }
175+
/mountpoint:[[:space:]]+"\/boot"/ { print t; exit }
176+
' "${rootfs}${disk_yaml}" 2>/dev/null || true)"
221177
222178
sudo buildah umount "${ctr}" >/dev/null 2>&1 || true
223179
sudo buildah rm "${ctr}" >/dev/null 2>&1 || true
224-
return "${status}"
180+
181+
if [ "${boot_fstype}" != "ext4" ]; then
182+
echo "${image} does not have /boot as ext4 in ${disk_yaml} (found: '${boot_fstype:-missing}')." >&2
183+
echo "Rebuild the workstation image before packaging qcow2:" >&2
184+
echo " LOS_TAG=${package_tag} just build workstation" >&2
185+
return 1
186+
fi
225187
}
226188
227189
case "{{ format }}" in

0 commit comments

Comments
 (0)