From 30cc2e4f158889cd9f1deaacccb9ebd516677edf Mon Sep 17 00:00:00 2001 From: clerie Date: Fri, 20 Oct 2023 22:14:00 +0200 Subject: [PATCH] pkgs/nixfiles: update ssh host keys only if they are not empty --- pkgs/nixfiles/nixfiles-update-ssh-host-keys.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/nixfiles/nixfiles-update-ssh-host-keys.sh b/pkgs/nixfiles/nixfiles-update-ssh-host-keys.sh index e1298f4..ef27713 100755 --- a/pkgs/nixfiles/nixfiles-update-ssh-host-keys.sh +++ b/pkgs/nixfiles/nixfiles-update-ssh-host-keys.sh @@ -4,5 +4,9 @@ cd "$(git rev-parse --show-toplevel)" for host in $(nix eval --apply 'attrs: builtins.concatStringsSep "\n" (builtins.filter (name: (builtins.substring 0 1 name) != "_") (builtins.attrNames attrs))' --raw .#clerie.hosts); do echo "$host" - ssh-keyscan -t ed25519 "${host}.net.clerie.de" 2>/dev/null | sed -E 's/(\S+) (.+)/\2/g' > "hosts/${host}/ssh.pub" + ssh_key=$(ssh-keyscan -t ed25519 "${host}.net.clerie.de" 2>/dev/null | sed -E 's/(\S+) (.+)/\2/g' || true) + if [[ -n "$ssh_key" ]]; then + echo "$ssh_key" + echo "$ssh_key" > "hosts/${host}/ssh.pub" + fi done