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

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