From 95ddbcbfd6d2e14b7289971f400b8b411e27502e Mon Sep 17 00:00:00 2001 From: Zhaofeng Li Date: Fri, 12 Feb 2021 13:54:17 -0800 Subject: [PATCH] ssh/deploy-key: Skip chown if the user/group doesn't exist This matches the behavior of NixOps. Potential solution to #10. --- src/nix/host/deploy-key.template | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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"