Merge remote-tracking branch 'sans/master' into dependencies

This commit is contained in:
Nico Schottelius 2011-03-17 13:40:43 +01:00
commit c830597402
19 changed files with 391 additions and 40 deletions

View File

@ -37,7 +37,7 @@ touch "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_parameter_re
touch "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_parameter_optional}"
# Manifest
cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_manifest}"
cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_dir "$__cdist_type")/${__cdist_name_manifest}"
#
# This is the manifest, which can be used to create other objects like this:
@ -50,7 +50,7 @@ cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_parameter_
eof
# Gencode
cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_gencode}"
cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_dir "$__cdist_type")/${__cdist_name_gencode}"
#
# This file should generate code on stdout, which will be collected by cdist
@ -63,4 +63,4 @@ cat "$__cdist_abs_mydir/../doc/dev/header" - << eof > "$(__cdist_type_parameter_
eof
# Explorer
mkdir -p "$(__cdist_type_parameter_dir "$__cdist_type")/${__cdist_name_explorer}"
mkdir -p "$(__cdist_type_dir "$__cdist_type")/${__cdist_name_explorer}"

2
conf/type/__group/TODO Normal file
View File

@ -0,0 +1,2 @@
- delete groups

View File

@ -18,19 +18,10 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# __package is an abstract type which dispatches to the lower level
# __package_$name types which do the actual interaction with the packaging
# system.
# Get an existing groups group entry.
#
# TODO: depend on package gentoolkit for qpkg
name=$__object_id
# TODO:
# if /var/cache/eix is older then /usr/portage/metadata/timestamp
# then run /usr/bin/eix-update
#
# check if package is installed:
#
# get currently installed version:
#
getent group "$name" || true

View File

@ -18,27 +18,10 @@
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
#
#
# Manage packages on gentoo.
# Get an existing groups gshadow entry.
#
if [ -f "$__object/parameter/name" ]; then
name="$(cat "$__object/parameter/name")"
else
name="$__object_id"
fi
name=$__object_id
state="$(cat "$__object/parameter/state")"
getent gshadow "$name" || true
case "$state" in
installed)
# FIXME: only install if not already installed
echo "emerge -q \"$name\""
;;
deinstalled)
# FIXME: only uninstall if currently installed
# FIXME: rename deinstalled to uninstalled
echo "emerge -q -C \"$name\""
;;
esac
exit 0

66
conf/type/__group/gencode Executable file
View File

@ -0,0 +1,66 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
#
# 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 groups.
#
name="$__object_id"
command=
if grep -q "^$name" "$__object/explorer/group"; then
# group exists
command="groupmod"
else
# group does not exist
command="groupadd"
fi
get_current_value() {
local key="$1"
local index
case "$key" in
password)
cut -d':' -f 2 "$__object/explorer/gshadow"
break
;;
gid) index=3;;
esac
cut -d':' -f $index "$__object/explorer/group"
}
set -- "$@"
cd "$__object/parameter"
for property in $(ls .); do
current_value=$(get_current_value "$property")
new_value="$(cat "$property")"
if [ "$new_value" != "$current_value" ]; then
# Shedule changed properties for update
set -- "$@" "--$property" \"$new_value\"
fi
done
if [ $# -gt 0 ]; then
# Update changed properties
echo $command $@ $name
fi

View File

@ -0,0 +1,52 @@
cdist-type__group(7)
===================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__group - Manage groups
DESCRIPTION
-----------
This cdist type allows you to create or modify groups on the target.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
gid::
see groupmod(8)
password::
see above
EXAMPLES
--------
--------------------------------------------------------------------------------
# Create a group 'foobar' with operating system default settings
__group foobar
# Same but with a specific gid
__group foobar --gid 1234
# Same but with a gid and password
__group foobar --gid 1234 --password 'crypted-password-string'
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -0,0 +1,2 @@
gid
password

View File

@ -0,0 +1,61 @@
cdist-type__user(7)
===================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__package - Manage packages
DESCRIPTION
-----------
This cdist type allows you to install or uninstall packages on the target.
It dispatches the actual work to the package system dependant types.
REQUIRED PARAMETERS
-------------------
state::
The state the package should be in, either "installed" or "uninstalled"
OPTIONAL PARAMETERS
-------------------
name::
The name of the package to install. Default is to use the object_id as the
package name.
version::
The version of the package to install. Default is to install the version
choosen by the local package manager.
type::
The package type to use. Default is determined based on the $os explorer
variable.
e.g. __package_apt for Debian
__package_emerge for Gentoo
EXAMPLES
--------
--------------------------------------------------------------------------------
# Install the package vim on the target
__package vim --state installed
# Same but install specific version
__package vim --state installed --version 7.3.50
# Force use of a specific package type
__package vim --state installed --type __package_apt
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -38,7 +38,7 @@ case "$state" in
echo apt-get --quiet --yes install \"$name\"
fi
;;
deinstalled)
uninstalled)
# Remove only if existent
if [ -n "$is_installed" ]; then
echo apt-get --quiet --yes remove \"$name\"

