Skip to content

Commit eee38aa

Browse files
DavHauEnzime
authored andcommitted
kexec: support other compression than gzip
1 parent 94c3849 commit eee38aa

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/nixos-anywhere.sh

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,18 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr
671671
local localUploadCommand=()
672672
local remoteUploadCommand=()
673673
674+
# gnu tar cannot automatically detect the compression when decompressing via stdin
675+
tarDecomp=""
676+
if [[ ${kexecUrl} =~ \.tar\.gz$ ]]; then
677+
tarDecomp="--gzip"
678+
elif [[ ${kexecUrl} =~ \.tar\.xz$ ]]; then
679+
tarDecomp="--xz"
680+
elif [[ ${kexecUrl} =~ \.tar\.zstd$ ]]; then
681+
tarDecomp="--zstd"
682+
elif [[ ${kexecUrl} =~ \.tar$ ]]; then
683+
tarDecomp=""
684+
fi
685+
674686
if [[ -f $kexecUrl ]]; then
675687
localUploadCommand=(cat "$kexecUrl")
676688
elif [[ $hasWget == "y" ]]; then
@@ -686,14 +698,14 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr
686698
local remoteCommands
687699
if [[ ${#localUploadCommand[@]} -eq 0 ]]; then
688700
# Use remote command for download and execution
689-
tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | ${maybeSudo} tar -C /root/kexec -xvzf-"
701+
tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | ${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
690702
691703
remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand}
692704
693705
runSsh sh -c "$(printf '%q' "$remoteCommands")"
694706
else
695707
# Use local command with pipe to remote
696-
tarCommand="${maybeSudo} tar -C /root/kexec -xvzf-"
708+
tarCommand="${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
697709
remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand}
698710
699711
"${localUploadCommand[@]}" | runSsh sh -c "$(printf '%q' "$remoteCommands")"

0 commit comments

Comments
 (0)