ssh/deploy-key: Skip chown if the user/group doesn't exist

This matches the behavior of NixOps.

Potential solution to #10.
This commit is contained in:
Zhaofeng Li 2021-02-12 13:54:17 -08:00
parent dbd66d7c7c
commit 95ddbcbfd6

View file

@ -1,15 +1,20 @@
set -euo pipefail set -euo pipefail
destination=%DESTINATION% destination=%DESTINATION%
tmp=$destination.tmp tmp="${destination}.tmp"
user=%USER% user=%USER%
group=%GROUP% group=%GROUP%
permissions=%PERMISSIONS% permissions=%PERMISSIONS%
mkdir -p $(dirname "$destination") mkdir -p $(dirname "$destination")
touch "$tmp" touch "$tmp"
chown "$user:$group" $tmp
chmod "$permissions" $tmp if getent passwd "$user" >/dev/null && getent group "$group" >/dev/null; then
chown "$user:$group" "$tmp"
else
>&2 echo "User $user and/or group $group do not exist. Skipping chown."
fi
chmod "$permissions" "$tmp"
cat <&0 >$tmp cat <&0 >$tmp
mv "$tmp" "$destination" mv "$tmp" "$destination"