From 92e0ef6bf261af47dc400d28ff87aeb7a0e1ae2d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Thalheim?= Date: Sun, 22 Jan 2023 09:36:29 +0100 Subject: [PATCH] handle error case better when facts return no results back --- src/nixos-remote.sh | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/src/nixos-remote.sh b/src/nixos-remote.sh index 05e45df..e68bc59 100755 --- a/src/nixos-remote.sh +++ b/src/nixos-remote.sh @@ -171,12 +171,10 @@ else abort "flake must be set" fi -# wait for machine to become reachable (possibly forever) -# TODO we probably need an architecture detection here -# TODO if we have specified a user here but we are already booted into the -# installer, than the user might not work anymore -until facts=$( - ssh_ -o ConnectTimeout=10 -- </dev/null && echo "y" || echo "n" @@ -194,13 +192,23 @@ has_wget=\$(has wget) has_curl=\$(has curl) FACTS SSH -); do + ); then + return 1 + fi + filtered_facts=$(echo "$facts" | grep -E '^(has|is)_[a-z0-9_]+=\S+') + if [[ -z "$filtered_facts" ]]; then + abort "Retrieving host facts via ssh failed. Check with --debug for the root cause, unless you have done so already" + fi + # make facts available in script + # shellcheck disable=SC2046 + export $(echo "$filtered_facts" | xargs) +} + +# wait for machine to become reachable (possibly forever) +until import_facts; do sleep 5 done -# make facts available in script -# shellcheck disable=SC2046 -export $(echo "$facts" | grep -E '^(has|is)_[a-z0-9_]+=\S+' | xargs) if [[ ${has_tar-n} == "n" ]]; then abort "no tar command found, but required to unpack kexec tarball"