From e1eae5604ef816114b51c0ad695c44e0a24a0433 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Tue, 10 Dec 2013 16:57:02 +0100 Subject: [PATCH 1/2] unlock the whole power of zypper added the ptype parameter (package type of zypper install) --- .../__package_zypper/explorer/pkg_version | 19 +++++++++++++++++-- .../conf/type/__package_zypper/gencode-remote | 11 +++++++++-- cdist/conf/type/__package_zypper/man.text | 6 ++++++ .../__package_zypper/parameter/default/ptype | 1 + .../type/__package_zypper/parameter/optional | 1 + 5 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 cdist/conf/type/__package_zypper/parameter/default/ptype diff --git a/cdist/conf/type/__package_zypper/explorer/pkg_version b/cdist/conf/type/__package_zypper/explorer/pkg_version index 655b464d..64fd64c0 100644 --- a/cdist/conf/type/__package_zypper/explorer/pkg_version +++ b/cdist/conf/type/__package_zypper/explorer/pkg_version @@ -1,6 +1,7 @@ #!/bin/sh # # 2011-2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2013 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -18,7 +19,7 @@ # along with cdist. If not, see . # # -# Retrieve the status of a package +# Retrieve the status of a package off different types # if [ -f "$__object/parameter/name" ]; then @@ -27,4 +28,18 @@ else name="$__object_id" fi -rpm -q --whatprovides "$name" | grep -v 'no package provides' || true +if [ -f "$__object/parameter/ptype" ]; then + ptype="$(cat "$__object/parameter/ptype")" +else + ptype="package" +fi + +case "$ptype" in + package|patch|pattern|product|srcpackage) + zypper se --match-exact -i -t "$ptype" "$name" | grep -E '^i' | cut -d " " -f 3 || true + ;; + *) + echo "unknown type in __package_zypper explorer" &>2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__package_zypper/gencode-remote b/cdist/conf/type/__package_zypper/gencode-remote index d1766126..ef3bf029 100644 --- a/cdist/conf/type/__package_zypper/gencode-remote +++ b/cdist/conf/type/__package_zypper/gencode-remote @@ -1,6 +1,7 @@ #!/bin/sh # # 2012 Nico Schottelius (nico-cdist at schottelius.org) +# 2013 Daniel Heule (hda at sfs.biz) # # This file is part of cdist. # @@ -39,6 +40,12 @@ else state_should="present" fi +if [ -f "$__object/parameter/ptype" ]; then + ptype="$(cat "$__object/parameter/ptype")" +else + ptype="package" +fi + pkg_version="$(cat "$__object/explorer/pkg_version")" if [ -z "$pkg_version" ]; then state_is="absent" @@ -51,10 +58,10 @@ fi case "$state_should" in present) - echo zypper $globalopts install --auto-agree-with-licenses \"$name\" ">/dev/null" + echo zypper $globalopts install --type \"$ptype\" --auto-agree-with-licenses \"$name\" ">/dev/null" ;; absent) - echo zypper $globalopts remove \"$name\" ">/dev/null" + echo zypper $globalopts remove --type \"$ptype\" \"$name\" ">/dev/null" ;; *) echo "Unknown state: $state_should" >&2 diff --git a/cdist/conf/type/__package_zypper/man.text b/cdist/conf/type/__package_zypper/man.text index e2261d33..465b21be 100644 --- a/cdist/conf/type/__package_zypper/man.text +++ b/cdist/conf/type/__package_zypper/man.text @@ -26,6 +26,9 @@ name:: state:: Either "present" or "absent", defaults to "present" +ptype:: + Either "package", "patch", "pattern", "product" or "srcpackage", defaults to "package". For a description see man zypper. + EXAMPLES -------- @@ -39,6 +42,9 @@ __package_zypper python --state present --name python2 # Remove package __package_zypper cfengine --state absent + +# install all packages which belongs to pattern x11 +__package_zypper x11 --ptype pattern --state present -------------------------------------------------------------------------------- diff --git a/cdist/conf/type/__package_zypper/parameter/default/ptype b/cdist/conf/type/__package_zypper/parameter/default/ptype new file mode 100644 index 00000000..ba3bd787 --- /dev/null +++ b/cdist/conf/type/__package_zypper/parameter/default/ptype @@ -0,0 +1 @@ +package diff --git a/cdist/conf/type/__package_zypper/parameter/optional b/cdist/conf/type/__package_zypper/parameter/optional index 1b423dc4..b484bf07 100644 --- a/cdist/conf/type/__package_zypper/parameter/optional +++ b/cdist/conf/type/__package_zypper/parameter/optional @@ -1,2 +1,3 @@ name state +ptype From 785e54b3112e96f34ac026cec15385d22574bcc2 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 11 Dec 2013 13:44:01 +0100 Subject: [PATCH 2/2] =?UTF-8?q?vorbereitung=20um=20mit=20zypper=20auch=20s?= =?UTF-8?q?pezifische=20versionen=20zu=20unterst=C3=BCtzen=20parameter=20p?= =?UTF-8?q?type=20auch=20beim=20package=20type=20zulassen,=20analog=20ande?= =?UTF-8?q?rer=20parameter=20von=20subtypes=20...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cdist/conf/type/__package/parameter/optional | 1 + cdist/conf/type/__package_zypper/explorer/pkg_version | 9 ++++++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__package/parameter/optional b/cdist/conf/type/__package/parameter/optional index 9982507e..5a89ffc6 100644 --- a/cdist/conf/type/__package/parameter/optional +++ b/cdist/conf/type/__package/parameter/optional @@ -3,3 +3,4 @@ version type pkgsite state +pstate diff --git a/cdist/conf/type/__package_zypper/explorer/pkg_version b/cdist/conf/type/__package_zypper/explorer/pkg_version index 64fd64c0..aaa1da89 100644 --- a/cdist/conf/type/__package_zypper/explorer/pkg_version +++ b/cdist/conf/type/__package_zypper/explorer/pkg_version @@ -35,11 +35,14 @@ else fi case "$ptype" in - package|patch|pattern|product|srcpackage) - zypper se --match-exact -i -t "$ptype" "$name" | grep -E '^i' | cut -d " " -f 3 || true + package) + zypper search --details --match-exact --installed-only --type "$ptype" "$name" | grep -E '^i' | cut -d " " -f 3,7 || true + ;; + patch|pattern|product|srcpackage) + zypper search --match-exact --installed-only --type "$ptype" "$name" | grep -E '^i' | cut -d " " -f 3 || true ;; *) - echo "unknown type in __package_zypper explorer" &>2 + echo "unknown ptype in __package_zypper explorer" &>2 exit 1 ;; esac