|
|
d60042 |
From 63d711246f7e86c838c4471bec538a40abffbfb8 Mon Sep 17 00:00:00 2001
|
|
|
d60042 |
From: Pino Toscano <ptoscano@redhat.com>
|
|
|
d60042 |
Date: Mon, 4 May 2020 11:55:41 +0200
|
|
|
d60042 |
Subject: [PATCH] customize: port do_run to run_in_guest_command
|
|
|
d60042 |
|
|
|
d60042 |
Make use of the new helper function in Tools_utils to run commands in
|
|
|
d60042 |
the guest.
|
|
|
d60042 |
|
|
|
d60042 |
(cherry picked from commit b25e3495f522378f59d201526d7d2d02c2bf6f3f)
|
|
|
d60042 |
---
|
|
|
d60042 |
customize/customize_run.ml | 48 ++++++--------------------------------
|
|
|
d60042 |
1 file changed, 7 insertions(+), 41 deletions(-)
|
|
|
d60042 |
|
|
|
d60042 |
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
|
|
|
d60042 |
index 3eacdaca0..f2ee20413 100644
|
|
|
d60042 |
--- a/customize/customize_run.ml
|
|
|
d60042 |
+++ b/customize/customize_run.ml
|
|
|
d60042 |
@@ -30,12 +30,6 @@ open Append_line
|
|
|
d60042 |
module G = Guestfs
|
|
|
d60042 |
|
|
|
d60042 |
let run (g : G.guestfs) root (ops : ops) =
|
|
|
d60042 |
- (* Is the host_cpu compatible with the guest arch? ie. Can we
|
|
|
d60042 |
- * run commands in this guest?
|
|
|
d60042 |
- *)
|
|
|
d60042 |
- let guest_arch = g#inspect_get_arch root in
|
|
|
d60042 |
- let guest_arch_compatible = guest_arch_compatible guest_arch in
|
|
|
d60042 |
-
|
|
|
d60042 |
(* Based on the guest type, choose a log file location. *)
|
|
|
d60042 |
let logfile =
|
|
|
d60042 |
match g#inspect_get_type root with
|
|
|
d60042 |
@@ -54,42 +48,14 @@ let run (g : G.guestfs) root (ops : ops) =
|
|
|
d60042 |
|
|
|
d60042 |
(* Useful wrapper for scripts. *)
|
|
|
d60042 |
let do_run ~display ?(warn_failed_no_network = false) cmd =
|
|
|
d60042 |
- if not guest_arch_compatible then
|
|
|
d60042 |
+ let incompatible_fn () =
|
|
|
d60042 |
+ let guest_arch = g#inspect_get_arch root in
|
|
|
d60042 |
error (f_"host cpu (%s) and guest arch (%s) are not compatible, so you cannot use command line options that involve running commands in the guest. Use --firstboot scripts instead.")
|
|
|
d60042 |
- Guestfs_config.host_cpu guest_arch;
|
|
|
d60042 |
-
|
|
|
d60042 |
- (* Add a prologue to the scripts:
|
|
|
d60042 |
- * - Pass environment variables through from the host.
|
|
|
d60042 |
- * - Send stdout and stderr to a log file so we capture all output
|
|
|
d60042 |
- * in error messages.
|
|
|
d60042 |
- * - Use setarch when running x86_64 host + i686 guest.
|
|
|
d60042 |
- * Also catch errors and dump the log file completely on error.
|
|
|
d60042 |
- *)
|
|
|
d60042 |
- let env_vars =
|
|
|
d60042 |
- List.filter_map (
|
|
|
d60042 |
- fun name ->
|
|
|
d60042 |
- try Some (sprintf "export %s=%s" name (quote (Sys.getenv name)))
|
|
|
d60042 |
- with Not_found -> None
|
|
|
d60042 |
- ) [ "http_proxy"; "https_proxy"; "ftp_proxy"; "no_proxy" ] in
|
|
|
d60042 |
- let env_vars = String.concat "\n" env_vars ^ "\n" in
|
|
|
d60042 |
-
|
|
|
d60042 |
- let cmd =
|
|
|
d60042 |
- match Guestfs_config.host_cpu, guest_arch with
|
|
|
d60042 |
- | "x86_64", ("i386"|"i486"|"i586"|"i686") ->
|
|
|
d60042 |
- sprintf "setarch i686 <<\"__EOCMD\"
|
|
|
d60042 |
-%s
|
|
|
d60042 |
-__EOCMD
|
|
|
d60042 |
-" cmd
|
|
|
d60042 |
- | _ -> cmd in
|
|
|
d60042 |
-
|
|
|
d60042 |
- let cmd = sprintf "\
|
|
|
d60042 |
-exec >>%s 2>&1
|
|
|
d60042 |
-%s
|
|
|
d60042 |
-%s
|
|
|
d60042 |
-" (quote logfile) env_vars cmd in
|
|
|
d60042 |
-
|
|
|
d60042 |
- debug "running command:\n%s" cmd;
|
|
|
d60042 |
- try ignore (g#sh cmd)
|
|
|
d60042 |
+ Guestfs_config.host_cpu guest_arch
|
|
|
d60042 |
+ in
|
|
|
d60042 |
+
|
|
|
d60042 |
+ try
|
|
|
d60042 |
+ run_in_guest_command g root ~logfile ~incompatible_fn cmd
|
|
|
d60042 |
with
|
|
|
d60042 |
G.Error msg ->
|
|
|
d60042 |
debug_logfile ();
|
|
|
d60042 |
--
|
|
|
b155d0 |
2.26.2
|
|
|
d60042 |
|