mirror of
https://github.com/numtide/nixos-anywhere.git
synced 2024-10-04 08:27:30 +03:00
use early return in runKexec
This commit is contained in:
parent
ef708ac46d
commit
bc77bd1cca
@ -375,65 +375,67 @@ importFacts() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
runKexec() {
|
runKexec() {
|
||||||
if [[ ${isKexec-n} == "n" ]] && [[ ${isInstaller-n} == "n" ]]; then
|
if [[ ${isKexec-n} == "y" ]] || [[ ${isInstaller-n} == "y" ]]; then
|
||||||
if [[ ${isContainer-none} != "none" ]]; then
|
return
|
||||||
echo "WARNING: This script does not support running from a '${isContainer}' container. kexec will likely not work" >&2
|
fi
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ $kexecUrl == "" ]]; then
|
if [[ ${isContainer-none} != "none" ]]; then
|
||||||
case "${isArch-unknown}" in
|
echo "WARNING: This script does not support running from a '${isContainer}' container. kexec will likely not work" >&2
|
||||||
x86_64 | aarch64)
|
fi
|
||||||
kexecUrl="https://github.com/nix-community/nixos-images/releases/download/nixos-24.05/nixos-kexec-installer-noninteractive-${isArch}-linux.tar.gz"
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
abort "Unsupported architecture: ${isArch}. Our default kexec images only support x86_64 and aarch64 cpus. Checkout https://github.com/nix-community/nixos-anywhere/#using-your-own-kexec-image for more information."
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
fi
|
|
||||||
|
|
||||||
step Switching system into kexec
|
if [[ $kexecUrl == "" ]]; then
|
||||||
runSsh sh <<SSH
|
case "${isArch-unknown}" in
|
||||||
|
x86_64 | aarch64)
|
||||||
|
kexecUrl="https://github.com/nix-community/nixos-images/releases/download/nixos-24.05/nixos-kexec-installer-noninteractive-${isArch}-linux.tar.gz"
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
abort "Unsupported architecture: ${isArch}. Our default kexec images only support x86_64 and aarch64 cpus. Checkout https://github.com/nix-community/nixos-anywhere/#using-your-own-kexec-image for more information."
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
|
||||||
|
step Switching system into kexec
|
||||||
|
runSsh sh <<SSH
|
||||||
set -efu ${enableDebug}
|
set -efu ${enableDebug}
|
||||||
$maybeSudo rm -rf /root/kexec
|
$maybeSudo rm -rf /root/kexec
|
||||||
$maybeSudo mkdir -p /root/kexec
|
$maybeSudo mkdir -p /root/kexec
|
||||||
SSH
|
SSH
|
||||||
|
|
||||||
# no way to reach global ipv4 destinations, use gh-v6.com automatically if github url
|
# no way to reach global ipv4 destinations, use gh-v6.com automatically if github url
|
||||||
if [[ ${hasIpv6_only-n} == "y" ]] && [[ $kexecUrl == "https://github.com/"* ]]; then
|
if [[ ${hasIpv6_only-n} == "y" ]] && [[ $kexecUrl == "https://github.com/"* ]]; then
|
||||||
kexecUrl=${kexecUrl/"github.com"/"gh-v6.com"}
|
kexecUrl=${kexecUrl/"github.com"/"gh-v6.com"}
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -f $kexecUrl ]]; then
|
if [[ -f $kexecUrl ]]; then
|
||||||
runSsh "${maybeSudo} tar -C /root/kexec -xvzf-" <"$kexecUrl"
|
runSsh "${maybeSudo} tar -C /root/kexec -xvzf-" <"$kexecUrl"
|
||||||
elif [[ ${hasCurl-n} == "y" ]]; then
|
elif [[ ${hasCurl-n} == "y" ]]; then
|
||||||
runSsh "curl --fail -Ss -L '${kexecUrl}' | ${maybeSudo} tar -C /root/kexec -xvzf-"
|
runSsh "curl --fail -Ss -L '${kexecUrl}' | ${maybeSudo} tar -C /root/kexec -xvzf-"
|
||||||
elif [[ ${hasWget-n} == "y" ]]; then
|
elif [[ ${hasWget-n} == "y" ]]; then
|
||||||
runSsh "wget '${kexecUrl}' -O- | ${maybeSudo} tar -C /root/kexec -xvzf-"
|
runSsh "wget '${kexecUrl}' -O- | ${maybeSudo} tar -C /root/kexec -xvzf-"
|
||||||
else
|
else
|
||||||
curl --fail -Ss -L "${kexecUrl}" | runSsh "${maybeSudo} tar -C /root/kexec -xvzf-"
|
curl --fail -Ss -L "${kexecUrl}" | runSsh "${maybeSudo} tar -C /root/kexec -xvzf-"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
runSsh <<SSH
|
runSsh <<SSH
|
||||||
TMPDIR=/root/kexec setsid ${maybeSudo} /root/kexec/kexec/run --kexec-extra-flags "${kexecExtraFlags}"
|
TMPDIR=/root/kexec setsid ${maybeSudo} /root/kexec/kexec/run --kexec-extra-flags "${kexecExtraFlags}"
|
||||||
SSH
|
SSH
|
||||||
|
|
||||||
# use the default SSH port to connect at this point
|
# use the default SSH port to connect at this point
|
||||||
for i in "${!sshArgs[@]}"; do
|
for i in "${!sshArgs[@]}"; do
|
||||||
if [[ ${sshArgs[i]} == "-p" ]]; then
|
if [[ ${sshArgs[i]} == "-p" ]]; then
|
||||||
sshArgs[i + 1]=$postKexecSshPort
|
sshArgs[i + 1]=$postKexecSshPort
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
# wait for machine to become unreachable.
|
# wait for machine to become unreachable.
|
||||||
while runSshTimeout -- exit 0; do sleep 1; done
|
while runSshTimeout -- exit 0; do sleep 1; done
|
||||||
|
|
||||||
# After kexec we explicitly set the user to root@
|
# After kexec we explicitly set the user to root@
|
||||||
sshConnection="root@${sshHost}"
|
sshConnection="root@${sshHost}"
|
||||||
|
|
||||||
# waiting for machine to become available again
|
# waiting for machine to become available again
|
||||||
until runSsh -o ConnectTimeout=10 -- exit 0; do sleep 5; done
|
until runSsh -o ConnectTimeout=10 -- exit 0; do sleep 5; done
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runDisko() {
|
runDisko() {
|
||||||
|
Loading…
Reference in New Issue
Block a user