start installation with ssh-copy-id, allow custom kexec tarball

This commit is contained in:
lassulus 2022-11-24 17:28:47 +00:00
parent e6788fcd68
commit f4235fead3

View File

@ -46,6 +46,9 @@ while [[ $# -gt 0 ]]; do
kexec_url=$2
shift
;;
--no-ssh-copy-id)
no_ssh_copy=y
;;
*)
if [ -z ${ssh_connection+x} ]; then
ssh_connection=$1
@ -95,15 +98,19 @@ else
abort "flake must be set"
fi
# wait for machine to become reachable (possibly forever)
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
if [ ${no_ssh_copy-n} != "y" ]; then
until ssh-copy-id "$ssh_connection"; do sleep 5; done
else
until ssh_ -o ConnectTimeout=10 -- exit 0; do sleep 5; done
fi
# first check if the remote system is kexec booted
if $(ssh_ -- test -e /etc/is_kexec); then
is_kexec=y
fi
echo ${is_kexec-n}
if [ ${is_kexec-n} != "y" ]; then
# TODO we probably need an architecture detection here
ssh_ << SSH
@ -113,6 +120,19 @@ if [[ "\$os" != "Linux" ]]; then
echo "This script requires Linux as the operating system, but got \${os}" >&2
exit 1
fi
if ! command -v tar >/dev/null 2>&1; then
echo "no tar command found, but required to unpack kexec tarball" >&2
exit 1
fi
rm -rf /root/kexec
mkdir -p /root/kexec
SSH
if [[ -e "$kexec_url" ]]; then
cat "$kexec_url" | ssh_ 'tar -C /root/kexec -xvzf-'
else
ssh_ << SSH
fetch(){
if command -v curl >/dev/null 2>&1; then
curl --fail -Ss -L "\$1"
@ -123,17 +143,15 @@ fetch(){
exit 1
fi
}
if ! command -v tar >/dev/null 2>&1; then
echo "no tar command found, but required to unpack kexec tarball" >&2
exit 1
fetch "$kexec_url" | tar -C /root/kexec -xvzf-
SSH
fi
rm -rf /root/kexec
mkdir -p /root/kexec
fetch "$kexec_url" | tar -C /root/kexec -xvzf-
ssh_ << SSH
export TMPDIR=/root/kexec
setsid /root/kexec/kexec/run
SSH
# wait for machine to become unreachable
while timeout_ssh_ -- exit 0; do sleep 1; done