[Libguestfs] [PATCH / RFC] Handle --packager-config in zypp_rpm

Olaf Hering olaf at aepfle.de
Tue Jun 4 09:37:45 UTC 2013


This is an attempt to handle a different --reposd-dir in the zypp_rpm
driver. Up to now the system repositories in /etc/zypp/repos.d were
used.

To specify a different set of repositories for zypp a parser for a
simple zypper.conf is added in this patch. It just looks for reposdir=
in section main, like this:

 [main]
 reposdir=/path/to/other/repofiles

If the config file provided via "--packager-config my_zypp.conf" is
valid the other directory is passed to zypper, otherwise the system
repos.d is used like its done in current code.

Depending on the kind of provided repos, the current code may fail to
import a repo in non-interactive mode. This happens if the repo data are
not properly signed. For this reason the option --no-gpg-checks is added
by this patch.

Finally, the parser uses ocaml-inifiles to read the config file. This is
a new build dependency. inifiles should be available in various
distributions, copies of the original sources can be found via google.

This patch has received some light testing, I sent it out to the list
for further comments. Particular about the new inifiles dependency..


Signed-off-by: Olaf Hering <olaf at aepfle.de>

---
 src/Makefile.am          |  2 +-
 src/supermin_zypp_rpm.ml | 23 ++++++++++++++++++++---
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am
index 3b6ca9b..6ed0faf 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -56,7 +56,7 @@ OBJECTS = $(XOBJECTS)
 BEST    = opt
 endif
 
-OCAMLPACKAGES = -package unix,str
+OCAMLPACKAGES = -package unix,str,inifiles
 OCAMLFLAGS = -warn-error CDEFLMPSUVXYZ
 
 supermin: $(OBJECTS)
diff --git a/src/supermin_zypp_rpm.ml b/src/supermin_zypp_rpm.ml
index c269aab..c9786ce 100644
--- a/src/supermin_zypp_rpm.ml
+++ b/src/supermin_zypp_rpm.ml
@@ -45,6 +45,7 @@
  *)
 open Unix
 open Printf
+open Inifiles
 
 open Supermin_package_handlers
 open Supermin_utils
@@ -54,6 +55,19 @@ open Supermin_cmdline
 (* Create a temporary directory for use by all the functions in this file. *)
 let tmpdir = tmpdir ()
 
+let get_repos_dir () =
+  let zypper_default = "/etc/zypp/repos.d" in
+  let parse_repos_dir path = 
+    let cfg = new inifile path in
+    let dir = (try cfg#getval "main" "reposdir" with _ -> zypper_default) in
+    dir
+  in
+  let dir = (match packager_config with None -> zypper_default |
+      Some filename -> (try parse_repos_dir filename with _ -> zypper_default) ) in
+  dir
+
+let repos_dir = get_repos_dir ()
+
 let zypp_rpm_detect () =
   (file_exists "/etc/SuSE-release") &&
     Config.zypper <> "no" && Config.rpm <> "no"
@@ -75,10 +89,11 @@ pkg_cache_dir=%S
 time zypper \
 	%s \
 	%s \
-	--root %S --reposd-dir /etc/zypp/repos.d \
+	--root %S --reposd-dir %S \
 	--cache-dir \"${cache_dir}\" \
 	--pkg-cache-dir \"${pkg_cache_dir}\" \
 	--gpg-auto-import-keys \
+	--no-gpg-checks \
 	--non-interactive \
 	install \
 	--auto-agree-with-licenses \
@@ -92,6 +107,7 @@ time zypper \
     (match packager_config with None -> ""
      | Some filename -> sprintf "--config %s" filename)
     tmp_root
+    repos_dir
     in
   run_shell sh names;
 
@@ -129,9 +145,10 @@ unset LANG ${!LC_*}
 zypper \
 	%s \
 	%s \
-	--root %S --reposd-dir /etc/zypp/repos.d \
+	--root %S --reposd-dir %S \
 	--cache-dir %S \
 	--gpg-auto-import-keys \
+	--no-gpg-checks \
 	--non-interactive \
 	--xml \
 	install \
@@ -146,7 +163,7 @@ zypper \
     (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
+    tmpdir repos_dir 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. *)




More information about the Libguestfs mailing list