mrc0mmand / rpms / libguestfs

Forked from rpms/libguestfs 3 years ago
Clone

Blame SOURCES/0104-customize-Add-uninstall-operation-RHBZ-1343375.patch

e76f14
From a99e410a2dc450569bc3218005fbc38e60e2d4af Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Tue, 7 Jun 2016 10:24:54 +0100
e76f14
Subject: [PATCH] customize: Add --uninstall operation (RHBZ#1343375).
e76f14
e76f14
(cherry picked from commit 6425a8824b13a60ddf5d04270808da00568b1b53)
e76f14
---
e76f14
 customize/customize_run.ml | 29 +++++++++++++++++++++++++++++
e76f14
 generator/customize.ml     | 17 +++++++++++++++--
e76f14
 2 files changed, 44 insertions(+), 2 deletions(-)
e76f14
e76f14
diff --git a/customize/customize_run.ml b/customize/customize_run.ml
e76f14
index 8c38d62..10647fd 100644
e76f14
--- a/customize/customize_run.ml
e76f14
+++ b/customize/customize_run.ml
e76f14
@@ -154,6 +154,30 @@ exec >>%s 2>&1
e76f14
     | pm ->
e76f14
       error_unimplemented_package_manager (s_"--update") pm
e76f14
 
e76f14
+  and guest_uninstall_command packages =
e76f14
+    let quoted_args = String.concat " " (List.map quote packages) in
e76f14
+    match g#inspect_get_package_management root with
e76f14
+    | "apk" -> sprintf "apk del %s" quoted_args
e76f14
+    | "apt" ->
e76f14
+      (* http://unix.stackexchange.com/questions/22820 *)
e76f14
+      sprintf "
e76f14
+        export DEBIAN_FRONTEND=noninteractive
e76f14
+        apt_opts='-q -y -o Dpkg::Options::=--force-confnew'
e76f14
+        apt-get $apt_opts remove %s
e76f14
+      " quoted_args
e76f14
+    | "dnf" ->    sprintf "dnf -y remove %s" quoted_args
e76f14
+    | "pisi" ->   sprintf "pisi rm %s" quoted_args
e76f14
+    | "pacman" -> sprintf "pacman -R %s" quoted_args
e76f14
+    | "urpmi" ->  sprintf "urpme %s" quoted_args
e76f14
+    | "xbps" ->   sprintf "xbps-remove -Sy %s" quoted_args
e76f14
+    | "yum" ->    sprintf "yum -y remove %s" quoted_args
e76f14
+    | "zypper" -> sprintf "zypper -n rm -l %s" quoted_args
e76f14
+
e76f14
+    | "unknown" ->
e76f14
+      error_unknown_package_manager (s_"--uninstall")
e76f14
+    | pm ->
e76f14
+      error_unimplemented_package_manager (s_"--uninstall") pm
e76f14
+
e76f14
   (* Windows has package_management == "unknown". *)
e76f14
   and error_unknown_package_manager flag =
e76f14
     error (f_"cannot use '%s' because no package manager has been detected for this guest OS.\n\nIf this guest OS is a common one with ordinary package management then this may have been caused by a failure of libguestfs inspection.\n\nFor OSes such as Windows that lack package management, this is not possible.  Try using one of the '--firstboot*' flags instead (described in the manual).") flag
e76f14
@@ -334,6 +358,11 @@ exec >>%s 2>&1
e76f14
       message (f_"Running touch: %s") path;
e76f14
       g#touch path
e76f14
 
e76f14
+    | `UninstallPackages pkgs ->
e76f14
+      message (f_"Uninstalling packages: %s") (String.concat " " pkgs);
e76f14
+      let cmd = guest_uninstall_command pkgs in
e76f14
+      do_run ~display:cmd cmd
e76f14
+
e76f14
     | `Update ->
e76f14
       message (f_"Updating packages");
e76f14
       let cmd = guest_update_command () in
e76f14
diff --git a/generator/customize.ml b/generator/customize.ml
e76f14
index 403bb89..8caf2b5 100644
e76f14
--- a/generator/customize.ml
e76f14
+++ b/generator/customize.ml
e76f14
@@ -214,7 +214,7 @@ installed during the image build using the guest's package manager
e76f14
 For an overview on the different ways to install packages, see
e76f14
 L<virt-builder(1)/INSTALLING PACKAGES>.
e76f14
 
e76f14
-See also I<--update>.";
e76f14
+See also I<--update>, I<--uninstall>.";
e76f14
   };
e76f14
 
e76f14
   { op_name = "link";
e76f14
@@ -424,6 +424,19 @@ string like C<Europe/London>";
e76f14
 This command performs a L<touch(1)>-like operation on C<FILE>.";
e76f14
   };
e76f14
 
e76f14
+  { op_name = "uninstall";
e76f14
+    op_type = StringList "PKG,PKG..";
e76f14
+    op_discrim = "`UninstallPackages";
e76f14
+    op_shortdesc = "Uninstall package(s)";
e76f14
+    op_pod_longdesc = "\
e76f14
+Uninstall the named packages (a comma-separated list).  These are
e76f14
+removed during the image build using the guest's package manager
e76f14
+(eg. apt, yum, etc.).  Dependent packages may also need to be
e76f14
+uninstalled to satisfy the request.
e76f14
+
e76f14
+See also I<--install>, I<--update>.";
e76f14
+  };
e76f14
+
e76f14
   { op_name = "update";
e76f14
     op_type = Unit;
e76f14
     op_discrim = "`Update";
e76f14
@@ -433,7 +446,7 @@ Do the equivalent of C<yum update>, C<apt-get upgrade>, or whatever
e76f14
 command is required to update the packages already installed in the
e76f14
 template to their latest versions.
e76f14
 
e76f14
-See also I<--install>.";
e76f14
+See also I<--install>, I<--uninstall>.";
e76f14
   };
e76f14
 
e76f14
   { op_name = "upload";
e76f14
-- 
aa0300
2.7.4
e76f14