View File

@ -1,2 +0,0 @@
name
version

View File

@ -1 +0,0 @@
state

View File

@ -44,7 +44,7 @@ case "$state" in
echo pacman "$pacopts" -S \"$name\"
fi
;;
deinstalled)
uninstalled)
if [ "$pkg_version" ]; then
echo pacman "$pacopts" -R \"$name\"
fi

2
conf/type/__user/TODO Normal file
View File

@ -0,0 +1,2 @@
- delete users

View File

@ -0,0 +1,27 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
#
# 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/>.
#
#
# Get an existing users passwd entry.
#
name=$__object_id
getent passwd "$name" || true

View File

@ -0,0 +1,27 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
#
# 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/>.
#
#
# Get an existing users shadow entry.
#
name=$__object_id
getent shadow "$name" || true

70
conf/type/__user/gencode Executable file
View File

@ -0,0 +1,70 @@
#!/bin/sh
#
# 2011 Steven Armstrong (steven-cdist at armstrong.cc)
#
# 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 users.
#
name="$__object_id"
command=
if grep -q "^$name" "$__object/explorer/passwd"; then
# user exists
command="usermod"
else
# user does not exist
command="useradd"
fi
get_current_value() {
local key="$1"
local index
case "$key" in
password)
cut -d':' -f 2 "$__object/explorer/shadow"
break
;;
uid) index=3;;
gid) index=4;;
comment) index=5;;
home) index=6;;
shell) index=7;;
esac
cut -d':' -f $index "$__object/explorer/passwd"
}
set -- "$@"
cd "$__object/parameter"
for property in $(ls .); do
current_value=$(get_current_value "$property")
new_value="$(cat "$property")"
if [ "$new_value" != "$current_value" ]; then
# Shedule changed properties for update
set -- "$@" "--$property" \"$new_value\"
fi
done
if [ $# -gt 0 ]; then
# Update changed properties
echo $command $@ $name
fi

62
conf/type/__user/man.text Normal file
View File

@ -0,0 +1,62 @@
cdist-type__user(7)
===================
Steven Armstrong <steven-cdist--@--armstrong.cc>
NAME
----
cdist-type__user - Manage users
DESCRIPTION
-----------
This cdist type allows you to create or modify users on the target.
REQUIRED PARAMETERS
-------------------
None.
OPTIONAL PARAMETERS
-------------------
comment::
see usermod(8)
home::
see above
gid::
see above
groups::
see above
password::
see above
shell::
see above
uid::
see above
EXAMPLES
--------
--------------------------------------------------------------------------------
# Create user account for foobar with operating system default settings
__user foobar
# Same but with a different shell
__user foobar --shell /bin/zsh
# Set explicit uid and home
__user foobar --uid 1001 --shell /bin/zsh --home /home/foobar
--------------------------------------------------------------------------------
SEE ALSO
--------
- cdist-type(7)
COPYING
-------
Copyright \(C) 2011 Steven Armstrong. Free use of this software is
granted under the terms of the GNU General Public License version 3 (GPLv3).

View File

@ -0,0 +1,7 @@
comment
home
gid
groups
password
shell
uid

View File

@ -9,6 +9,8 @@
* New type __motd
* New type __addifnosuchline (Daniel Roth)
* Document type __issue
* New type __user
* Document type __package
* Document type __package_pacman
* Document type __package_apt
* New parameter for __file: --owner and --group