forked from ungleich-public/cdist
add --state parameter to __directory type which allows removal of directories
Signed-off-by: Steven Armstrong <steven@icarus.ethz.ch>
This commit is contained in:
parent
76f07511a9
commit
37612ff102
4 changed files with 80 additions and 32 deletions
|
@ -25,7 +25,10 @@
|
||||||
#
|
#
|
||||||
|
|
||||||
destination="/$__object_id"
|
destination="/$__object_id"
|
||||||
|
state_should="$(cat "$__object/parameter/state")"
|
||||||
|
|
||||||
|
case "$state_should" in
|
||||||
|
present)
|
||||||
# Include parent directories?
|
# Include parent directories?
|
||||||
if [ -f "$__object/parameter/parents" ]; then
|
if [ -f "$__object/parameter/parents" ]; then
|
||||||
parents="$(cat "$__object/parameter/parents")"
|
parents="$(cat "$__object/parameter/parents")"
|
||||||
|
@ -61,3 +64,16 @@ fi
|
||||||
if [ -f "$__object/parameter/owner" ]; then
|
if [ -f "$__object/parameter/owner" ]; then
|
||||||
echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\"
|
echo chown $recursive \"$(cat "$__object/parameter/owner")\" \"$destination\"
|
||||||
fi
|
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
|
NAME
|
||||||
----
|
----
|
||||||
cdist-type__directory - Create a directory
|
cdist-type__directory - Manage a directory
|
||||||
|
|
||||||
|
|
||||||
DESCRIPTION
|
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
|
REQUIRED PARAMETERS
|
||||||
|
@ -20,6 +20,9 @@ None.
|
||||||
|
|
||||||
OPTIONAL PARAMETERS
|
OPTIONAL PARAMETERS
|
||||||
-------------------
|
-------------------
|
||||||
|
state::
|
||||||
|
'present' or 'absent', defaults to 'present'
|
||||||
|
|
||||||
group::
|
group::
|
||||||
Group to chgrp to.
|
Group to chgrp to.
|
||||||
|
|
||||||
|
@ -45,6 +48,9 @@ EXAMPLES
|
||||||
# A silly example
|
# A silly example
|
||||||
__directory /tmp/foobar
|
__directory /tmp/foobar
|
||||||
|
|
||||||
|
# Remove a directory
|
||||||
|
__directory /tmp/foobar --ensure absent
|
||||||
|
|
||||||
# Ensure /etc exists correctly
|
# Ensure /etc exists correctly
|
||||||
__directory /etc --owner root --group root --mode 0755
|
__directory /etc --owner root --group root --mode 0755
|
||||||
|
|
||||||
|
|
25
conf/type/__directory/manifest
Executable file
25
conf/type/__directory/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/>.
|
||||||
|
#
|
||||||
|
|
||||||
|
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