Merge pull request #219 from asteven/issue/219
__key_value removes quotes from values
This commit is contained in:
commit
6f4881a9a9
1 changed files with 18 additions and 9 deletions
|
@ -26,8 +26,8 @@ state_should=present
|
||||||
|
|
||||||
file="$(cat "$__object/parameter/file")"
|
file="$(cat "$__object/parameter/file")"
|
||||||
delimiter="$(cat "$__object/parameter/delimiter")"
|
delimiter="$(cat "$__object/parameter/delimiter")"
|
||||||
value="$(cat "$__object/parameter/value")"
|
# escape double quotes, as that is what we use ourself below
|
||||||
|
value_escaped="$(cat "$__object/parameter/value" | sed -e "s/\([\"]\)/\\\\\1/g")"
|
||||||
state_is="$(cat "$__object/explorer/state")"
|
state_is="$(cat "$__object/explorer/state")"
|
||||||
|
|
||||||
[ "$state_is" = "$state_should" ] && exit 0
|
[ "$state_is" = "$state_should" ] && exit 0
|
||||||
|
@ -35,20 +35,29 @@ state_is="$(cat "$__object/explorer/state")"
|
||||||
case "$state_should" in
|
case "$state_should" in
|
||||||
absent)
|
absent)
|
||||||
# remove lines starting with key
|
# remove lines starting with key
|
||||||
echo "sed '/^$key\($delimiter\+\)/d' \"$file\" > \"$file.cdist-tmp\""
|
cat << DONE
|
||||||
echo "mv \"$file.cdist-tmp\" \"$file\""
|
tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
|
||||||
|
# preserve ownership and permissions by copying existing file over tmpfile
|
||||||
|
cp -p "$file" "\$tmpfile"
|
||||||
|
sed '/^$key\($delimiter\+\)/d' "$file" > "\$tmpfile"
|
||||||
|
mv -f "\$tmpfile" "$file"
|
||||||
|
DONE
|
||||||
;;
|
;;
|
||||||
present)
|
present)
|
||||||
case "$state_is" in
|
case "$state_is" in
|
||||||
absent)
|
absent)
|
||||||
# add new key and value
|
# add new key and value
|
||||||
echo "echo \"${key}${delimiter}${value}\" >> \"$file\""
|
printf 'echo "%s%s%s" >> "%s"' "$key" "$delimiter" "$value_escaped" "$file"
|
||||||
;;
|
;;
|
||||||
wrongvalue)
|
wrongvalue)
|
||||||
# change exisiting value
|
# change exisiting value
|
||||||
printf 'sed "s|^%s\(%s\+\).*|%s\\1%s|" "%s" > "%s.cdist-tmp"\n' \
|
cat << DONE
|
||||||
"$key" "$delimiter" "$key" "$value" "$file" "$file"
|
tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
|
||||||
echo "mv \"$file.cdist-tmp\" \"$file\""
|
# preserve ownership and permissions by copying existing file over tmpfile
|
||||||
|
cp -p "$file" "\$tmpfile"
|
||||||
|
sed "s|^$key\($delimiter\+\).*|$key\\1$value_escaped|" "$file" > "\$tmpfile"
|
||||||
|
mv -f "\$tmpfile" "$file"
|
||||||
|
DONE
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo "Unknown explorer state: $state_is" >&2
|
echo "Unknown explorer state: $state_is" >&2
|
||||||
|
@ -58,4 +67,4 @@ case "$state_should" in
|
||||||
*)
|
*)
|
||||||
echo "Unknown state: $state_should" >&2
|
echo "Unknown state: $state_should" >&2
|
||||||
exit 1
|
exit 1
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue