mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

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

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