Skip to content

Commit efe280b

Browse files
committed
remove remoteHomeDir from facts
1 parent 7d420d6 commit efe280b

File tree

2 files changed

+12
-19
lines changed

2 files changed

+12
-19
lines changed

src/get-facts.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,4 @@ hasWget=$(has wget)
2020
hasCurl=$(has curl)
2121
hasSetsid=$(has setsid)
2222
hasNixOSFacter=$(command -v nixos-facter >/dev/null && echo "y" || echo "n")
23-
remoteHomeDir=$HOME
2423
FACTS

src/nixos-anywhere.sh

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@ hasWget=
5858
hasCurl=
5959
hasSetsid=
6060
hasNixOSFacter=
61-
remoteHomeDir=
6261

6362
tempDir=$(mktemp -d)
6463
trap 'rm -rf "$tempDir"' EXIT
@@ -586,7 +585,7 @@ importFacts() {
586585

587586
# Necessary to prevent Bash erroring before printing out which fact had an issue
588587
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
590589
if [[ -z ${!var} ]]; then
591590
abort "Failed to retrieve fact $var from host"
592591
fi
@@ -727,7 +726,7 @@ runKexec() {
727726
local logContent=""
728727
if logContent=$(
729728
set +x
730-
runSsh "cat \"$remoteHomeDir/kexec/nixos-anywhere.log\" 2>/dev/null" 2>/dev/null
729+
runSsh 'cat "$HOME/kexec/nixos-anywhere.log" 2>/dev/null' 2>/dev/null
731730
); then
732731
echo "Remote output log:" >&2
733732
echo "$logContent" >&2
@@ -736,28 +735,23 @@ runKexec() {
736735
exit 1
737736
}
738737
739-
# Extract directly to the user's home directory
740-
if [[ -z $remoteHomeDir ]]; then
741-
abort "Could not determine home directory for user $sshUser"
742-
fi
743-
744738
# Define common remote commands template
745739
local remoteCommandTemplate
746740
remoteCommandTemplate="
747741
# Run kexec commands with sudo if needed
748742
{
749743
set -eu ${enableDebug}
750-
${maybeSudo} rm -rf \"$remoteHomeDir/kexec\"
751-
mkdir -p \"$remoteHomeDir/kexec\"
752-
cd \"$remoteHomeDir/kexec\"
744+
${maybeSudo} rm -rf \"\$HOME/kexec\"
745+
mkdir -p \"\$HOME/kexec\"
746+
cd \"\$HOME/kexec\"
753747
echo Downloading kexec tarball, this may take a moment...
754748
# Execute tar command
755749
%TAR_COMMAND%
756-
TMPDIR=\"$remoteHomeDir/kexec\" ${maybeSudo} setsid --wait \"$remoteHomeDir/kexec/kexec/run\" --kexec-extra-flags $(printf '%q' "$kexecExtraFlags")
757-
} 2>&1 | tee \"$remoteHomeDir/kexec/nixos-anywhere.log\" || true
750+
TMPDIR=\"\$HOME/kexec\" ${maybeSudo} setsid --wait \"\$HOME/kexec/kexec/run\" --kexec-extra-flags $(printf '%q' "$kexecExtraFlags")
751+
} 2>&1 | tee \"\$HOME/kexec/nixos-anywhere.log\" || true
758752
759753
# The script will likely disconnect us, so we consider it successful if we see the kexec message
760-
if ! grep -q 'machine will boot into nixos' \"$remoteHomeDir/kexec/nixos-anywhere.log\"; then
754+
if ! grep -q 'machine will boot into nixos' \"\$HOME/kexec/nixos-anywhere.log\"; then
761755
echo 'Kexec may have failed - check output above'
762756
exit 1
763757
fi
@@ -797,19 +791,19 @@ fi
797791
tarCommand="$(printf '%q ' "${remoteUploadCommand[@]}") | tar -xv ${tarDecomp}"
798792
else
799793
# Upload the kexec tarball first
800-
"${localUploadCommand[@]}" | runSsh "cat > \"$remoteHomeDir\"/kexec-tarball.tar.gz"
794+
"${localUploadCommand[@]}" | runSsh 'cat > "$HOME/kexec-tarball.tar.gz"'
801795
# Use local file for extraction
802-
tarCommand="cat \"$remoteHomeDir\"/kexec-tarball.tar.gz | tar -xv ${tarDecomp}"
796+
tarCommand="cat \"\$HOME/kexec-tarball.tar.gz\" | tar -xv ${tarDecomp}"
803797
fi
804798
805799
local remoteCommands
806800
remoteCommands=${remoteCommandTemplate//'%TAR_COMMAND%'/$tarCommand}
807801
808802
# Create and execute the script on the remote system
809-
runSsh "mkdir -p \"$remoteHomeDir/kexec\" && cat > \"$remoteHomeDir/kexec/unpack.sh\"" <<EOF
803+
runSsh 'mkdir -p "$HOME/kexec" && cat > "$HOME/kexec/nixos-anywhere-kexec.sh"' <<EOF
810804
$remoteCommands
811805
EOF
812-
runSsh "bash $remoteHomeDir/kexec/unpack.sh" || handleKexecFailure "Kexec"
806+
runSsh 'bash "$HOME/kexec/nixos-anywhere-kexec.sh"' || handleKexecFailure "Kexec"
813807
814808
# use the default SSH port to connect at this point
815809
local i

0 commit comments

Comments
 (0)