SHA256
1
0
forked from pool/supermin

handle --use-installed in zypper

OBS-URL: https://build.opensuse.org/package/show/Virtualization/supermin?expand=0&rev=4
This commit is contained in:
Olaf Hering 2013-04-11 18:10:05 +00:00 committed by Git OBS Bridge
parent fbd0f39cbc
commit 1b5dfec97b
7 changed files with 292 additions and 14 deletions

View File

@ -1,7 +1,7 @@
From 9f60bbb8e486c410d76e1864a11d3990c2119787 Mon Sep 17 00:00:00 2001 From 9f60bbb8e486c410d76e1864a11d3990c2119787 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com> From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Tue, 5 Feb 2013 16:46:22 +0000 Date: Tue, 5 Feb 2013 16:46:22 +0000
Subject: [PATCH] Actually update gnulib. Subject: [PATCH 1/6] Actually update gnulib.
This fixes commit 4df7ff0786d872c9bb8a0a1b5410429ca1f8440b. This fixes commit 4df7ff0786d872c9bb8a0a1b5410429ca1f8440b.
--- ---

View File

@ -0,0 +1,62 @@
From 81a3470088aff911c4e5e729bf1f1b61480baab8 Mon Sep 17 00:00:00 2001
From: "Richard W.M. Jones" <rjones@redhat.com>
Date: Fri, 5 Apr 2013 17:14:52 +0100
Subject: [PATCH 2/6] helper: Add missing options to --help and man page
(RHBZ#948880).
---
helper/main.c | 4 ++--
helper/supermin-helper.pod | 16 ++++++++++++++++
2 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/helper/main.c b/helper/main.c
index 25a4d91..6948e93 100644
--- a/helper/main.c
+++ b/helper/main.c
@@ -83,10 +83,10 @@ usage (FILE *f, const char *progname)
" Specify output format (default: cpio).\n"
" --copy-kernel\n"
" Copy the kernel instead of symlinking to it.\n"
- " -u user\n"
+ " -u user | --user user\n"
" The user name or uid the appliance will run as. Use of this\n"
" option requires root privileges.\n"
- " -g group\n"
+ " -g group | --group group\n"
" The group name or gid the appliance will run as. Use of\n"
" this option requires root privileges.\n"
" -k file | --kmods file\n"
diff --git a/helper/supermin-helper.pod b/helper/supermin-helper.pod
index 10c5223..86d7a97 100644
--- a/helper/supermin-helper.pod
+++ b/helper/supermin-helper.pod
@@ -38,6 +38,10 @@ the checksum output C<-f checksum>.
=over 4
+=item B<--help>
+
+Display brief command line usage, and exit.
+
=item B<-f fmt>
=item B<--format fmt>
@@ -122,6 +126,18 @@ effective uid/gid to the real uid/gid when invoked. As
supermin-helper uses bash in parts, this will result in the creation
of an appliance with a mixture of ownerships.
+=item B<-v>
+
+=item B<--verbose>
+
+Enable verbose messages (give multiple times for more verbosity).
+
+=item B<-V>
+
+=item B<--version>
+
+Display version number and exit.
+
=back
=head1 SPEED

View File

@ -1,7 +1,7 @@
From e83608bd0b8ef62fcd950b2b848effa1e1b81d66 Mon Sep 17 00:00:00 2001 From 1ecd918f88065b55bcb411b54311d813ce54c2ad Mon Sep 17 00:00:00 2001
From: Olaf Hering <olaf@aepfle.de> From: Olaf Hering <olaf@aepfle.de>
Date: Tue, 9 Apr 2013 18:43:11 +0200 Date: Tue, 9 Apr 2013 19:27:01 +0200
Subject: [PATCH 1/2] add run_shell helper Subject: [PATCH 3/6] add run_shell helper
The new run_shell helper is a copy of run_python, The new run_shell helper is a copy of run_python,
and will be used by upcoming changes. and will be used by upcoming changes.

View File

@ -1,7 +1,7 @@
From fbc07fc688ea6a59a9d2ff34e28436933a38ec69 Mon Sep 17 00:00:00 2001 From 392eca634d68a01045475799a76b988e4589006c Mon Sep 17 00:00:00 2001
From: Olaf Hering <olaf@aepfle.de> From: Olaf Hering <olaf@aepfle.de>
Date: Tue, 9 Apr 2013 18:47:13 +0200 Date: Tue, 9 Apr 2013 19:27:02 +0200
Subject: [PATCH 2/2] add support for zypp Subject: [PATCH 4/6] add support for zypp
This adds support for zypper which is used as package management in This adds support for zypper which is used as package management in
SuSE Linux. It started out as copy of yum support. SuSE Linux. It started out as copy of yum support.
@ -12,10 +12,11 @@ TODO:
Signed-off-by: Olaf Hering <olaf@aepfle.de> Signed-off-by: Olaf Hering <olaf@aepfle.de>
--- ---
configure.ac | 1 + configure.ac | 1 +
src/.depend | 2 +
src/Makefile.am | 1 + src/Makefile.am | 1 +
src/config.ml.in | 1 + src/config.ml.in | 1 +
src/supermin_zypp_rpm.ml | 174 +++++++++++++++++++++++++++++++++++++++++++++++ src/supermin_zypp_rpm.ml | 174 +++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 177 insertions(+) 5 files changed, 179 insertions(+)
create mode 100644 src/supermin_zypp_rpm.ml create mode 100644 src/supermin_zypp_rpm.ml
diff --git a/configure.ac b/configure.ac diff --git a/configure.ac b/configure.ac
@ -30,6 +31,16 @@ index a22fcf3..f975f3f 100644
AC_CHECK_PROG(YUM,[yum],[yum],[no]) AC_CHECK_PROG(YUM,[yum],[yum],[no])
AC_CHECK_PROG(RPM,[rpm],[rpm],[no]) AC_CHECK_PROG(RPM,[rpm],[rpm],[no])
AC_CHECK_PROG(YUMDOWNLOADER,[yumdownloader],[yumdownloader],[no]) AC_CHECK_PROG(YUMDOWNLOADER,[yumdownloader],[yumdownloader],[no])
diff --git a/src/.depend b/src/.depend
index 624191e..36a642f 100644
--- a/src/.depend
+++ b/src/.depend
@@ -17,3 +17,5 @@ supermin_utils.cmo: supermin_cmdline.cmi supermin_utils.cmi
supermin_utils.cmx: supermin_cmdline.cmx supermin_utils.cmi
supermin_yum_rpm.cmo: supermin_utils.cmi supermin_package_handlers.cmi supermin_cmdline.cmi config.cmo
supermin_yum_rpm.cmx: supermin_utils.cmx supermin_package_handlers.cmx supermin_cmdline.cmx config.cmx
+supermin_zypp_rpm.cmo: supermin_utils.cmi supermin_package_handlers.cmi supermin_cmdline.cmi config.cmo
+supermin_zypp_rpm.cmx: supermin_utils.cmx supermin_package_handlers.cmx supermin_cmdline.cmx config.cmx
diff --git a/src/Makefile.am b/src/Makefile.am diff --git a/src/Makefile.am b/src/Makefile.am
index 6ff3d56..3b6ca9b 100644 index 6ff3d56..3b6ca9b 100644
--- a/src/Makefile.am --- a/src/Makefile.am
@ -56,7 +67,7 @@ index c281486..c3e7672 100644
let yumdownloader = "@YUMDOWNLOADER@" let yumdownloader = "@YUMDOWNLOADER@"
diff --git a/src/supermin_zypp_rpm.ml b/src/supermin_zypp_rpm.ml diff --git a/src/supermin_zypp_rpm.ml b/src/supermin_zypp_rpm.ml
new file mode 100644 new file mode 100644
index 0000000..e4555bf index 0000000..51f01eb
--- /dev/null --- /dev/null
+++ b/src/supermin_zypp_rpm.ml +++ b/src/supermin_zypp_rpm.ml
@@ -0,0 +1,174 @@ @@ -0,0 +1,174 @@

View File

@ -0,0 +1,42 @@
From 235933bb68a378cb48c5c740b97e5075975edf9a Mon Sep 17 00:00:00 2001
From: Olaf Hering <olaf@aepfle.de>
Date: Thu, 11 Apr 2013 16:36:40 +0200
Subject: [PATCH 5/6] always work with empty --root in zypp driver
The current mode of operation in the zypp driver is to download all
packages into a temporary pkg-cache-dir. Installed packages in the root
filesystem are ignored, otherwise zypper would download only a subset of
packages, and it would not provide a list of all required dependencies.
Remove the getuid check to force an empty root directory and use the
configured system repositories.
This works for root and non-root users.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
src/supermin_zypp_rpm.ml | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/supermin_zypp_rpm.ml b/src/supermin_zypp_rpm.ml
index 51f01eb..2089837 100644
--- a/src/supermin_zypp_rpm.ml
+++ b/src/supermin_zypp_rpm.ml
@@ -50,7 +50,7 @@ pkg_cache_dir=%S
time zypper \
%s \
%s \
- %s \
+ --root %S --reposd-dir /etc/zypp/repos.d \
--cache-dir \"${cache_dir}\" \
--pkg-cache-dir \"${pkg_cache_dir}\" \
--gpg-auto-import-keys \
@@ -65,7 +65,7 @@ time zypper \
(if verbose then "--verbose --verbose" else "--quiet")
(match packager_config with None -> ""
| Some filename -> sprintf "--config %s" filename)
- (if Unix.getuid() > 0 then sprintf "--root %S --reposd-dir /etc/zypp/repos.d" tmp_root else "")
+ tmp_root
in
run_shell sh names;

View File

@ -0,0 +1,155 @@
From 9750c2e6050d73276699090180dc2e43d87c9663 Mon Sep 17 00:00:00 2001
From: Olaf Hering <olaf@aepfle.de>
Date: Thu, 11 Apr 2013 19:07:11 +0200
Subject: [PATCH 6/6] handle --use-installed in zypp driver
An attempt to use installed files in zypp driver.
Add also a comment about the theory of operation.
Enable set -x in shell only in verbose mode.
This adds a dependency to xmlstarlet, which is required to parse zypper output.
Signed-off-by: Olaf Hering <olaf@aepfle.de>
---
src/supermin_zypp_rpm.ml | 93 +++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 80 insertions(+), 13 deletions(-)
diff --git a/src/supermin_zypp_rpm.ml b/src/supermin_zypp_rpm.ml
index 2089837..0f3b63a 100644
--- a/src/supermin_zypp_rpm.ml
+++ b/src/supermin_zypp_rpm.ml
@@ -18,6 +18,31 @@
(* Zypper and RPM support. *)
+(*
+ * Theory of operation:
+ * called as root:
+ * - without --use-installed:
+ * ->ph_resolve_dependencies_and_download() returns a list of filenames
+ * Need to download all packages into an empty --root directory so that
+ * zypper places all dependencies into --pkg-cache-dir
+ * - with --use-installed:
+ * ->ph_resolve_dependencies_and_download() returns a list of package names
+ * Need to work with an empty --root directory so that zypper can list
+ * all dependencies of "names". This mode assumes that all required packages
+ * are installed and the system is consistent. Downloading just the missing
+ * packages is not implemented.
+ * called as non-root:
+ * (Due to the usage of --root zypper does not require root permissions.)
+ * - without --use-installed:
+ * Same as above.
+ * - with --use-installed:
+ * Same as above.
+ *
+ * The usage of --packager-config is tricky: If --root is used zypper assumes
+ * that every config file is below <rootdir>. So the config has to be parsed
+ * and relevant files/dirs should be copied into <rootdir> so that zypper can
+ * use the specified config.
+ *)
open Unix
open Printf
@@ -34,15 +59,15 @@ let zypp_rpm_detect () =
Config.zypper <> "no" && Config.rpm <> "no"
let zypp_rpm_init () =
- if use_installed && Unix.getuid() > 0 then
- failwith "zypp_rpm driver doesn't support --use-installed when called as non-root user"
+ if use_installed then
+ eprintf "supermin: zypp_rpm driver assumes all packages are already installed when called with option --use-installed.\n%!"
-let zypp_rpm_resolve_dependencies_and_download names =
+let zypp_rpm_resolve_dependencies_and_download_no_installed names =
(* Liberate this data from shell. *)
let tmp_pkg_cache_dir = tmpdir // "pkg_cache_dir" in
let tmp_root = tmpdir // "root" in
let sh = sprintf "
-set -ex
+%s
unset LANG ${!LC_*}
tmpdir=%S
cache_dir=\"${tmpdir}/cache-dir\"
@@ -60,6 +85,7 @@ time zypper \
--download-only \
$@
"
+ (if verbose then "set -x" else "")
tmpdir
tmp_pkg_cache_dir
(if verbose then "--verbose --verbose" else "--quiet")
@@ -96,10 +122,47 @@ time zypper \
(* Return list of package filenames. *)
pkgs
+let zypp_rpm_resolve_dependencies_and_download_use_installed names =
+ let cmd = sprintf "
+%s
+unset LANG ${!LC_*}
+zypper \
+ %s \
+ %s \
+ --root %S --reposd-dir /dev/shm/supermin/zypp/repos.d \
+ --cache-dir %S \
+ --gpg-auto-import-keys \
+ --non-interactive \
+ --xml \
+ install \
+ --auto-agree-with-licenses \
+ --dry-run \
+ %s | \
+ xml sel -t \
+ -m \"stream/install-summary/to-install/solvable[%@type='package']\" \
+ -c \"string(%@name)\" -n
+"
+ (if verbose then "set -x" else "")
+ (if verbose then "--verbose --verbose" else "--quiet")
+ (match packager_config with None -> ""
+ | Some filename -> sprintf "--config %s" filename)
+ tmpdir tmpdir (String.concat " " (List.map Filename.quote names)) in
+ let pkg_names = run_command_get_lines cmd in
+
+ (* Return list of package names, remove empty lines. *)
+ List.filter (fun s -> s <> "") pkg_names
+
+let zypp_rpm_resolve_dependencies_and_download names =
+ if use_installed then
+ zypp_rpm_resolve_dependencies_and_download_use_installed names
+ else
+ zypp_rpm_resolve_dependencies_and_download_no_installed names
+
let rec zypp_rpm_list_files pkg =
(* Run rpm -qlp with some extra magic. *)
let cmd =
- sprintf "rpm -q --qf '[%%{FILENAMES} %%{FILEFLAGS:fflags} %%{FILEMODES} %%{FILESIZES}\\n]' -p %S"
+ sprintf "rpm -q --qf '[%%{FILENAMES} %%{FILEFLAGS:fflags} %%{FILEMODES} %%{FILESIZES}\\n]' %s %S"
+ (if use_installed then "" else "-p")
pkg in
let lines = run_command_get_lines cmd in
@@ -153,14 +216,18 @@ let rec zypp_rpm_list_files pkg =
files
let zypp_rpm_get_file_from_package pkg file =
- debug "extracting %s from %s ..." file (Filename.basename pkg);
-
- let outfile = tmpdir // file in
- let cmd =
- sprintf "umask 0000; rpm2cpio %s | (cd %s && cpio --quiet -id .%s)"
- (Filename.quote pkg) (Filename.quote tmpdir) (Filename.quote file) in
- run_command cmd;
- outfile
+ if use_installed then
+ file
+ else (
+ debug "extracting %s from %s ..." file (Filename.basename pkg);
+
+ let outfile = tmpdir // file in
+ let cmd =
+ sprintf "umask 0000; rpm2cpio %s | (cd %s && cpio --quiet -id .%s)"
+ (Filename.quote pkg) (Filename.quote tmpdir) (Filename.quote file) in
+ run_command cmd;
+ outfile
+ )
let () =
let ph = {

View File

@ -27,11 +27,16 @@ Group: System/Filesystems
Provides: febootstrap Provides: febootstrap
Obsoletes: febootstrap Obsoletes: febootstrap
Requires: distribution-release Requires: distribution-release
Requires: xmlstarlet
Requires: zypper
BuildRoot: %{_tmppath}/%{name}-%{version}-build BuildRoot: %{_tmppath}/%{name}-%{version}-build
Source0: http://libguestfs.org/download/supermin/supermin-%{version}.tar.gz Source0: http://libguestfs.org/download/supermin/supermin-%{version}.tar.gz
Patch0: 0000-Actually-update-gnulib.patch Patch1: 0001-Actually-update-gnulib.patch
Patch1: 0001-add-run_shell-helper.patch Patch2: 0002-helper-Add-missing-options-to-help-and-man-page-RHBZ.patch
Patch2: 0002-add-support-for-zypp.patch Patch3: 0003-add-run_shell-helper.patch
Patch4: 0004-add-support-for-zypp.patch
Patch5: 0005-always-work-with-empty-root-in-zypp-driver.patch
Patch6: 0006-handle-use-installed-in-zypp-driver.patch
BuildRequires: autoconf BuildRequires: autoconf
BuildRequires: automake BuildRequires: automake
BuildRequires: e2fsprogs BuildRequires: e2fsprogs
@ -51,9 +56,12 @@ you need to boot one of them.
%prep %prep
%setup -q %setup -q
%patch0 -p1
%patch1 -p1 %patch1 -p1
%patch2 -p1 %patch2 -p1
%patch3 -p1
%patch4 -p1
%patch5 -p1
%patch6 -p1
%build %build
export ZYPPER=zypper export ZYPPER=zypper