Merge branch 'fix/type/__ssh_authorized_key/grep-only-if-file-exists' into 'master'

__ssh_authorized_key: only grep if file exists

See merge request ungleich-public/cdist!979
This commit is contained in:
poljakowski 2021-03-10 19:24:23 +01:00
commit 2f4a7e1a94
2 changed files with 3 additions and 2 deletions

View file

@ -25,6 +25,7 @@ type_and_key="$(tr ' ' '\n' < "$__object/parameter/key"| awk '/^(ssh|ecdsa)-[^ ]
if [ -n "${type_and_key}" ] if [ -n "${type_and_key}" ]
then then
file="$(cat "$__object/parameter/file")" file="$(cat "$__object/parameter/file")"
test -e "$file" || exit 0
# get any entries that match the type and key # get any entries that match the type and key

View file

@ -37,9 +37,9 @@ tmpfile=\$(mktemp ${file}.cdist.XXXXXXXXXX)
# preserve ownership and permissions of existing file # preserve ownership and permissions of existing file
if [ -f "$file" ]; then if [ -f "$file" ]; then
cp -p "$file" "\$tmpfile" cp -p "$file" "\$tmpfile"
grep -v -F -x '$line' '$file' >\$tmpfile
fi fi
grep -v -F -x '$line' '$file' > \$tmpfile || true cat "\$tmpfile" >"$file"
mv -f "\$tmpfile" "$file"
DONE DONE
} }