Blame SOURCES/0028-v2v-Replace-broken-VMware-Tools-uninstall-command-ms.patch

62f9b7
From 2bf5fc815d53e581398e787ae96444c438945ab3 Mon Sep 17 00:00:00 2001
62f9b7
From: "Richard W.M. Jones" <rjones@redhat.com>
62f9b7
Date: Tue, 19 Jan 2021 12:17:49 +0000
62f9b7
Subject: [PATCH] v2v: Replace broken VMware Tools uninstall command msiexec /i
62f9b7
 with /x.
62f9b7
62f9b7
Fixes: https://bugzilla.redhat.com/1917760
62f9b7
Thanks: Chetan Nagarkar
62f9b7
(cherry picked from commit f7496b0a7e76a06bda8d7ec1aba36741f8cb295c)
62f9b7
---
62f9b7
 v2v/convert_windows.ml | 15 ++++++++++++---
62f9b7
 1 file changed, 12 insertions(+), 3 deletions(-)
62f9b7
62f9b7
diff --git a/v2v/convert_windows.ml b/v2v/convert_windows.ml
62f9b7
index 84db742f..44cef5ed 100644
62f9b7
--- a/v2v/convert_windows.ml
62f9b7
+++ b/v2v/convert_windows.ml
62f9b7
@@ -135,7 +135,7 @@ let convert (g : G.guestfs) inspect _ output rcaps static_ips =
62f9b7
   (* Locate and retrieve all the uninstallation commands for installed
62f9b7
    * applications.
62f9b7
    *)
62f9b7
-  let uninstallation_commands pretty_name matchfn extra_uninstall_params =
62f9b7
+  let uninstallation_commands pretty_name matchfn modfn extra_uninstall_params =
62f9b7
     let path = ["Microsoft"; "Windows"; "CurrentVersion"; "Uninstall"] in
62f9b7
     let uninstval = "UninstallString" in
62f9b7
     let ret = ref [] in
62f9b7
@@ -155,6 +155,7 @@ let convert (g : G.guestfs) inspect _ output rcaps static_ips =
62f9b7
                    let valueh = g#hivex_node_get_value uninstnode uninstval in
62f9b7
                    if valueh <> 0L then (
62f9b7
                      let reg_cmd = g#hivex_value_string valueh in
62f9b7
+                     let reg_cmd = modfn reg_cmd in
62f9b7
                      let cmd =
62f9b7
                        sprintf "%s /quiet /norestart /l*v+ \"%%~dpn0.log\" REBOOT=ReallySuppress REMOVE=ALL %s"
62f9b7
                          reg_cmd extra_uninstall_params in
62f9b7
@@ -183,14 +184,22 @@ let convert (g : G.guestfs) inspect _ output rcaps static_ips =
62f9b7
      *)
62f9b7
     let extra_uninstall_params =
62f9b7
       "PREVENT_REBOOT=Yes LAUNCHED_BY_SETUP_EXE=Yes" in
62f9b7
-    uninstallation_commands "Parallels Tools" matchfn extra_uninstall_params in
62f9b7
+    uninstallation_commands "Parallels Tools" matchfn identity
62f9b7
+      extra_uninstall_params in
62f9b7
 
62f9b7
   (* Locate and retrieve all uninstallation commands for VMware Tools. *)
62f9b7
   let vmwaretools_uninst =
62f9b7
     let matchfn s =
62f9b7
       String.find s "VMware Tools" != -1
62f9b7
     in
62f9b7
-    uninstallation_commands "VMware Tools" matchfn "" in
62f9b7
+    (* VMware Tools writes the install command (MsiExec /I) into the
62f9b7
+     * UninstallString key in the registry, rather than the uninstall
62f9b7
+     * command.  Try to spot this and rewrite.  (RHBZ#1917760).
62f9b7
+     *)
62f9b7
+    let re1 = PCRE.compile ~caseless:true "msiexec" in
62f9b7
+    let re2 = PCRE.compile ~caseless:true "/i" in
62f9b7
+    let msifn s = if PCRE.matches re1 s then PCRE.replace re2 "/x" s else s in
62f9b7
+    uninstallation_commands "VMware Tools" matchfn msifn "" in
62f9b7
 
62f9b7
   (*----------------------------------------------------------------------*)
62f9b7
   (* Perform the conversion of the Windows guest. *)
62f9b7
-- 
0602f3
2.31.1
62f9b7