forked from ungleich-public/cdist
add --create and --ifexists options to line
This commit is contained in:
parent
d4bf41ce3b
commit
a379bfc742
5 changed files with 20 additions and 2 deletions
2
cdist/conf/type/__line/boolean
Normal file
2
cdist/conf/type/__line/boolean
Normal file
|
@ -0,0 +1,2 @@
|
|||
create
|
||||
ifexists
|
|
@ -34,8 +34,16 @@ state_should="$(cat "$__object/parameter/state")"
|
|||
state_is="$(cat "$__object/explorer/state")"
|
||||
|
||||
if [ -z "$state_is" ]; then
|
||||
printf 'The file "%s" is missing. Please create it before using %s on it.\n' "$file" "${__type##*/}" >&2
|
||||
exit 1
|
||||
if [ -f "$__object/parameter/create" ]; then
|
||||
echo "touch $file"
|
||||
else
|
||||
# only bark if the file should exists
|
||||
if [ -f "$__object/parameter/ifexists" ]; then
|
||||
exit 0
|
||||
fi
|
||||
printf 'The file "%s" is missing. Please create it before using %s on it.\n' "$file" "${__type##*/}" >&2
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$state_should" = "$state_is" ] || \
|
||||
|
|
|
@ -21,6 +21,9 @@ OPTIONAL PARAMETERS
|
|||
after
|
||||
Insert the given line after this pattern.
|
||||
|
||||
create
|
||||
It the file does not exist then create an empty file
|
||||
|
||||
before
|
||||
Insert the given line before this pattern.
|
||||
|
||||
|
@ -28,6 +31,9 @@ file
|
|||
If supplied, use this as the destination file.
|
||||
Otherwise the object_id is used.
|
||||
|
||||
ifexists
|
||||
Only apply the line if the file exists.
|
||||
|
||||
line
|
||||
Specifies the line which should be absent or present.
|
||||
|
||||
|
|
1
cdist/conf/type/__line/parameter/default/create
Normal file
1
cdist/conf/type/__line/parameter/default/create
Normal file
|
@ -0,0 +1 @@
|
|||
false
|
1
cdist/conf/type/__line/parameter/default/ifexists
Normal file
1
cdist/conf/type/__line/parameter/default/ifexists
Normal file
|
@ -0,0 +1 @@
|
|||
false
|
Loading…
Reference in a new issue