add --state parameter to __file type which allows removal of files
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
c631a609ed
commit
76f07511a9
5 changed files with 85 additions and 38 deletions
|
@ -22,8 +22,10 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
destination="/$__object_id"
|
destination="/$__object_id"
|
||||||
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
if [ -f "$__object/parameter/source" ]; then
|
if [ "$state_should" = "present" ]; then
|
||||||
|
if [ -f "$__object/parameter/source" ]; then
|
||||||
source="$(cat "$__object/parameter/source")"
|
source="$(cat "$__object/parameter/source")"
|
||||||
|
|
||||||
if [ -f "$source" ]; then
|
if [ -f "$source" ]; then
|
||||||
|
@ -41,4 +43,5 @@ if [ -f "$__object/parameter/source" ]; then
|
||||||
echo "Source \"$source\" does not exist." >&2
|
echo "Source \"$source\" does not exist." >&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -22,25 +22,33 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
destination="/$__object_id"
|
destination="/$__object_id"
|
||||||
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
|
exists="$(cat "$__object/explorer/exists")"
|
||||||
|
|
||||||
# No source? Create empty file
|
if [ "$state_should" = "present" ]; then
|
||||||
if [ ! -f "$__object/parameter/source" ]; then
|
# No source? Create empty file
|
||||||
if [ no = "$(cat "$__object/explorer/exists")" ]; then
|
if [ ! -f "$__object/parameter/source" ]; then
|
||||||
|
if [ "$exists" = "no" ]; then
|
||||||
echo touch \"$destination\"
|
echo touch \"$destination\"
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Mode settings
|
# Mode settings
|
||||||
if [ -f "$__object/parameter/mode" ]; then
|
if [ -f "$__object/parameter/mode" ]; then
|
||||||
echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
|
echo chmod \"$(cat "$__object/parameter/mode")\" \"$destination\"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Group
|
# Group
|
||||||
if [ -f "$__object/parameter/group" ]; then
|
if [ -f "$__object/parameter/group" ]; then
|
||||||
echo chgrp \"$(cat "$__object/parameter/group")\" \"$destination\"
|
echo chgrp \"$(cat "$__object/parameter/group")\" \"$destination\"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Owner
|
# Owner
|
||||||
if [ -f "$__object/parameter/owner" ]; then
|
if [ -f "$__object/parameter/owner" ]; then
|
||||||
echo chown \"$(cat "$__object/parameter/owner")\" \"$destination\"
|
echo chown \"$(cat "$__object/parameter/owner")\" \"$destination\"
|
||||||
|
fi
|
||||||
|
elif [ "$state_should" = "absent" ]; then
|
||||||
|
if [ "$exists" = "yes" ]; then
|
||||||
|
echo rm \"$destination\"
|
||||||
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
|
@ -5,21 +5,24 @@ Nico Schottelius <nico-cdist--@--schottelius.org>
|
||||||
|
|
||||||
NAME
|
NAME
|
||||||
----
|
----
|
||||||
cdist-type__file - Create files
|
cdist-type__file - Manage files
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
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
|
REQUIRED PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
None.
|
None.
|
||||||
|
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
|
state::
|
||||||
|
'present' or 'absent', defaults to 'present'
|
||||||
|
|
||||||
group::
|
group::
|
||||||
Group to chgrp to.
|
Group to chgrp to.
|
||||||
|
|
||||||
|
@ -40,13 +43,18 @@ EXAMPLES
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
# Create /etc/cdist-configured as an empty file
|
# Create /etc/cdist-configured as an empty file
|
||||||
__file /etc/cdist-configured
|
__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
|
# 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
|
# Supply some more settings
|
||||||
__file /etc/shadow --source "$__type/files/shadow" \
|
__file /etc/shadow --source "$__type/files/shadow" \
|
||||||
--owner root --group shadow --mode 0640
|
--owner root --group shadow --mode 0640 \
|
||||||
|
--ensure present
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
27
conf/type/__file/manifest
Executable file
27
conf/type/__file/manifest
Executable 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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
name="$__object_id"
|
||||||
|
|
||||||
|
if [ -f "$__object/parameter/state" ]; then
|
||||||
|
state="$(cat "$__object/parameter/state")"
|
||||||
|
else
|
||||||
|
echo "present" > "$__object/parameter/state"
|
||||||
|
fi
|
|
@ -1,3 +1,4 @@
|
||||||
|
state
|
||||||
group
|
group
|
||||||
mode
|
mode
|
||||||
owner
|
owner
|
||||||
|
|
Loading…
Reference in a new issue