forked from ungleich-public/cdist
bugfix, if file was absent and type is now tested on openwrt
This commit is contained in:
parent
fa55cd7d3b
commit
38c3d551ba
3 changed files with 17 additions and 2 deletions
|
@ -24,6 +24,12 @@ export key="$(cat "$__object/parameter/key" 2>/dev/null \
|
|||
export state="$(cat "$__object/parameter/state" 2>/dev/null \
|
||||
|| echo "present")"
|
||||
file="$(cat "$__object/parameter/file")"
|
||||
|
||||
if [ ! -f "$file" ]; then
|
||||
echo "nosuchfile"
|
||||
exit
|
||||
fi
|
||||
|
||||
export delimiter="$(cat "$__object/parameter/delimiter")"
|
||||
export value="$(cat "$__object/parameter/value" 2>/dev/null \
|
||||
|| echo "__CDIST_NOTSET__")"
|
||||
|
|
|
@ -44,7 +44,7 @@ fi
|
|||
case "$state_should" in
|
||||
absent)
|
||||
case "$state_is" in
|
||||
absent)
|
||||
absent|nosuchfile)
|
||||
# nothing to do
|
||||
;;
|
||||
wrongformat|wrongvalue|present)
|
||||
|
@ -58,6 +58,9 @@ case "$state_should" in
|
|||
;;
|
||||
present)
|
||||
case "$state_is" in
|
||||
nosuchfile)
|
||||
echo created >> "$__messages_out"
|
||||
;;
|
||||
absent)
|
||||
echo inserted >> "$__messages_out"
|
||||
;;
|
||||
|
@ -104,7 +107,11 @@ export exact_delimiter="$exact_delimiter"
|
|||
|
||||
tmpfile=\$(mktemp "${file}.cdist.XXXXXXXXXX")
|
||||
# preserve ownership and permissions by copying existing file over tmpfile
|
||||
cp -p "$file" "\$tmpfile"
|
||||
if [ -f "$file" ]; then
|
||||
cp -p "$file" "\$tmpfile"
|
||||
else
|
||||
touch "$file"
|
||||
fi
|
||||
awk -f - "$file" >"\$tmpfile" <<"AWK_EOF"
|
||||
BEGIN {
|
||||
# import variables in a secure way ..
|
||||
|
|
|
@ -53,6 +53,8 @@ inserted::
|
|||
A new line was inserted
|
||||
changed::
|
||||
An existing line was changed
|
||||
created::
|
||||
A new line was inserted in a new file
|
||||
|
||||
|
||||
EXAMPLES
|
||||
|
|
Loading…
Reference in a new issue