From b29a52db1a954249cae052ff80c1df6cf3d56f80 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 09:37:01 +0100 Subject: [PATCH] Initial add vom type __zypper_repo --- .../type/__zypper_repo/explorer/all_repo_ids | 3 + .../__zypper_repo/explorer/enabled_repo_ids | 3 + .../conf/type/__zypper_repo/explorer/repo_id | 8 ++ cdist/conf/type/__zypper_repo/gencode-remote | 94 +++++++++++++++++++ cdist/conf/type/__zypper_repo/man.text | 68 ++++++++++++++ .../__zypper_repo/parameter/default/state | 1 + .../type/__zypper_repo/parameter/optional | 4 + docs/man/man7/.directory | 4 + 8 files changed, 185 insertions(+) create mode 100644 cdist/conf/type/__zypper_repo/explorer/all_repo_ids create mode 100644 cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids create mode 100644 cdist/conf/type/__zypper_repo/explorer/repo_id create mode 100644 cdist/conf/type/__zypper_repo/gencode-remote create mode 100644 cdist/conf/type/__zypper_repo/man.text create mode 100644 cdist/conf/type/__zypper_repo/parameter/default/state create mode 100644 cdist/conf/type/__zypper_repo/parameter/optional create mode 100644 docs/man/man7/.directory diff --git a/cdist/conf/type/__zypper_repo/explorer/all_repo_ids b/cdist/conf/type/__zypper_repo/explorer/all_repo_ids new file mode 100644 index 00000000..e1772956 --- /dev/null +++ b/cdist/conf/type/__zypper_repo/explorer/all_repo_ids @@ -0,0 +1,3 @@ +#!/bin/sh +# +echo $(zypper lr -u | cut -d'|' -f 1 | grep -E '^[0-9]') diff --git a/cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids b/cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids new file mode 100644 index 00000000..6ece6e05 --- /dev/null +++ b/cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids @@ -0,0 +1,3 @@ +#!/bin/sh +# +echo $(zypper lr -E | cut -d'|' -f 1 | grep -E '^[0-9]') diff --git a/cdist/conf/type/__zypper_repo/explorer/repo_id b/cdist/conf/type/__zypper_repo/explorer/repo_id new file mode 100644 index 00000000..aa1e5f99 --- /dev/null +++ b/cdist/conf/type/__zypper_repo/explorer/repo_id @@ -0,0 +1,8 @@ +#!/bin/sh +# +if [ -f "$__object/parameter/repo_uri" ]; then + uri="$(cat "$__object/parameter/repo_uri")" +else + uri="/$__object_id" +fi +echo $(zypper lr -u | grep -E "\<$uri\>" | cut -d'|' -f 1 | grep -E '^[0-9]' ) diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote new file mode 100644 index 00000000..b56518c9 --- /dev/null +++ b/cdist/conf/type/__zypper_repo/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 repo services with Zypper (mostly suse) +# + +# Debug +#exec >&2 +#set -x + +zypper_def_opts=" -q " + +if [ -f "$__object/parameter/repo_desc" ]; then + desc="$(cat "$__object/parameter/repo_desc")" +else + desc="$__object_id" +fi + +if [ -f "$__object/parameter/repo_uri" ]; then + uri="$(cat "$__object/parameter/repo_uri")" +else + uri="$__object_id" +fi + +if [ -f "$__object/parameter/repo_id" ]; then + id="$(cat "$__object/parameter/repo_id")" +else + id="$__object_id" +fi + +if [ -f "$__object/parameter/state" ]; then + state="$(cat "$__object/parameter/state")" +else + state="present" +fi + +all_repo_ids="$(cat "$__object/explorer/all_repo_ids")" +enabled_repo_ids="$(cat "$__object/explorer/enabled_repo_ids")" +repo_id="$(cat "$__object/explorer/repo_id")" + +act_id="" +if grep -q $id $__object/explorer/all_repo_ids; then + act_id="$id" +elif grep -q $repo_id $__object/explorer/all_repo_ids; then + act_id="$repo_id" +fi + +case "$state" in + present) + if [ -z "$desc" ] || [ -z "$uri" ]; then + echo "parameter repo_desc and repo_uri for $state needed" >&2 + exit 4 + fi + if [ -z "$repo_id" ]; then + echo zypper $zypper_def_opts addrepo "'$uri'" "'$desc'" + fi + ;; + absent) + if [ ! -z "$act_id" ]; then + echo zypper $zypper_def_opts removerepo $act_id + fi + ;; + enabled) + if [ ! -z "$act_id" ]; then + echo zypper $zypper_def_opts modifyrepo -e $act_id + fi + ;; + disabled) + if [ ! -z "$act_id" ]; then + echo zypper $zypper_def_opts modifyrepo -d $act_id + fi + ;; + *) + echo "Unknown state: $state" >&2 + exit 1 + ;; +esac diff --git a/cdist/conf/type/__zypper_repo/man.text b/cdist/conf/type/__zypper_repo/man.text new file mode 100644 index 00000000..c5d23713 --- /dev/null +++ b/cdist/conf/type/__zypper_repo/man.text @@ -0,0 +1,68 @@ +cdist-type__zypper_repo(7) +========================== +Daniel Heule + + +NAME +---- +cdist-type__zypper_repo - repository management with zypper + + +DESCRIPTION +----------- +Zypper is usually used on the SuSE distribution to manage repositorys. + + +REQUIRED PARAMETERS +------------------- +None + + +OPTIONAL PARAMETERS +------------------- +state:: + Either "present" or "absent" or "enabled" or "disabled", defaults to "present" + +repo_uri:: + If supplied, use the uri and not the object id as the repo uri. + +repo_desc:: + If supplied, use the description and not the object id as the repo description, only used for state present if the repo must created + +repo_id:: + If supplied, use the id and not the object id as the repo id, can be used for with states absent,enabled,disabled + + +EXAMPLES +-------- + +-------------------------------------------------------------------------------- +# Ensure testrepo in installed +__zypper_repo testrepo --state present --repo_uri http://url.to.your.repo/with/path + +# Drop repo by repo uri +__zypper_repo testrepo --state absent --repo_uri http://url.to.your.repo/with/path + +# Drop repo by id nummber, attention: on every call to absent, repos are new numbered from 1 to max +__zypper_repo testrepo --state absent --repo_id 1 + +# enable repo by id +__zypper_repo testrepo2 --state enabled --repo_id 2 + +# enable repo by uri +__zypper_repo testrepo3 --state enabled --repo_uri http://url.to.your.repo/with/path + +# disable a repo works like enabling +__zypper_repo testrepo4 --state disabled --repo_id 4 +-------------------------------------------------------------------------------- + + +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_repo/parameter/default/state b/cdist/conf/type/__zypper_repo/parameter/default/state new file mode 100644 index 00000000..e7f6134f --- /dev/null +++ b/cdist/conf/type/__zypper_repo/parameter/default/state @@ -0,0 +1 @@ +present diff --git a/cdist/conf/type/__zypper_repo/parameter/optional b/cdist/conf/type/__zypper_repo/parameter/optional new file mode 100644 index 00000000..6f5a8325 --- /dev/null +++ b/cdist/conf/type/__zypper_repo/parameter/optional @@ -0,0 +1,4 @@ +state +repo_uri +repo_desc +repo_id diff --git a/docs/man/man7/.directory b/docs/man/man7/.directory new file mode 100644 index 00000000..e2ac7573 --- /dev/null +++ b/docs/man/man7/.directory @@ -0,0 +1,4 @@ +[Dolphin] +Timestamp=2013,12,4,9,33,47 +Version=3 +ViewMode=2