From b29a52db1a954249cae052ff80c1df6cf3d56f80 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 09:37:01 +0100 Subject: [PATCH 01/13] 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 From 19219fe1f96b30ed5c8a38f40d3a2e63b7c4466a Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 09:44:45 +0100 Subject: [PATCH 02/13] An allen orten correcte gpl headers eingesetzt ... --- .../type/__zypper_repo/explorer/all_repo_ids | 23 ++++++++++++++++++- .../__zypper_repo/explorer/enabled_repo_ids | 21 +++++++++++++++++ .../conf/type/__zypper_repo/explorer/repo_id | 21 +++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__zypper_repo/explorer/all_repo_ids b/cdist/conf/type/__zypper_repo/explorer/all_repo_ids index e1772956..b37d8ac5 100644 --- a/cdist/conf/type/__zypper_repo/explorer/all_repo_ids +++ b/cdist/conf/type/__zypper_repo/explorer/all_repo_ids @@ -1,3 +1,24 @@ #!/bin/sh # -echo $(zypper lr -u | cut -d'|' -f 1 | grep -E '^[0-9]') +# 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 . +# +# +# Retrieve all repo id nummbers - parsed zypper output +# +# +echo $(zypper lr | 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 index 6ece6e05..a0d092b1 100644 --- a/cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids +++ b/cdist/conf/type/__zypper_repo/explorer/enabled_repo_ids @@ -1,3 +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 . +# +# +# Retrieve all repo id nummbers from enabled repos - parsed zypper output +# +# 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 index aa1e5f99..8184860d 100644 --- a/cdist/conf/type/__zypper_repo/explorer/repo_id +++ b/cdist/conf/type/__zypper_repo/explorer/repo_id @@ -1,5 +1,26 @@ #!/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 . +# +# +# Retrieve the id from the repo with the uri from parameter repo_uri - parsed zypper output +# +# if [ -f "$__object/parameter/repo_uri" ]; then uri="$(cat "$__object/parameter/repo_uri")" else From b5a0c52684eb82d12c31ab8d5887695cb640b78e Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 10:15:24 +0100 Subject: [PATCH 03/13] =?UTF-8?q?aus=20versehen=20eine=20.direcotry=20date?= =?UTF-8?q?i=20vom=20dolphin=20eingecheckt,=20nun=20wieder=20gel=C3=B6scht?= =?UTF-8?q?=20...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/man/man7/.directory | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 docs/man/man7/.directory diff --git a/docs/man/man7/.directory b/docs/man/man7/.directory deleted file mode 100644 index e2ac7573..00000000 --- a/docs/man/man7/.directory +++ /dev/null @@ -1,4 +0,0 @@ -[Dolphin] -Timestamp=2013,12,4,9,33,47 -Version=3 -ViewMode=2 From 6a68c14a7632db061e7fe18d80e78ce9e0e531da Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 10:56:45 +0100 Subject: [PATCH 04/13] letzter feinschliff bei der man page ... --- cdist/conf/type/__zypper_repo/man.text | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cdist/conf/type/__zypper_repo/man.text b/cdist/conf/type/__zypper_repo/man.text index c5d23713..4f2de508 100644 --- a/cdist/conf/type/__zypper_repo/man.text +++ b/cdist/conf/type/__zypper_repo/man.text @@ -10,7 +10,7 @@ cdist-type__zypper_repo - repository management with zypper DESCRIPTION ----------- -Zypper is usually used on the SuSE distribution to manage repositorys. +zypper is usually used on the SuSE distribution to manage repositories. REQUIRED PARAMETERS @@ -24,13 +24,13 @@ 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. + If supplied, use the uri and not the object id as 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 + If supplied, use the description and not the object id as repo description, only used if the state is present and the repo has to be 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 + If supplied, use the id and not the object id as repo id, can be used with state absent, enabled and disabled EXAMPLES @@ -43,7 +43,7 @@ __zypper_repo testrepo --state present --repo_uri http://url.to.your.repo/with/p # 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 +# Drop repo by id number (attention: repos are always numbered from 1 to max) __zypper_repo testrepo --state absent --repo_id 1 # enable repo by id @@ -52,7 +52,7 @@ __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 +# disable a repo works like enabling it __zypper_repo testrepo4 --state disabled --repo_id 4 -------------------------------------------------------------------------------- From 808ea306347ae98f122dc453e9d4e416b166ad12 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 14:50:11 +0100 Subject: [PATCH 05/13] Korrektur der intention, vim hat mich verschaukelt ... --- cdist/conf/type/__zypper_repo/gencode-remote | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote index b56518c9..c2302662 100644 --- a/cdist/conf/type/__zypper_repo/gencode-remote +++ b/cdist/conf/type/__zypper_repo/gencode-remote @@ -65,27 +65,27 @@ 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 + 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 + echo zypper $zypper_def_opts addrepo "'$uri'" "'$desc'" + fi ;; absent) if [ ! -z "$act_id" ]; then echo zypper $zypper_def_opts removerepo $act_id - fi + fi ;; enabled) if [ ! -z "$act_id" ]; then echo zypper $zypper_def_opts modifyrepo -e $act_id - fi + fi ;; disabled) if [ ! -z "$act_id" ]; then echo zypper $zypper_def_opts modifyrepo -d $act_id - fi + fi ;; *) echo "Unknown state: $state" >&2 From ea33b093f0e4c9f2c97a76d7e628937afe71012f Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 14:58:15 +0100 Subject: [PATCH 06/13] cleanup of variable quoting --- cdist/conf/type/__zypper_repo/gencode-remote | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote index c2302662..83b05dd0 100644 --- a/cdist/conf/type/__zypper_repo/gencode-remote +++ b/cdist/conf/type/__zypper_repo/gencode-remote @@ -56,9 +56,9 @@ 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 +if grep -q "$id" "$__object/explorer/all_repo_ids"; then act_id="$id" -elif grep -q $repo_id $__object/explorer/all_repo_ids; then +elif grep -q "$repo_id" "$__object/explorer/all_repo_ids"; then act_id="$repo_id" fi @@ -74,17 +74,17 @@ case "$state" in ;; absent) if [ ! -z "$act_id" ]; then - echo zypper $zypper_def_opts removerepo $act_id + echo zypper $zypper_def_opts removerepo "'$act_id'" fi ;; enabled) if [ ! -z "$act_id" ]; then - echo zypper $zypper_def_opts modifyrepo -e $act_id + 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 + echo zypper $zypper_def_opts modifyrepo -d "'$act_id'" fi ;; *) From 33a4f07bb40a2406fddeb41e81c734bc3424d45f Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 15:22:48 +0100 Subject: [PATCH 07/13] in der manpage state parameter besser erlaeutert ... TODO: howto line breaks in html ? --- cdist/conf/type/__zypper_repo/man.text | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/cdist/conf/type/__zypper_repo/man.text b/cdist/conf/type/__zypper_repo/man.text index 4f2de508..6ea88f16 100644 --- a/cdist/conf/type/__zypper_repo/man.text +++ b/cdist/conf/type/__zypper_repo/man.text @@ -21,7 +21,12 @@ None OPTIONAL PARAMETERS ------------------- state:: - Either "present" or "absent" or "enabled" or "disabled", defaults to "present" + Either "present" or "absent" or "enabled" or "disabled", defaults to "present" + + #present# - make sure that the repo is aviable, needs repo_uri and repo_desc + + for all following states, the repo can be searched via repo_id or repo_uri + + #absent# - drop the repo if found + + #enabled# - a repo can have state disabled if installed via zypper service (ris), in this case, you can enable the repo + + #disabled# - instead of absent (drop), a repo can also set to disabled, wich makes it inaccessible + repo_uri:: If supplied, use the uri and not the object id as repo uri. From a37c48ed439ba90c2bc59dcd3c4b9cf37f4e3433 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 15:24:18 +0100 Subject: [PATCH 08/13] bei dem repo_id eine kleine verschoenerung --- cdist/conf/type/__zypper_repo/explorer/repo_id | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cdist/conf/type/__zypper_repo/explorer/repo_id b/cdist/conf/type/__zypper_repo/explorer/repo_id index 8184860d..83a698b7 100644 --- a/cdist/conf/type/__zypper_repo/explorer/repo_id +++ b/cdist/conf/type/__zypper_repo/explorer/repo_id @@ -24,6 +24,6 @@ if [ -f "$__object/parameter/repo_uri" ]; then uri="$(cat "$__object/parameter/repo_uri")" else - uri="/$__object_id" + uri="$__object_id" fi echo $(zypper lr -u | grep -E "\<$uri\>" | cut -d'|' -f 1 | grep -E '^[0-9]' ) From 72bbf932826a94077287cbbdd6cd9985cddddc18 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Wed, 4 Dec 2013 15:32:31 +0100 Subject: [PATCH 09/13] korrekte ids, hier werden von zypper keine quotes erwartet, da nur zahlen moeglich sind --- cdist/conf/type/__zypper_repo/gencode-remote | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote index 83b05dd0..efe0a8f5 100644 --- a/cdist/conf/type/__zypper_repo/gencode-remote +++ b/cdist/conf/type/__zypper_repo/gencode-remote @@ -74,17 +74,17 @@ case "$state" in ;; absent) if [ ! -z "$act_id" ]; then - echo zypper $zypper_def_opts removerepo "'$act_id'" + echo zypper $zypper_def_opts removerepo "$act_id" fi ;; enabled) if [ ! -z "$act_id" ]; then - echo zypper $zypper_def_opts modifyrepo -e "'$act_id'" + 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'" + echo zypper $zypper_def_opts modifyrepo -d "$act_id" fi ;; *) From e1a2ebab5c4d6727cae37fb829c671c1cd0e7f56 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 5 Dec 2013 08:45:12 +0100 Subject: [PATCH 10/13] gencode-remote gibt nur noch befehle aus wenn was zu tun ist ... --- cdist/conf/type/__zypper_repo/gencode-remote | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote index efe0a8f5..c93ca229 100644 --- a/cdist/conf/type/__zypper_repo/gencode-remote +++ b/cdist/conf/type/__zypper_repo/gencode-remote @@ -51,8 +51,6 @@ 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="" @@ -62,6 +60,13 @@ elif grep -q "$repo_id" "$__object/explorer/all_repo_ids"; then act_id="$repo_id" fi +if grep -q "$act_id" "$__object/explorer/enabled_repo_ids"; then + state="enabled" +else + state="disabled" +fi + + case "$state" in present) if [ -z "$desc" ] || [ -z "$uri" ]; then @@ -78,12 +83,12 @@ case "$state" in fi ;; enabled) - if [ ! -z "$act_id" ]; then + if [ ! -z "$act_id" ] && [ "$state" = "disabled" ]; then echo zypper $zypper_def_opts modifyrepo -e "$act_id" fi ;; disabled) - if [ ! -z "$act_id" ]; then + if [ ! -z "$act_id" ] && [ "$state" = "disabled" ]; then echo zypper $zypper_def_opts modifyrepo -d "$act_id" fi ;; From 512b4100123c649ee4958ba54272e5c3ca055856 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 5 Dec 2013 08:47:57 +0100 Subject: [PATCH 11/13] korrektur eines typos ... --- cdist/conf/type/__zypper_repo/gencode-remote | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote index c93ca229..e2cc25e5 100644 --- a/cdist/conf/type/__zypper_repo/gencode-remote +++ b/cdist/conf/type/__zypper_repo/gencode-remote @@ -60,10 +60,9 @@ elif grep -q "$repo_id" "$__object/explorer/all_repo_ids"; then act_id="$repo_id" fi +state="disabled" if grep -q "$act_id" "$__object/explorer/enabled_repo_ids"; then state="enabled" -else - state="disabled" fi @@ -88,7 +87,7 @@ case "$state" in fi ;; disabled) - if [ ! -z "$act_id" ] && [ "$state" = "disabled" ]; then + if [ ! -z "$act_id" ] && [ "$state" = "enabled" ]; then echo zypper $zypper_def_opts modifyrepo -d "$act_id" fi ;; From 59de2afdaaa7b122744dac5c5eab27d36fa07ed4 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Thu, 5 Dec 2013 13:14:15 +0100 Subject: [PATCH 12/13] ups, was a variable collision --- cdist/conf/type/__zypper_repo/gencode-remote | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote index e2cc25e5..4698582e 100644 --- a/cdist/conf/type/__zypper_repo/gencode-remote +++ b/cdist/conf/type/__zypper_repo/gencode-remote @@ -60,9 +60,9 @@ elif grep -q "$repo_id" "$__object/explorer/all_repo_ids"; then act_id="$repo_id" fi -state="disabled" +repostate="disabled" if grep -q "$act_id" "$__object/explorer/enabled_repo_ids"; then - state="enabled" + repostate="enabled" fi @@ -82,12 +82,12 @@ case "$state" in fi ;; enabled) - if [ ! -z "$act_id" ] && [ "$state" = "disabled" ]; then + if [ ! -z "$act_id" ] && [ "$repostate" = "disabled" ]; then echo zypper $zypper_def_opts modifyrepo -e "$act_id" fi ;; disabled) - if [ ! -z "$act_id" ] && [ "$state" = "enabled" ]; then + if [ ! -z "$act_id" ] && [ "$repostate" = "enabled" ]; then echo zypper $zypper_def_opts modifyrepo -d "$act_id" fi ;; From a271244cfb77aa7a70ac2af836fcdc7aa4fa41c4 Mon Sep 17 00:00:00 2001 From: Daniel Heule Date: Fri, 6 Dec 2013 15:23:09 +0100 Subject: [PATCH 13/13] Die 4 codepaths mit comments erklaert ... --- cdist/conf/type/__zypper_repo/gencode-remote | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/cdist/conf/type/__zypper_repo/gencode-remote b/cdist/conf/type/__zypper_repo/gencode-remote index 4698582e..4d834c47 100644 --- a/cdist/conf/type/__zypper_repo/gencode-remote +++ b/cdist/conf/type/__zypper_repo/gencode-remote @@ -73,21 +73,25 @@ case "$state" in exit 4 fi if [ -z "$repo_id" ]; then + # Repo not present, so we need to create it echo zypper $zypper_def_opts addrepo "'$uri'" "'$desc'" fi ;; absent) if [ ! -z "$act_id" ]; then + # Repo present (act_id not ""), so we ned to delete it echo zypper $zypper_def_opts removerepo "$act_id" fi ;; enabled) if [ ! -z "$act_id" ] && [ "$repostate" = "disabled" ]; then + # Repo present (act_id not "") and repostate not enabled, so a enable call is needed echo zypper $zypper_def_opts modifyrepo -e "$act_id" fi ;; disabled) if [ ! -z "$act_id" ] && [ "$repostate" = "enabled" ]; then + # Repo present (act_id not "") and repostate enabled, so a disable call is needed echo zypper $zypper_def_opts modifyrepo -d "$act_id" fi ;;