feat: detect shell for --kernel
- Move detect_shell() to new src/utils.rs for reuse - Use detected shell in QEMU VM mode (bash when available) - Update chroot.rs and qemu_vm.rs to use shared function
This commit is contained in:
+7
-4
@@ -54,6 +54,9 @@ pub fn launch_qemu(config: QemuConfig) -> Result<()> {
|
||||
qemu_bin, get_arch_package_suffix(&config.arch), get_arch_package_suffix(&config.arch), get_arch_package_suffix(&config.arch)
|
||||
))?;
|
||||
|
||||
// Detect the best available shell in the rootfs
|
||||
let shell = crate::utils::detect_shell(&config.rootfs_path);
|
||||
|
||||
// Generate a unique hostname like "ecr-vm-a1b2c3"
|
||||
let hostname_suffix = format!("{:x}", (std::process::id() as u64)
|
||||
.wrapping_mul(std::time::SystemTime::now()
|
||||
@@ -72,14 +75,14 @@ pub fn launch_qemu(config: QemuConfig) -> Result<()> {
|
||||
let kernel_append = if let Some(ref cmd) = config.command {
|
||||
let cmd_str = cmd.join(" ");
|
||||
format!(
|
||||
"console=ttyS0 quiet rdinit=/bin/sh -- -c \"echo {} >/etc/hostname; hostname {}; setsid sh -c 'exec sh </dev/ttyS0 >/dev/ttyS0 2>&1 -c {}'\"",
|
||||
hostname, hostname, cmd_str
|
||||
"console=ttyS0 quiet rdinit=/bin/sh -- -c \"echo {} >/etc/hostname; hostname {}; setsid sh -c 'exec {} </dev/ttyS0 >/dev/ttyS0 2>&1 -c {}'\"",
|
||||
hostname, hostname, shell, cmd_str
|
||||
)
|
||||
} else {
|
||||
// Default to interactive shell with proper job control
|
||||
format!(
|
||||
"console=ttyS0 quiet rdinit=/bin/sh -- -c \"echo {} >/etc/hostname; hostname {}; setsid sh -c 'exec sh </dev/ttyS0 >/dev/ttyS0 2>&1'\"",
|
||||
hostname, hostname
|
||||
"console=ttyS0 quiet rdinit=/bin/sh -- -c \"echo {} >/etc/hostname; hostname {}; setsid sh -c 'exec {} </dev/ttyS0 >/dev/ttyS0 2>&1'\"",
|
||||
hostname, hostname, shell
|
||||
)
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user