working version 1
This commit is contained in:
@@ -204,7 +204,7 @@ if [ -z \"$NBD\" ]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo \"Selected NBD: $NBD\"
|
echo \"Selected NBD: $NBD\" >&2
|
||||||
|
|
||||||
# Settle and probe partitions
|
# Settle and probe partitions
|
||||||
udevadm settle >/dev/null 2>&1 || true
|
udevadm settle >/dev/null 2>&1 || true
|
||||||
@@ -234,7 +234,7 @@ else
|
|||||||
exit 33
|
exit 33
|
||||||
fi
|
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
|
if [ ! -b \"$ROOT_DEV\" ]; then
|
||||||
echo \"Root partition not found: $ROOT_DEV\" >&2
|
echo \"Root partition not found: $ROOT_DEV\" >&2
|
||||||
@@ -357,8 +357,10 @@ fi
|
|||||||
rm -f \"$RAW\"
|
rm -f \"$RAW\"
|
||||||
qemu-img convert -U -f qcow2 -O raw \"$WORK\" \"$RAW\"
|
qemu-img convert -U -f qcow2 -O raw \"$WORK\" \"$RAW\"
|
||||||
|
|
||||||
# Output result triple
|
# Output result triple ONLY on stdout, then prevent any further trap output
|
||||||
echo \"$RAW|$ROOT_UUID|$BOOT_UUID\"
|
echo \"RESULT:$RAW|$ROOT_UUID|$BOOT_UUID\"
|
||||||
|
trap - EXIT
|
||||||
|
exit 0
|
||||||
",
|
",
|
||||||
src = shell_escape(&src),
|
src = shell_escape(&src),
|
||||||
vm_dir = shell_escape(&vm_dir),
|
vm_dir = shell_escape(&vm_dir),
|
||||||
@@ -374,8 +376,30 @@ echo \"$RAW|$ROOT_UUID|$BOOT_UUID\"
|
|||||||
);
|
);
|
||||||
|
|
||||||
let res = run_script(&script)?;
|
let res = run_script(&script)?;
|
||||||
let line = res.stdout.trim().lines().last().unwrap_or("").trim().to_string();
|
// Prefer a RESULT:-prefixed line (robust against extra stdout noise)
|
||||||
let parts: Vec<_> = line.split('|').map(|s| s.to_string()).collect();
|
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 {
|
if parts.len() != 3 {
|
||||||
return Err(fail(&format!(
|
return Err(fail(&format!(
|
||||||
"unexpected output from image_prepare script, expected RAW|ROOT_UUID|BOOT_UUID, got: {}",
|
"unexpected output from image_prepare script, expected RAW|ROOT_UUID|BOOT_UUID, got: {}",
|
||||||
|
Reference in New Issue
Block a user