Skip to content

Commit 68ef34d

Browse files
committed
kexec: support other compression than gzip
Also make compatible to the upstream nixpkgs kexec tarball format
1 parent b21cc6a commit 68ef34d

File tree

1 file changed

+25
-5
lines changed

1 file changed

+25
-5
lines changed

src/nixos-anywhere.sh

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,18 +630,38 @@ SSH
630630
kexecUrl=${kexecUrl/"github.com"/"gh-v6.com"}
631631
fi
632632
633+
# gnu tar cannot automatically detect the compression when decompressing via stdin
634+
tarDecomp=""
635+
if [[ ${kexecUrl} =~ \.tar\.gz$ ]]; then
636+
tarDecomp="--gzip"
637+
elif [[ ${kexecUrl} =~ \.tar\.xz$ ]]; then
638+
tarDecomp="--xz"
639+
elif [[ ${kexecUrl} =~ \.tar\.zstd$ ]]; then
640+
tarDecomp="--zstd"
641+
elif [[ ${kexecUrl} =~ \.tar$ ]]; then
642+
tarDecomp=""
643+
fi
644+
633645
if [[ -f $kexecUrl ]]; then
634-
runSsh "${maybeSudo} tar -C /root/kexec -xvzf-" <"$kexecUrl"
646+
runSsh "${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}" <"$kexecUrl"
635647
elif [[ ${hasCurl} == "y" ]]; then
636-
runSsh "curl --fail -Ss -L '${kexecUrl}' | ${maybeSudo} tar -C /root/kexec -xvzf-"
648+
runSsh "curl --fail -Ss -L '${kexecUrl}' | ${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
637649
elif [[ ${hasWget} == "y" ]]; then
638-
runSsh "wget '${kexecUrl}' -O- | ${maybeSudo} tar -C /root/kexec -xvzf-"
650+
runSsh "wget '${kexecUrl}' -O- | ${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
639651
else
640-
curl --fail -Ss -L "${kexecUrl}" | runSsh "${maybeSudo} tar -C /root/kexec -xvzf-"
652+
curl --fail -Ss -L "${kexecUrl}" | runSsh "${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
641653
fi
642654
643655
runSsh <<SSH
644-
TMPDIR=/root/kexec setsid ${maybeSudo} /root/kexec/kexec/run --kexec-extra-flags "${kexecExtraFlags}"
656+
if [[ -e /root/kexec/kexec/run ]]; then
657+
TMPDIR=/root/kexec setsid ${maybeSudo} /root/kexec/kexec/run --kexec-extra-flags "${kexecExtraFlags}"
658+
elif [[ -e /root/kexec/kexec-boot ]]; then
659+
# upstream kexecTarball format
660+
TMPDIR=/root/kexec setsid ${maybeSudo} /root/kexec/kexec-boot --kexec-extra-flags "${kexecExtraFlags}"
661+
else
662+
echo "No kexec script found in /root/kexec/kexec/run or /root/kexec/kexec-boot" >&2
663+
exit 1
664+
fi
645665
SSH
646666
647667
# use the default SSH port to connect at this point

0 commit comments

Comments
 (0)