[Libguestfs] [PATCH] customize: Add --uninstall operation.

Richard W.M. Jones rjones at redhat.com
Tue Jun 7 11:20:35 UTC 2016


On Tue, Jun 07, 2016 at 10:29:01AM +0100, Richard W.M. Jones wrote:
> ---
>  customize/customize_run.ml | 30 ++++++++++++++++++++++++++++++
>  generator/customize.ml     | 17 +++++++++++++++--
>  2 files changed, 45 insertions(+), 2 deletions(-)
> 
> diff --git a/customize/customize_run.ml b/customize/customize_run.ml
> index c9d9d7d..b2506d1 100644
> --- a/customize/customize_run.ml
> +++ b/customize/customize_run.ml
> @@ -151,6 +151,31 @@ exec >>%s 2>&1
>      | pm ->
>        error_unimplemented_package_manager (s_"--update") pm
>  
> +  and guest_uninstall_command packages =
> +    let quoted_args = String.concat " " (List.map quote packages) in
> +    match g#inspect_get_package_management root with
> +    | "apk" -> sprintf "apk del %s" quoted_args
> +    | "apt" ->
> +      (* http://unix.stackexchange.com/questions/22820 *)
> +      sprintf "
> +        export DEBIAN_FRONTEND=noninteractive
> +        apt_opts='-q -y -o Dpkg::Options::=--force-confnew'

> +        apt-get $apt_opts update

I pushed this patch as it should be a simple feature request, but I
removed the above line which the bug requester has assured me is not
needed on Debian when removing packages.

Rich.

> +        apt-get $apt_opts remove %s
> +      " quoted_args
> +    | "dnf" ->    sprintf "dnf -y remove %s" quoted_args
> +    | "pisi" ->   sprintf "pisi rm %s" quoted_args
> +    | "pacman" -> sprintf "pacman -R %s" quoted_args
> +    | "urpmi" ->  sprintf "urpme %s" quoted_args
> +    | "xbps" ->   sprintf "xbps-remove -Sy %s" quoted_args
> +    | "yum" ->    sprintf "yum -y remove %s" quoted_args
> +    | "zypper" -> sprintf "zypper -n rm -l %s" quoted_args
> +
> +    | "unknown" ->
> +      error_unknown_package_manager (s_"--uninstall")
> +    | pm ->
> +      error_unimplemented_package_manager (s_"--uninstall") pm
> +
>    (* Windows has package_management == "unknown". *)
>    and error_unknown_package_manager flag =
>      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
> @@ -330,6 +355,11 @@ exec >>%s 2>&1
>        message (f_"Running touch: %s") path;
>        g#touch path
>  
> +    | `UninstallPackages pkgs ->
> +      message (f_"Uninstalling packages: %s") (String.concat " " pkgs);
> +      let cmd = guest_uninstall_command pkgs in
> +      do_run ~display:cmd cmd
> +
>      | `Update ->
>        message (f_"Updating packages");
>        let cmd = guest_update_command () in
> diff --git a/generator/customize.ml b/generator/customize.ml
> index 3d3f978..496077b 100644
> --- a/generator/customize.ml
> +++ b/generator/customize.ml
> @@ -214,7 +214,7 @@ installed during the image build using the guest's package manager
>  For an overview on the different ways to install packages, see
>  L<virt-builder(1)/INSTALLING PACKAGES>.
>  
> -See also I<--update>.";
> +See also I<--update>, I<--uninstall>.";
>    };
>  
>    { op_name = "link";
> @@ -424,6 +424,19 @@ string like C<Europe/London>";
>  This command performs a L<touch(1)>-like operation on C<FILE>.";
>    };
>  
> +  { op_name = "uninstall";
> +    op_type = StringList "PKG,PKG..";
> +    op_discrim = "`UninstallPackages";
> +    op_shortdesc = "Uninstall package(s)";
> +    op_pod_longdesc = "\
> +Uninstall the named packages (a comma-separated list).  These are
> +removed during the image build using the guest's package manager
> +(eg. apt, yum, etc.).  Dependent packages may also need to be
> +uninstalled to satisfy the request.
> +
> +See also I<--install>, I<--update>.";
> +  };
> +
>    { op_name = "update";
>      op_type = Unit;
>      op_discrim = "`Update";
> @@ -433,7 +446,7 @@ Do the equivalent of C<yum update>, C<apt-get upgrade>, or whatever
>  command is required to update the packages already installed in the
>  template to their latest versions.
>  
> -See also I<--install>.";
> +See also I<--install>, I<--uninstall>.";
>    };
>  
>    { op_name = "upload";
> -- 
> 2.7.4
> 
> _______________________________________________
> Libguestfs mailing list
> Libguestfs at redhat.com
> https://www.redhat.com/mailman/listinfo/libguestfs

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-top is 'top' for virtual machines.  Tiny program with many
powerful monitoring features, net stats, disk stats, logging, etc.
http://people.redhat.com/~rjones/virt-top




More information about the Libguestfs mailing list