From f4235fead39ec6053eca4362008b4f626f9460f6 Mon Sep 17 00:00:00 2001 From: lassulus Date: Thu, 24 Nov 2022 17:28:47 +0000 Subject: [PATCH] start installation with ssh-copy-id, allow custom kexec tarball --- nixos-remote | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/nixos-remote b/nixos-remote index 2156fff..8ed589d 100755 --- a/nixos-remote +++ b/nixos-remote @@ -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