@@ -58,7 +58,6 @@ hasWget=
58
58
hasCurl=
59
59
hasSetsid=
60
60
hasNixOSFacter=
61
- remoteHomeDir=
62
61
63
62
tempDir=$( mktemp -d)
64
63
trap ' rm -rf "$tempDir"' EXIT
@@ -586,16 +585,13 @@ importFacts() {
586
585
587
586
# Necessary to prevent Bash erroring before printing out which fact had an issue
588
587
set +u
589
- for var in isOs isArch isInstaller isContainer isRoot hasIpv6Only hasTar hasCpio hasSudo hasDoas hasWget hasCurl hasSetsid remoteHomeDir ; do
588
+ for var in isOs isArch isInstaller isContainer isRoot hasIpv6Only hasTar hasCpio hasSudo hasDoas hasWget hasCurl hasSetsid; do
590
589
if [[ -z ${! var} ]]; then
591
590
abort " Failed to retrieve fact $var from host"
592
591
fi
593
592
done
594
593
set -u
595
594
596
- # Compute the log file path from the home directory
597
- remoteLogFile=" ${remoteHomeDir} /.nixos-anywhere.log"
598
-
599
595
if [[ -n ${enableDebug} ]]; then
600
596
set -x
601
597
fi
@@ -722,10 +718,6 @@ runKexec() {
722
718
kexecUrl=${kexecUrl/ " github.com" / " gh-v6.com" }
723
719
fi
724
720
725
- if [[ -z $remoteLogFile ]]; then
726
- abort " Could not create a temporary log file for $sshUser "
727
- fi
728
-
729
721
# Handle kexec operation failures
730
722
handleKexecFailure () {
731
723
local operation=$1
@@ -734,7 +726,8 @@ runKexec() {
734
726
local logContent=" "
735
727
if logContent=$(
736
728
set +x
737
- runSsh " cat \" $remoteLogFile \" 2>/dev/null" 2> /dev/null
729
+ # shellcheck disable=SC2016 # We want $HOME to expand on the remote server
730
+ runSsh ' cat "$HOME/kexec/nixos-anywhere.log" 2>/dev/null' 2> /dev/null
738
731
) ; then
739
732
echo " Remote output log:" >&2
740
733
echo " $logContent " >&2
@@ -743,28 +736,21 @@ runKexec() {
743
736
exit 1
744
737
}
745
738
746
- # Extract directly to the user's home directory
747
- if [[ -z $remoteHomeDir ]]; then
748
- abort " Could not determine home directory for user $sshUser "
749
- fi
750
-
751
739
# Define common remote commands template
752
740
local remoteCommandTemplate
753
741
remoteCommandTemplate="
754
742
# Run kexec commands with sudo if needed
755
743
{
756
744
set -eu ${enableDebug}
757
- ${maybeSudo} rm -rf \" $remoteHomeDir /kexec\"
758
- mkdir -p \" $remoteHomeDir /kexec\"
759
- cd \" $remoteHomeDir /kexec\"
745
+ cd \"\$ HOME/kexec\"
760
746
echo Downloading kexec tarball, this may take a moment...
761
747
# Execute tar command
762
748
%TAR_COMMAND%
763
- TMPDIR=\" $remoteHomeDir /kexec\" ${maybeSudo} setsid --wait \" $remoteHomeDir /kexec/kexec/run\" --kexec-extra-flags $( printf ' %q' " $kexecExtraFlags " )
764
- } 2>&1 | tee \" $remoteLogFile \" || true
749
+ TMPDIR=\"\$ HOME /kexec\" ${maybeSudo} setsid --wait \"\$ HOME /kexec/kexec/run\" --kexec-extra-flags $( printf ' %q' " $kexecExtraFlags " )
750
+ } 2>&1 | tee \"\$ HOME/kexec/nixos-anywhere.log \" || true
765
751
766
752
# The script will likely disconnect us, so we consider it successful if we see the kexec message
767
- if ! grep -q 'machine will boot into nixos' \" $remoteLogFile \" ; then
753
+ if ! grep -q 'machine will boot into nixos' \"\$ HOME/kexec/nixos-anywhere.log \" ; then
768
754
echo 'Kexec may have failed - check output above'
769
755
exit 1
770
756
fi
803
789
# Use remote command for download
804
790
tarCommand=" $( printf ' %q ' " ${remoteUploadCommand[@]} " ) | tar -xv ${tarDecomp} "
805
791
else
806
- # Upload the kexec tarball first
807
- " ${localUploadCommand[@]} " | runSsh " cat > \" $remoteHomeDir \" /kexec-tarball.tar.gz"
808
792
# Use local file for extraction
809
- tarCommand=" cat \" $remoteHomeDir \" /kexec-tarball.tar.gz | tar -xv ${tarDecomp} "
793
+ tarCommand=" cat \"\$ HOME /kexec/kexec -tarball.tar.gz\" | tar -xv ${tarDecomp} "
810
794
fi
811
795
812
796
local remoteCommands
813
797
remoteCommands=${remoteCommandTemplate// ' %TAR_COMMAND%' / $tarCommand }
814
798
815
799
# Create and execute the script on the remote system
816
- runSsh " mkdir -p \" $remoteHomeDir /kexec\" && cat > \" $remoteHomeDir /kexec/unpack.sh\" " << EOF
800
+ # shellcheck disable=SC2016 # We want $HOME to expand on the remote server
801
+ runSsh ' mkdir -p "$HOME/kexec" && cat > "$HOME/kexec/nixos-anywhere-kexec.sh"' << EOF
817
802
$remoteCommands
818
803
EOF
819
- runSsh " bash $remoteHomeDir /kexec/unpack.sh" || handleKexecFailure " Kexec"
804
+ if [[ ${# localUploadCommand[@]} -gt 0 ]]; then
805
+ # Upload the kexec tarball first
806
+ # shellcheck disable=SC2016 # We want $HOME to expand on the remote server
807
+ " ${localUploadCommand[@]} " | runSsh ' cat > "$HOME/kexec/kexec-tarball.tar.gz"'
808
+ fi
809
+ # shellcheck disable=SC2016 # We want $HOME to expand on the remote server
810
+ runSsh ' bash "$HOME/kexec/nixos-anywhere-kexec.sh"' || handleKexecFailure " Kexec"
820
811
821
812
# use the default SSH port to connect at this point
822
813
local i
0 commit comments