Skip to content

Commit e07e74b

Browse files
committed
kexec: support other compression than gzip
1 parent ff87db6 commit e07e74b

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
@@ -654,6 +654,18 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr
654654
local localUploadCommand=()
655655
local remoteUploadCommand=()
656656
657+
# gnu tar cannot automatically detect the compression when decompressing via stdin
658+
tarDecomp=""
659+
if [[ ${kexecUrl} =~ \.tar\.gz$ ]]; then
660+
tarDecomp="--gzip"
661+
elif [[ ${kexecUrl} =~ \.tar\.xz$ ]]; then
662+
tarDecomp="--xz"
663+
elif [[ ${kexecUrl} =~ \.tar\.zstd$ ]]; then
664+
tarDecomp="--zstd"
665+
elif [[ ${kexecUrl} =~ \.tar$ ]]; then
666+
tarDecomp=""
667+
fi
668+
657669
if [[ -f $kexecUrl ]]; then
658670
localUploadCommand=(cat "$kexecUrl")
659671
elif [[ $hasWget == "y" ]]; then
@@ -669,14 +681,14 @@ TMPDIR=/root/kexec setsid --wait ${maybeSudo} /root/kexec/kexec/run --kexec-extr
669681
local remoteCommands
670682
if [[ ${#localUploadCommand[@]} -eq 0 ]]; then
671683
# Use remote command for download and execution
672-
tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | ${maybeSudo} tar -C /root/kexec -xvzf-"
684+
tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | ${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
673685
674686
remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand}
675687
676688
runSsh sh -c "$(printf '%q' "$remoteCommands")"
677689
else
678690
# Use local command with pipe to remote
679-
tarCommand="${maybeSudo} tar -C /root/kexec -xvzf-"
691+
tarCommand="${maybeSudo} tar -C /root/kexec -xv ${tarDecomp}"
680692
remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand}
681693
682694
"${localUploadCommand[@]}" | runSsh sh -c "$(printf '%q' "$remoteCommands")"

0 commit comments

Comments
 (0)