mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0032-v2v-windows-Add-a-helper-function-for-installing-Pow.patch

46b2f6
From bb09f8b1ab0fc3bda654e7d564d5010f9f24f660 Mon Sep 17 00:00:00 2001
46b2f6
From: "Richard W.M. Jones" <rjones@redhat.com>
46b2f6
Date: Tue, 4 Dec 2018 16:09:42 +0000
46b2f6
Subject: [PATCH] v2v: windows: Add a helper function for installing Powershell
46b2f6
 firstboot scripts.
46b2f6
46b2f6
(cherry picked from commit e1e9b3845e76a4bb406d16b96283ac38677cd91f)
46b2f6
---
46b2f6
 v2v/Makefile.am |  1 +
46b2f6
 v2v/windows.ml  | 23 +++++++++++++++++++++++
46b2f6
 v2v/windows.mli |  6 ++++++
46b2f6
 3 files changed, 30 insertions(+)
46b2f6
46b2f6
diff --git a/v2v/Makefile.am b/v2v/Makefile.am
46b2f6
index 30f040d3e..6568c9a6b 100644
46b2f6
--- a/v2v/Makefile.am
46b2f6
+++ b/v2v/Makefile.am
46b2f6
@@ -667,6 +667,7 @@ check_PROGRAMS += v2v_unit_tests var_expander_tests
46b2f6
 endif
46b2f6
 
46b2f6
 v2v_unit_tests_BOBJECTS = \
46b2f6
+	$(top_builddir)/customize/firstboot.cmo \
46b2f6
 	types.cmo \
46b2f6
 	uefi.cmo \
46b2f6
 	utils.cmo \
46b2f6
diff --git a/v2v/windows.ml b/v2v/windows.ml
46b2f6
index 23d589b00..d83f77b7f 100644
46b2f6
--- a/v2v/windows.ml
46b2f6
+++ b/v2v/windows.ml
46b2f6
@@ -45,3 +45,26 @@ and check_app { Guestfs.app2_name = name;
46b2f6
   publisher =~ rex_avg_tech
46b2f6
 
46b2f6
 and (=~) str rex = PCRE.matches rex str
46b2f6
+
46b2f6
+(* Unfortunately Powershell scripts cannot be directly executed
46b2f6
+ * (unless some system config changes are made which for other
46b2f6
+ * reasons we don't want to do) and so we have to run this via
46b2f6
+ * a regular batch file.
46b2f6
+ *)
46b2f6
+let install_firstboot_powershell g { Types.i_windows_systemroot; i_root }
46b2f6
+                                 filename code =
46b2f6
+  let tempdir = sprintf "%s/Temp" i_windows_systemroot in
46b2f6
+  g#mkdir_p tempdir;
46b2f6
+  let code = String.concat "\r\n" code ^ "\r\n" in
46b2f6
+  g#write (sprintf "%s/%s" tempdir filename) code;
46b2f6
+
46b2f6
+  (* Powershell interpreter.  Should we check this exists? XXX *)
46b2f6
+  let ps_exe =
46b2f6
+    i_windows_systemroot ^
46b2f6
+    "\\System32\\WindowsPowerShell\\v1.0\\powershell.exe" in
46b2f6
+
46b2f6
+  (* Windows path to the Powershell script. *)
46b2f6
+  let ps_path = i_windows_systemroot ^ "\\Temp\\" ^ filename in
46b2f6
+
46b2f6
+  let fb = sprintf "%s -ExecutionPolicy ByPass -file %s" ps_exe ps_path in
46b2f6
+  Firstboot.add_firstboot_script g i_root filename fb
46b2f6
diff --git a/v2v/windows.mli b/v2v/windows.mli
46b2f6
index 016ef2a78..6db7874b0 100644
46b2f6
--- a/v2v/windows.mli
46b2f6
+++ b/v2v/windows.mli
46b2f6
@@ -21,3 +21,9 @@
46b2f6
 val detect_antivirus : Types.inspect -> bool
46b2f6
 (** Return [true] if anti-virus (AV) software was detected in
46b2f6
     this Windows guest. *)
46b2f6
+
46b2f6
+val install_firstboot_powershell : Guestfs.guestfs -> Types.inspect ->
46b2f6
+                                   string -> string list -> unit
46b2f6
+(** [install_powershell_firstboot g inspect filename code] installs a
46b2f6
+    Powershell script (the lines of code) as a firstboot script in
46b2f6
+    the Windows VM. *)
46b2f6
-- 
46b2f6
2.24.1
46b2f6