refactor: harden diagnostics and consolidate runtime code
This commit is contained in:
@@ -85,6 +85,14 @@ render_bootloader_template() {
|
||||
initrd_placeholder="$7"
|
||||
initrd="$8"
|
||||
|
||||
for required_placeholder in \
|
||||
"@VERSION@" \
|
||||
"$kernel_placeholder" \
|
||||
"@APPEND_LIVE@" \
|
||||
"$initrd_placeholder"; do
|
||||
require_template_placeholder "$template" "$required_placeholder" || return 1
|
||||
done
|
||||
|
||||
BEE_RENDER_VERSION="$version" \
|
||||
BEE_RENDER_KERNEL_PLACEHOLDER="$kernel_placeholder" \
|
||||
BEE_RENDER_KERNEL="$kernel" \
|
||||
|
||||
@@ -359,9 +359,12 @@ validate_live_cmdline_params() {
|
||||
bad = 1
|
||||
}
|
||||
|
||||
$1 == command && has("boot=live") {
|
||||
$1 == command {
|
||||
live_entries++
|
||||
|
||||
if (!has("boot=live")) {
|
||||
reject("missing boot=live")
|
||||
}
|
||||
if (!has("udev.children_max=1")) {
|
||||
reject("missing udev.children_max=1")
|
||||
}
|
||||
@@ -432,7 +435,7 @@ validate_iso_live_boot_entries() {
|
||||
exit 1
|
||||
}
|
||||
|
||||
if grep -q '@APPEND_LIVE@\|@KERNEL_LIVE@\|@INITRD_LIVE@' "$grub_cfg" "$isolinux_cfg"; then
|
||||
if grep -Eq '@[A-Z][A-Z_]*@' "$grub_cfg" "$isolinux_cfg"; then
|
||||
echo "ERROR: unresolved live-build placeholders remain in ISO bootloader config" >&2
|
||||
rm -f "$grub_cfg" "$isolinux_cfg"
|
||||
exit 1
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
require_template_placeholder() {
|
||||
file="$1"
|
||||
placeholder="$2"
|
||||
if [ -z "$placeholder" ]; then
|
||||
echo "ERROR: template placeholder must not be empty" >&2
|
||||
return 1
|
||||
fi
|
||||
if ! BEE_TEMPLATE_PLACEHOLDER="$placeholder" awk '
|
||||
index($0, ENVIRON["BEE_TEMPLATE_PLACEHOLDER"]) { found=1 }
|
||||
END { exit found ? 0 : 1 }
|
||||
' "$file"; then
|
||||
echo "ERROR: required placeholder $placeholder is missing from $file" >&2
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
replace_literal_in_file() {
|
||||
file="$1"
|
||||
placeholder="$2"
|
||||
replacement="$3"
|
||||
require_template_placeholder "$file" "$placeholder" || return 1
|
||||
tmp="$(mktemp "${TMPDIR:-/tmp}/bee-template.XXXXXX")"
|
||||
|
||||
if BEE_TEMPLATE_PLACEHOLDER="$placeholder" \
|
||||
BEE_TEMPLATE_REPLACEMENT="$replacement" \
|
||||
awk '
|
||||
function replace_literal(text, needle, value, at) {
|
||||
while ((at = index(text, needle)) != 0) {
|
||||
text = substr(text, 1, at - 1) value substr(text, at + length(needle))
|
||||
}
|
||||
return text
|
||||
}
|
||||
{
|
||||
print replace_literal($0,
|
||||
ENVIRON["BEE_TEMPLATE_PLACEHOLDER"],
|
||||
ENVIRON["BEE_TEMPLATE_REPLACEMENT"])
|
||||
}
|
||||
' "$file" > "$tmp" && cat "$tmp" > "$file"; then
|
||||
status=0
|
||||
else
|
||||
status=$?
|
||||
fi
|
||||
rm -f "$tmp"
|
||||
return "$status"
|
||||
}
|
||||
|
||||
validate_project_version() {
|
||||
version="$1"
|
||||
case "$version" in
|
||||
""|[!A-Za-z0-9]*|*[!A-Za-z0-9]|*[!A-Za-z0-9.-]*)
|
||||
return 1
|
||||
;;
|
||||
esac
|
||||
return 0
|
||||
}
|
||||
Reference in New Issue
Block a user