inital commit of __zypper_service
This commit is contained in:
parent
6bf235c698
commit
0f1dabb080
12 changed files with 335 additions and 0 deletions
24
cdist/conf/type/__zypper_service/explorer/repo_ids
Normal file
24
cdist/conf/type/__zypper_service/explorer/repo_ids
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Manage services with Zypper (mostly suse)
|
||||||
|
#
|
||||||
|
#
|
||||||
|
echo $(zypper lr -u -E | cut -d'|' -f 1 | grep -E '^[0-9]')
|
28
cdist/conf/type/__zypper_service/explorer/service_id
Normal file
28
cdist/conf/type/__zypper_service/explorer/service_id
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# 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 )
|
23
cdist/conf/type/__zypper_service/explorer/service_ids
Normal file
23
cdist/conf/type/__zypper_service/explorer/service_ids
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# Manage services with Zypper (mostly suse)
|
||||||
|
#
|
||||||
|
echo $(zypper ls -u -E | cut -d'|' -f 1 | grep -E '^[0-9]')
|
28
cdist/conf/type/__zypper_service/explorer/service_uri
Normal file
28
cdist/conf/type/__zypper_service/explorer/service_uri
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# 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 )
|
94
cdist/conf/type/__zypper_service/gencode-remote
Normal file
94
cdist/conf/type/__zypper_service/gencode-remote
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# 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
|
67
cdist/conf/type/__zypper_service/man.text
Normal file
67
cdist/conf/type/__zypper_service/man.text
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
cdist-type__zypper_service(7)
|
||||||
|
=============================
|
||||||
|
Daniel Heule <hda--@--sfs.biz>
|
||||||
|
|
||||||
|
|
||||||
|
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).
|
63
cdist/conf/type/__zypper_service/manifest
Normal file
63
cdist/conf/type/__zypper_service/manifest
Normal file
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# 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
|
2
cdist/conf/type/__zypper_service/parameter/boolean
Normal file
2
cdist/conf/type/__zypper_service/parameter/boolean
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
remove-all-other-service
|
||||||
|
remove-all-repos
|
1
cdist/conf/type/__zypper_service/parameter/default/state
Normal file
1
cdist/conf/type/__zypper_service/parameter/default/state
Normal file
|
@ -0,0 +1 @@
|
||||||
|
present
|
1
cdist/conf/type/__zypper_service/parameter/default/type
Normal file
1
cdist/conf/type/__zypper_service/parameter/default/type
Normal file
|
@ -0,0 +1 @@
|
||||||
|
ris
|
3
cdist/conf/type/__zypper_service/parameter/optional
Normal file
3
cdist/conf/type/__zypper_service/parameter/optional
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
service_desc
|
||||||
|
state
|
||||||
|
type
|
1
cdist/conf/type/__zypper_service/parameter/required
Normal file
1
cdist/conf/type/__zypper_service/parameter/required
Normal file
|
@ -0,0 +1 @@
|
||||||
|
service_uri
|
Loading…
Reference in a new issue