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:
parent
dbd66d7c7c
commit
95ddbcbfd6
1 changed files with 9 additions and 4 deletions
|
@ -1,15 +1,20 @@
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
destination=%DESTINATION%
|
||||
tmp=$destination.tmp
|
||||
tmp="${destination}.tmp"
|
||||
user=%USER%
|
||||
group=%GROUP%
|
||||
permissions=%PERMISSIONS%
|
||||
|
||||
mkdir -p $(dirname "$destination")
|
||||
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
|
||||
mv "$tmp" "$destination"
|
||||
|
|
Loading…
Reference in a new issue