diff --git a/src/nix/host/deploy-key.template b/src/nix/host/deploy-key.template index 339e59f..a0f94d2 100644 --- a/src/nix/host/deploy-key.template +++ b/src/nix/host/deploy-key.template @@ -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"