Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions crates/muvm/src/bin/muvm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ fn main() -> Result<ExitCode> {
emulator: options.emulator,
cwd,
init_commands,
user_init_commands: options.user_init_commands,
};
let mut muvm_config_file = NamedTempFile::new()
.context("Failed to create a temporary file to store the muvm guest config")?;
Expand Down
12 changes: 11 additions & 1 deletion crates/muvm/src/cli_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ pub struct Options {
pub publish_ports: Vec<String>,
pub emulator: Option<Emulator>,
pub init_commands: Vec<PathBuf>,
pub user_init_commands: Vec<PathBuf>,
pub command: PathBuf,
pub command_args: Vec<String>,
}
Expand Down Expand Up @@ -136,12 +137,20 @@ pub fn options() -> OptionParser<Options> {
let init_commands = long("execute-pre")
.short('x')
.help(
"Command to run inside the VM before guest server starts.
"Command to run inside the VM before guest server starts, while still running as root.
Can be used for e.g. setting up additional mounts.
Can be specified multiple times.",
)
.argument("COMMAND")
.many();
let user_init_commands = long("user-execute-pre")
.short('X')
.help(
"Command to run inside the VM before guest server starts, but after the user is set up.
Can be specified multiple times.",
)
.argument("COMMAND")
.many();
let command = positional("COMMAND").help("the command you want to execute in the vm");
let command_args = any::<String, _, _>("COMMAND_ARGS", |arg| {
(!["--help", "-h"].contains(&&*arg)).then_some(arg)
Expand All @@ -163,6 +172,7 @@ pub fn options() -> OptionParser<Options> {
publish_ports,
emulator,
init_commands,
user_init_commands,
// positionals
command,
command_args,
Expand Down
10 changes: 10 additions & 0 deletions crates/muvm/src/guest/bin/muvm-guest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,16 @@ fn main() -> Result<()> {
Err(err) => return Err(err).context("Failed to set up user, bailing out"),
};

for init_command in options.user_init_commands {
let code = Command::new(&init_command)
.current_dir(&options.cwd)
.spawn()?
.wait()?;
if !code.success() {
return Err(anyhow!("Executing `{}` failed", init_command.display()));
}
}

let pulse_path = run_path.join("pulse");
std::fs::create_dir(&pulse_path)
.context("Failed to create `pulse` directory in `XDG_RUNTIME_DIR`")?;
Expand Down
1 change: 1 addition & 0 deletions crates/muvm/src/utils/launch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ pub struct GuestConfiguration {
pub emulator: Option<Emulator>,
pub cwd: PathBuf,
pub init_commands: Vec<PathBuf>,
pub user_init_commands: Vec<PathBuf>,
}

pub const PULSE_SOCKET: u32 = 3333;
Expand Down
Loading