From 0f1dabb08028b79e7ee373da468291ccc7efb3df Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Tue, 10 Dec 2013 11:50:18 +0100 Subject: [PATCH] inital commit of __zypper_service --- .../type/__zypper_service/explorer/repo_ids | 24 +++++ .../type/__zypper_service/explorer/service_id | 28 ++++++ .../__zypper_service/explorer/service_ids | 23 +++++ .../__zypper_service/explorer/service_uri | 28 ++++++ .../conf/type/__zypper_service/gencode-remote | 94 +++++++++++++++++++ cdist/conf/type/__zypper_service/man.text | 67 +++++++++++++ cdist/conf/type/__zypper_service/manifest | 63 +++++++++++++ .../type/__zypper_service/parameter/boolean | 2 + .../__zypper_service/parameter/default/state | 1 + .../__zypper_service/parameter/default/type | 1 + .../type/__zypper_service/parameter/optional | 3 + .../type/__zypper_service/parameter/required | 1 + 12 files changed, 335 insertions(+) create mode 100644 cdist/conf/type/__zypper_service/explorer/repo_ids create mode 100644 cdist/conf/type/__zypper_service/explorer/service_id create mode 100644 cdist/conf/type/__zypper_service/explorer/service_ids create mode 100644 cdist/conf/type/__zypper_service/explorer/service_uri create mode 100644 cdist/conf/type/__zypper_service/gencode-remote create mode 100644 cdist/conf/type/__zypper_service/man.text create mode 100644 cdist/conf/type/__zypper_service/manifest create mode 100644 cdist/conf/type/__zypper_service/parameter/boolean create mode 100644 cdist/conf/type/__zypper_service/parameter/default/state create mode 100644 cdist/conf/type/__zypper_service/parameter/default/type create mode 100644 cdist/conf/type/__zypper_service/parameter/optional create mode 100644 cdist/conf/type/__zypper_service/parameter/required diff --git a/cdist/conf/type/__zypper_service/explorer/repo_ids b/cdist/conf/type/__zypper_service/explorer/repo_ids new file mode 100644 index 00000000..8c32b40b --- /dev/null +++ b/cdist/conf/type/__zypper_service/explorer/repo_ids @@ -0,0 +1,24 @@ +#!/bin/sh +# +# 2013 Daniel Heule (hda at sfs.biz) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Manage services with Zypper (mostly suse) +# +# +echo $(zypper lr -u -E | cut -d'|' -f 1 | grep -E '^[0-9]') diff --git a/cdist/conf/type/__zypper_service/explorer/service_id b/cdist/conf/type/__zypper_service/explorer/service_id new file mode 100644 index 00000000..b473340c --- /dev/null +++ b/cdist/conf/type/__zypper_service/explorer/service_id @@ -0,0 +1,28 @@ +#!/bin/sh +# +# 2013 Daniel Heule (hda at sfs.biz) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Manage services with Zypper (mostly suse) +# +if [ -f "$__object/parameter/service_uri" ]; then + uri="$(cat "$__object/parameter/service_uri")" +else + uri="/$__object_id" +fi +echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 1 ) diff --git a/cdist/conf/type/__zypper_service/explorer/service_ids b/cdist/conf/type/__zypper_service/explorer/service_ids new file mode 100644 index 00000000..460b2006 --- /dev/null +++ b/cdist/conf/type/__zypper_service/explorer/service_ids @@ -0,0 +1,23 @@ +#!/bin/sh +# +# 2013 Daniel Heule (hda at sfs.biz) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Manage services with Zypper (mostly suse) +# +echo $(zypper ls -u -E | cut -d'|' -f 1 | grep -E '^[0-9]') diff --git a/cdist/conf/type/__zypper_service/explorer/service_uri b/cdist/conf/type/__zypper_service/explorer/service_uri new file mode 100644 index 00000000..aec93cb2 --- /dev/null +++ b/cdist/conf/type/__zypper_service/explorer/service_uri @@ -0,0 +1,28 @@ +#!/bin/sh +# +# 2013 Daniel Heule (hda at sfs.biz) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Manage services with Zypper (mostly suse) +# +if [ -f "$__object/parameter/service_uri" ]; then + uri="$(cat "$__object/parameter/service_uri")" +else + uri="/$__object_id" +fi +echo $(zypper ls -u -E | grep -E "\<$uri\>" | cut -d'|' -f 7 ) diff --git a/cdist/conf/type/__zypper_service/gencode-remote b/cdist/conf/type/__zypper_service/gencode-remote new file mode 100644 index 00000000..d11749ae --- /dev/null +++ b/cdist/conf/type/__zypper_service/gencode-remote @@ -0,0 +1,94 @@ +#!/bin/sh +# +# 2013 Daniel Heule (hda at sfs.biz) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Manage services with Zypper (mostly suse) +# + +# Debug +#exec >&2 +#set -x + +zypper_def_opts=" -q " + +if [ -f "$__object/parameter/service_desc" ]; then + desc="$(cat "$__object/parameter/service_desc")" +else + desc="$__object_id" +fi + +if [ -f "$__object/parameter/service_uri" ]; then + uri="$(cat "$__object/parameter/service_uri")" +else + uri="$__object_id" +fi + +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi + +if [ -f "$__object/parameter/type" ]; then + stype="$(cat "$__object/parameter/type")" +else + stype="ris" +fi + +exp_uri="$(cat "$__object/explorer/service_uri")" +exp_id="$(cat "$__object/explorer/service_id")" + +# we need this list to remove ids, but we must do this in reverse order +exp_ids="$(cat "$__object/explorer/service_ids" | rev)" + +if [ "$uri" = "$exp_uri" ] ; then + state_is="present" +else + state_is="absent" +fi + +# remove all other services if needed ... +if [ -f "$__object/parameter/remove-all-other-services" ]; then + # file exists -> True + for i in $exp_ids; do + if [ "$i" != "$exp_id" ] ; then + echo zypper $zypper_def_opts removeservice "$i" "&>/dev/null" + fi + done + echo zypper $zypper_def_opts refs "&>/dev/null" +fi + + +# Exit if nothing is needed to be done +[ "$state_is" = "$state_should" ] && exit 0 + +case "$state_should" in + present) + echo zypper $zypper_def_opts addservice -t "$stype" "$uri" \"$desc\" + echo zypper $zypper_def_opts refs + ;; + absent) + echo zypper $zypper_def_opts removeservice "$service_id" + echo zypper $zypper_def_opts refs + ;; + *) + echo "Unknown state: $state_should" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__zypper_service/man.text b/cdist/conf/type/__zypper_service/man.text new file mode 100644 index 00000000..3345be60 --- /dev/null +++ b/cdist/conf/type/__zypper_service/man.text @@ -0,0 +1,67 @@ +cdist-type__zypper_service(7) +============================= +Daniel Heule + + +NAME +---- +cdist-type__zypper_service - service management with zypper + + +DESCRIPTION +----------- +zypper is usually used on SuSE systems to manage services. + + +REQUIRED PARAMETERS +------------------- +service_uri:: + Uri of the service + + +OPTIONAL PARAMETERS +------------------- +service_desc:: + If supplied, use the service_desc and not the object id as descritpion for the service. + +state:: + Either "present" or "absent", defaults to "present" + +type:: + Defaults to "ris", the standard type of services at SLES11. For other values, see manpage of zypper. + + +BOOLEAN PARAMETERS +------------------ +remove-all-other-service:: + Drop all other services found on the target host before adding the new one. + +remove-all-repos:: + If supplied, remove all existing repos prior to setup the new service. + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Ensure that internal SLES11 SP3 RIS is in installed and all other services and repos are discarded +__zypper_service SFS_SLES11_SP3 --service_desc "Internal SLES11 SP3 RIS" --service_uri "http://path/to/your/ris/dir" --remove-all-other-service --remove-all-repos + +# Ensure that internal SLES11 SP3 RIS is in installed, no changes to ohter services or repos +__zypper_service SFS_SLES11_SP3 --service_desc "Internal SLES11 SP3 RIS" --service_uri "http://path/to/your/ris/dir" + +# Drop service by uri, no changes to ohter services or repos +__zypper_service SFS_SLES11_SP3 --state absent --service_uri "http://path/to/your/ris/dir" + +-------------------------------------------------------------------------------- + + +SEE ALSO +-------- +- cdist-type(7) + + +COPYING +------- +Copyright \(C) 2013 Daniel Heule. Free use of this software is +granted under the terms of the GNU General Public License version 3 (GPLv3). diff --git a/cdist/conf/type/__zypper_service/manifest b/cdist/conf/type/__zypper_service/manifest new file mode 100644 index 00000000..d8773605 --- /dev/null +++ b/cdist/conf/type/__zypper_service/manifest @@ -0,0 +1,63 @@ +#!/bin/sh +# +# 2013 Daniel Heule (hda at sfs.biz) +# +# This file is part of cdist. +# +# cdist is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# cdist is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with cdist. If not, see . +# +# +# Manage services with Zypper (mostly suse) +# + +# Debug +#exec >&2 +#set -x + +zypper_def_opts=" -q " + +if [ -f "$__object/parameter/service_uri" ]; then + uri="$(cat "$__object/parameter/service_uri")" +else + uri="$__object_id" +fi + +if [ -f "$__object/parameter/state" ]; then + state_should="$(cat "$__object/parameter/state")" +else + state_should="present" +fi + +exp_uri="$(cat "$__object/explorer/service_uri")" + +if [ "$uri" = "$exp_uri" ] ; then + state_is="present" +else + state_is="absent" +fi + + +# Exit if nothing is needed to be done +[ "$state_is" = "$state_should" ] && exit 0 + +# we need this list to remove ids, but we must do this in reverse order +exp_repos="$(cat "$__object/explorer/repo_ids" | rev)" + +# boolean parameter +if [ -f "$__object/parameter/remove-all-repos" ]; then + # file exists -> True + for i in $exp_repos; do + __zypper_repo "droprepo${i}" --state absent --repo_id "${i}" + done +fi diff --git a/cdist/conf/type/__zypper_service/parameter/boolean b/cdist/conf/type/__zypper_service/parameter/boolean new file mode 100644 index 00000000..bc6a5629 --- /dev/null +++ b/cdist/conf/type/__zypper_service/parameter/boolean @@ -0,0 +1,2 @@ +remove-all-other-service +remove-all-repos diff --git a/cdist/conf/type/__zypper_service/parameter/default/state b/cdist/conf/type/__zypper_service/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__zypper_service/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__zypper_service/parameter/default/type b/cdist/conf/type/__zypper_service/parameter/default/type new file mode 100644 index 00000000..b928830f --- /dev/null +++ b/cdist/conf/type/__zypper_service/parameter/default/type @@ -0,0 +1 @@ +ris diff --git a/cdist/conf/type/__zypper_service/parameter/optional b/cdist/conf/type/__zypper_service/parameter/optional new file mode 100644 index 00000000..b26c78d8 --- /dev/null +++ b/cdist/conf/type/__zypper_service/parameter/optional @@ -0,0 +1,3 @@ +service_desc +state +type diff --git a/cdist/conf/type/__zypper_service/parameter/required b/cdist/conf/type/__zypper_service/parameter/required new file mode 100644 index 00000000..2b4645ee --- /dev/null +++ b/cdist/conf/type/__zypper_service/parameter/required @@ -0,0 +1 @@ +service_uri