Skip to content

Commit 4e18e86

Browse files
Mic92mergify[bot]
authored andcommitted
make sure all facts are set by get-facts
1 parent 2d8325a commit 4e18e86

File tree

1 file changed

+27
-7
lines changed

1 file changed

+27
-7
lines changed

src/nixos-anywhere.sh

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,20 @@ postKexecSshPort=22
3434
buildOnRemote=n
3535
envPassword=n
3636

37+
# Facts set by get-facts.sh
38+
isOs=
39+
isArch=
40+
isKexec=
41+
isInstaller=
42+
isContainer=
43+
hasIpv6Only=
44+
hasTar=
45+
hasSudo=
46+
hasDoas=
47+
hasWget=
48+
hasCurl=
49+
hasSetsid=
50+
3751
sshKeyDir=$(mktemp -d)
3852
trap 'rm -rf "$sshKeyDir"' EXIT
3953
mkdir -p "$sshKeyDir"
@@ -359,19 +373,25 @@ importFacts() {
359373
# make facts available in script
360374
# shellcheck disable=SC2046
361375
export $(echo "$filteredFacts" | xargs)
376+
377+
for var in isOs isArch isKexec isInstaller isContainer hasIpv6Only hasTar hasSudo hasDoas hasWget hasCurl hasSetsid; do
378+
if [[ -z ${!var} ]]; then
379+
abort "Failed to retrieve fact $var from host"
380+
fi
381+
done
362382
}
363383

364384
runKexec() {
365-
if [[ ${isKexec-n} == "y" ]] || [[ ${isInstaller-n} == "y" ]]; then
385+
if [[ ${isKexec} == "y" ]] || [[ ${isInstaller} == "y" ]]; then
366386
return
367387
fi
368388

369-
if [[ ${isContainer-none} != "none" ]]; then
389+
if [[ ${isContainer} != "none" ]]; then
370390
echo "WARNING: This script does not support running from a '${isContainer}' container. kexec will likely not work" >&2
371391
fi
372392

373393
if [[ $kexecUrl == "" ]]; then
374-
case "${isArch-unknown}" in
394+
case "${isArch}" in
375395
x86_64 | aarch64)
376396
kexecUrl="https://github.com/nix-community/nixos-images/releases/download/nixos-24.05/nixos-kexec-installer-noninteractive-${isArch}-linux.tar.gz"
377397
;;
@@ -389,15 +409,15 @@ $maybeSudo mkdir -p /root/kexec
389409
SSH
390410

391411
# no way to reach global ipv4 destinations, use gh-v6.com automatically if github url
392-
if [[ ${hasIpv6Only-n} == "y" ]] && [[ $kexecUrl == "https://github.com/"* ]]; then
412+
if [[ ${hasIpv6Only} == "y" ]] && [[ $kexecUrl == "https://github.com/"* ]]; then
393413
kexecUrl=${kexecUrl/"github.com"/"gh-v6.com"}
394414
fi
395415

396416
if [[ -f $kexecUrl ]]; then
397417
runSsh "${maybeSudo} tar -C /root/kexec -xvzf-" <"$kexecUrl"
398-
elif [[ ${hasCurl-n} == "y" ]]; then
418+
elif [[ ${hasCurl} == "y" ]]; then
399419
runSsh "curl --fail -Ss -L '${kexecUrl}' | ${maybeSudo} tar -C /root/kexec -xvzf-"
400-
elif [[ ${hasWget-n} == "y" ]]; then
420+
elif [[ ${hasWget} == "y" ]]; then
401421
runSsh "wget '${kexecUrl}' -O- | ${maybeSudo} tar -C /root/kexec -xvzf-"
402422
else
403423
curl --fail -Ss -L "${kexecUrl}" | runSsh "${maybeSudo} tar -C /root/kexec -xvzf-"
@@ -560,7 +580,7 @@ main() {
560580
maybeSudo="doas"
561581
fi
562582

563-
if [[ ${isOs-n} != "Linux" ]]; then
583+
if [[ ${isOs} != "Linux" ]]; then
564584
abort "This script requires Linux as the operating system, but got $isOs"
565585
fi
566586

0 commit comments

Comments
 (0)