File tree Expand file tree Collapse file tree 5 files changed +29
-3
lines changed Expand file tree Collapse file tree 5 files changed +29
-3
lines changed Original file line number Diff line number Diff line change 1313``` sh
1414Usage: muvm [-c= CPU_LIST]... [-e= ENV]... [--mem= MEM] [--vram= VRAM] [--passt-socket= PATH] [-f=
1515FEX_IMAGE]... [-m] [-i] [-t] [--privileged] [-p=< [[IP:][HOST_PORT]:]GUEST_PORT[/PROTOCOL]> ]... [
16- --emu= EMU] COMMAND [COMMAND_ARGS]...
16+ --emu= EMU] [-x = COMMAND]... COMMAND [COMMAND_ARGS]...
1717
1818Available positional items:
1919 COMMAND the command you want to execute in the vm
@@ -56,6 +56,8 @@ Available options:
5656 Valid options are "box" and "fex". If this argument is not
5757 present, muvm will try to use FEX, falling back to Box if it
5858 can' t be found.
59+ -x, --execute-pre=COMMAND Command to run inside the VM before guest server starts.
60+ Can be used for e.g. setting up additional mounts. Can be specified many times
5961 -h, --help Prints help information
6062```
6163
Original file line number Diff line number Diff line change @@ -389,6 +389,7 @@ fn main() -> Result<ExitCode> {
389389 host_display : display,
390390 merged_rootfs : options. merged_rootfs ,
391391 emulator : options. emulator ,
392+ init_commands : options. init_commands ,
392393 } ;
393394 let mut muvm_config_file = NamedTempFile :: new ( )
394395 . context ( "Failed to create a temporary file to store the muvm guest config" ) ?;
Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ pub struct Options {
2121 pub privileged : bool ,
2222 pub publish_ports : Vec < String > ,
2323 pub emulator : Option < Emulator > ,
24+ pub init_commands : Vec < PathBuf > ,
2425 pub command : PathBuf ,
2526 pub command_args : Vec < String > ,
2627}
@@ -132,6 +133,14 @@ pub fn options() -> OptionParser<Options> {
132133 )
133134 . argument :: < String > ( "[[IP:][HOST_PORT]:]GUEST_PORT[/PROTOCOL]" )
134135 . many ( ) ;
136+ let init_commands = long ( "execute-pre" )
137+ . short ( 'x' )
138+ . help (
139+ "Command to run inside the VM before guest server starts.
140+ Can be used for e.g. setting up additional mounts. Can be specified many times" ,
141+ )
142+ . argument ( "COMMAND" )
143+ . many ( ) ;
135144 let command = positional ( "COMMAND" ) . help ( "the command you want to execute in the vm" ) ;
136145 let command_args = any :: < String , _ , _ > ( "COMMAND_ARGS" , |arg| {
137146 ( ![ "--help" , "-h" ] . contains ( & & * arg) ) . then_some ( arg)
@@ -152,6 +161,7 @@ pub fn options() -> OptionParser<Options> {
152161 privileged,
153162 publish_ports,
154163 emulator,
164+ init_commands,
155165 // positionals
156166 command,
157167 command_args,
Original file line number Diff line number Diff line change @@ -2,10 +2,10 @@ use std::fs::File;
22use std:: io:: Read ;
33use std:: os:: fd:: AsFd ;
44use std:: panic:: catch_unwind;
5- use std:: process:: Command ;
5+ use std:: process:: { Command , Stdio } ;
66use std:: { cmp, env, fs, thread} ;
77
8- use anyhow:: { Context , Result } ;
8+ use anyhow:: { anyhow , Context , Result } ;
99use muvm:: guest:: box64:: setup_box;
1010use muvm:: guest:: bridge:: pipewire:: start_pwbridge;
1111use muvm:: guest:: bridge:: x11:: start_x11bridge;
@@ -94,6 +94,18 @@ fn main() -> Result<()> {
9494 }
9595 }
9696
97+ for init_command in options. init_commands {
98+ let code = Command :: new ( & init_command)
99+ . stdin ( Stdio :: null ( ) )
100+ . stdout ( Stdio :: piped ( ) )
101+ . stderr ( Stdio :: piped ( ) )
102+ . spawn ( ) ?
103+ . wait ( ) ?;
104+ if !code. success ( ) {
105+ return Err ( anyhow ! ( "Executing `{}` failed" , init_command. display( ) ) ) ;
106+ }
107+ }
108+
97109 configure_network ( ) ?;
98110
99111 let run_path = match setup_user ( Uid :: from ( options. uid ) , Gid :: from ( options. gid ) ) {
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ pub struct GuestConfiguration {
4343 pub host_display : Option < String > ,
4444 pub merged_rootfs : bool ,
4545 pub emulator : Option < Emulator > ,
46+ pub init_commands : Vec < PathBuf > ,
4647}
4748
4849pub const PULSE_SOCKET : u32 = 3333 ;
You can’t perform that action at this time.
0 commit comments