Merge branch 'filestate' of git://github.com/asteven/cdist
This commit is contained in:
commit
7a6ebd2c6d
13 changed files with 197 additions and 74 deletions
|
@ -17,47 +17,57 @@
|
|||
# You should have received a copy of the GNU General Public License
|
||||
# along with cdist. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
#
|
||||
# Handle directories
|
||||
#
|
||||
#
|
||||
# __directory /etc [--mode --owner --group --parents [yes|no] ]
|
||||
#
|
||||
|
||||
destination="/$__object_id"
|
||||
state_should="$(cat "$__object/parameter/state")"
|
||||
|
||||
# Include parent directories?
|
||||
if [ -f "$__object/parameter/parents" ]; then
|
||||
parents="$(cat "$__object/parameter/parents")"
|
||||
if [ yes = "$parents" ]; then
|
||||
mkdiropt="-p"
|
||||
else
|
||||
mkdiropt=""
|
||||
fi
|
||||
fi
|
||||
case "$state_should" in
|
||||
present)
|
||||
# Include parent directories?
|
||||
if [ -f "$__object/parameter/parents" ]; then
|
||||
parents="$(cat "$__object/parameter/parents")"
|
||||
if [ yes = "$parents" ]; then
|
||||
mkdiropt="-p"
|
||||
else
|
||||
mkdiropt=""
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -f "$__object/parameter/recursive" ]; then
|
||||
if [ yes = "$(cat "$__object/parameter/recursive")" ]; then
|
||||
recursive="-R"
|
||||
fi
|
||||
fi
|
||||
if [ -f "$__object/parameter/recursive" ]; then
|
||||
if [ yes = "$(cat "$__object/parameter/recursive")" ]; then
|
||||
recursive="-R"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Only create if not already existent
|
||||
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
||||
echo mkdir $mkdiropt \"$destination\"
|
||||
fi
|
||||
# Only create if not already existent
|
||||
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
||||
echo mkdir $mkdiropt \"$destination\"
|
||||
fi
|
||||
|
||||
# Mode settings
|
||||
if [ -f "$__object/parameter/mode" ]; then
|
||||
echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
|
||||
fi
|
||||
# Mode settings
|
||||
if [ -f "$__object/parameter/mode" ]; then
|
||||
echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
|
||||
fi
|
||||
|
||||
# Group
|
||||
if [ -f "$__object/parameter/group" ]; then
|
||||
echo chgrp $recursive \"$(cat "$__object/parameter/group")\" \"$destination\"
|
||||
fi
|
||||
# Group
|
||||
if [ -f "$__object/parameter/group" ]; then
|
||||
echo chgrp $recursive \"$(cat "$__object/parameter/group")\" \"$destination\"
|
||||
fi
|
||||
|
||||
# Owner
|
||||
if [ -f "$__object/parameter/owner" ]; then
|
||||
echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\"
|
||||
fi
|
||||
# Owner
|
||||
if [ -f "$__object/parameter/owner" ]; then
|
||||
echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\"
|
||||
fi
|
||||
;;
|
||||
absent)
|
||||
# Only delete if it exists
|
||||
if [ yes = "$(cat "$__object/explorer/exists")" ]; then
|
||||
echo rm -r \"$destination\"
|
||||
fi
|
||||
|
||||
;;
|
||||
*)
|
||||
echo "Unknown state" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
|
@ -5,12 +5,12 @@ Nico Schottelius <nico-cdist--@--schottelius.org>
|
|||
|
||||
NAME
|
||||
----
|
||||
cdist-type__directory - Create a directory
|
||||
cdist-type__directory - Manage a directory
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This cdist type allows you to create directories on the target.
|
||||
This cdist type allows you to create or remove directories on the target.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
|
@ -20,6 +20,9 @@ None.
|
|||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
state::
|
||||
'present' or 'absent', defaults to 'present'
|
||||
|
||||
group::
|
||||
Group to chgrp to.
|
||||
|
||||
|
@ -45,6 +48,9 @@ EXAMPLES
|
|||
# A silly example
|
||||
__directory /tmp/foobar
|
||||
|
||||
# Remove a directory
|
||||
__directory /tmp/foobar --ensure absent
|
||||
|
||||
# Ensure /etc exists correctly
|
||||
__directory /etc --owner root --group root --mode 0755
|
||||
|
||||
|
|
23
conf/type/__directory/manifest
Executable file
23
conf/type/__directory/manifest
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/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/>.
|
||||
#
|
||||
|
||||
# set defaults
|
||||
state="$(cat "$__object/parameter/state" 2>/dev/null \
|
||||
|| echo "present" | tee "$__object/parameter/state")"
|
|
@ -1,3 +1,4 @@
|
|||
state
|
||||
group
|
||||
mode
|
||||
owner
|
||||
|
|
|
@ -22,19 +22,22 @@
|
|||
#
|
||||
|
||||
destination="/$__object_id"
|
||||
state_should="$(cat "$__object/parameter/state")"
|
||||
|
||||
if [ -f "$__object/parameter/source" ]; then
|
||||
source="$(cat "$__object/parameter/source")"
|
||||
if [ "$state_should" = "present" ]; then
|
||||
if [ -f "$__object/parameter/source" ]; then
|
||||
source="$(cat "$__object/parameter/source")"
|
||||
|
||||
if [ -f "$source" ]; then
|
||||
local_cksum="$(cksum < "$source")"
|
||||
remote_cksum="$(cat "$__object/explorer/cksum")"
|
||||
if [ -f "$source" ]; then
|
||||
local_cksum="$(cksum < "$source")"
|
||||
remote_cksum="$(cat "$__object/explorer/cksum")"
|
||||
|
||||
if [ "$local_cksum" != "$remote_cksum" ]; then
|
||||
echo "$__remote_copy" "$source" "${__target_host}:${destination}"
|
||||
if [ "$local_cksum" != "$remote_cksum" ]; then
|
||||
echo "$__remote_copy" "$source" "${__target_host}:${destination}"
|
||||
fi
|
||||
else
|
||||
echo "Source \"$source\" does not exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "Source \"$source\" does not exist." >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
|
|
@ -22,25 +22,33 @@
|
|||
#
|
||||
|
||||
destination="/$__object_id"
|
||||
state_should="$(cat "$__object/parameter/state")"
|
||||
exists="$(cat "$__object/explorer/exists")"
|
||||
|
||||
# No source? Create empty file
|
||||
if [ ! -f "$__object/parameter/source" ]; then
|
||||
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
||||
echo touch \"$destination\"
|
||||
if [ "$state_should" = "present" ]; then
|
||||
# No source? Create empty file
|
||||
if [ ! -f "$__object/parameter/source" ]; then
|
||||
if [ "$exists" = "no" ]; then
|
||||
echo touch \"$destination\"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Mode settings
|
||||
if [ -f "$__object/parameter/mode" ]; then
|
||||
echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
|
||||
fi
|
||||
|
||||
# Group
|
||||
if [ -f "$__object/parameter/group" ]; then
|
||||
echo chgrp \"$(cat "$__object/parameter/group")\" \"$destination\"
|
||||
fi
|
||||
|
||||
# Owner
|
||||
if [ -f "$__object/parameter/owner" ]; then
|
||||
echo chown \"$(cat "$__object/parameter/owner")\" \"$destination\"
|
||||
fi
|
||||
elif [ "$state_should" = "absent" ]; then
|
||||
if [ "$exists" = "yes" ]; then
|
||||
echo rm -f \"$destination\"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Mode settings
|
||||
if [ -f "$__object/parameter/mode" ]; then
|
||||
echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
|
||||
fi
|
||||
|
||||
# Group
|
||||
if [ -f "$__object/parameter/group" ]; then
|
||||
echo chgrp \"$(cat "$__object/parameter/group")\" \"$destination\"
|
||||
fi
|
||||
|
||||
# Owner
|
||||
if [ -f "$__object/parameter/owner" ]; then
|
||||
echo chown \"$(cat "$__object/parameter/owner")\" \"$destination\"
|
||||
fi
|
||||
|
|
|
@ -5,21 +5,24 @@ Nico Schottelius <nico-cdist--@--schottelius.org>
|
|||
|
||||
NAME
|
||||
----
|
||||
cdist-type__file - Create files
|
||||
cdist-type__file - Manage files
|
||||
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
This cdist type allows you to create files on the target.
|
||||
This cdist type allows you to create files, remove files and set file
|
||||
attributes on the target.
|
||||
|
||||
|
||||
REQUIRED PARAMETERS
|
||||
-------------------
|
||||
None.
|
||||
|
||||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
state::
|
||||
'present' or 'absent', defaults to 'present'
|
||||
|
||||
group::
|
||||
Group to chgrp to.
|
||||
|
||||
|
@ -40,13 +43,18 @@ EXAMPLES
|
|||
--------------------------------------------------------------------------------
|
||||
# Create /etc/cdist-configured as an empty file
|
||||
__file /etc/cdist-configured
|
||||
# The same thing
|
||||
__file /etc/cdist-configured --ensure present
|
||||
# Delete existing file
|
||||
__file /etc/cdist-configured --ensure absent
|
||||
|
||||
# Use __file from another type
|
||||
__file /etc/issue --source "$__type/files/archlinux"
|
||||
__file /etc/issue --source "$__type/files/archlinux" --ensure present
|
||||
|
||||
# Supply some more settings
|
||||
__file /etc/shadow --source "$__type/files/shadow" \
|
||||
--owner root --group shadow --mode 0640
|
||||
--owner root --group shadow --mode 0640 \
|
||||
--ensure present
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
||||
|
|
25
conf/type/__file/manifest
Executable file
25
conf/type/__file/manifest
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/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/>.
|
||||
#
|
||||
|
||||
name="$__object_id"
|
||||
|
||||
# set defaults
|
||||
state="$(cat "$__object/parameter/state" 2>/dev/null \
|
||||
|| echo "present" | tee "$__object/parameter/state")"
|
|
@ -1,3 +1,4 @@
|
|||
state
|
||||
group
|
||||
mode
|
||||
owner
|
||||
|
|
|
@ -39,4 +39,17 @@ case "$type" in
|
|||
;;
|
||||
esac
|
||||
|
||||
echo ln ${lnopt} -f \"$source\" \"$destination\"
|
||||
state_should="$(cat "$__object/parameter/state")"
|
||||
case "$state_should" in
|
||||
present)
|
||||
echo ln ${lnopt} -f \"$source\" \"$destination\"
|
||||
;;
|
||||
absent)
|
||||
echo rm -f \"$destination\"
|
||||
;;
|
||||
*)
|
||||
echo "Unknown state" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
|
|
|
@ -25,7 +25,8 @@ type::
|
|||
|
||||
OPTIONAL PARAMETERS
|
||||
-------------------
|
||||
None.
|
||||
state::
|
||||
'present' or 'absent', defaults to 'present'
|
||||
|
||||
|
||||
EXAMPLES
|
||||
|
|
23
conf/type/__link/manifest
Executable file
23
conf/type/__link/manifest
Executable file
|
@ -0,0 +1,23 @@
|
|||
#!/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/>.
|
||||
#
|
||||
|
||||
# set defaults
|
||||
state="$(cat "$__object/parameter/state" 2>/dev/null \
|
||||
|| echo "present" | tee "$__object/parameter/state")"
|
1
conf/type/__link/parameter/optional
Normal file
1
conf/type/__link/parameter/optional
Normal file
|
@ -0,0 +1 @@
|
|||
state
|
Loading…
Reference in a new issue