working version 1

This commit is contained in:
Maxime Van Hees
2025-08-26 17:46:42 +02:00
parent e8a369e3a2
commit 773db2238d

View File

@@ -204,7 +204,7 @@ if [ -z \"$NBD\" ]; then
exit 1
fi
echo \"Selected NBD: $NBD\"
echo \"Selected NBD: $NBD\" >&2
# Settle and probe partitions
udevadm settle >/dev/null 2>&1 || true
@@ -234,7 +234,7 @@ else
exit 33
fi
echo \"ROOT_DEV=$ROOT_DEV BOOT_DEV=$BOOT_DEV\"
echo \"ROOT_DEV=$ROOT_DEV BOOT_DEV=$BOOT_DEV\" >&2
if [ ! -b \"$ROOT_DEV\" ]; then
echo \"Root partition not found: $ROOT_DEV\" >&2
@@ -357,8 +357,10 @@ fi
rm -f \"$RAW\"
qemu-img convert -U -f qcow2 -O raw \"$WORK\" \"$RAW\"
# Output result triple
echo \"$RAW|$ROOT_UUID|$BOOT_UUID\"
# Output result triple ONLY on stdout, then prevent any further trap output
echo \"RESULT:$RAW|$ROOT_UUID|$BOOT_UUID\"
trap - EXIT
exit 0
",
src = shell_escape(&src),
vm_dir = shell_escape(&vm_dir),
@@ -374,8 +376,30 @@ echo \"$RAW|$ROOT_UUID|$BOOT_UUID\"
);
let res = run_script(&script)?;
let line = res.stdout.trim().lines().last().unwrap_or("").trim().to_string();
let parts: Vec<_> = line.split('|').map(|s| s.to_string()).collect();
// Prefer a RESULT:-prefixed line (robust against extra stdout noise)
let mut marker: Option<String> = None;
for l in res.stdout.lines().rev() {
let lt = l.trim();
if let Some(rest) = lt.strip_prefix("RESULT:") {
marker = Some(rest.trim().to_string());
break;
}
}
// Fallback: last line that looks like A|B|C
let line = if let Some(x) = marker {
x
} else {
let mut cand: Option<String> = None;
for l in res.stdout.lines().rev() {
let lt = l.trim();
if lt.split('|').count() == 3 {
cand = Some(lt.to_string());
break;
}
}
cand.ok_or_else(|| fail("no RAW|ROOT_UUID|BOOT_UUID line found in script output"))?
};
let parts: Vec<_> = line.split('|').map(|s| s.trim().to_string()).collect();
if parts.len() != 3 {
return Err(fail(&format!(
"unexpected output from image_prepare script, expected RAW|ROOT_UUID|BOOT_UUID, got: {}",