diff --git a/scripts/cluster/install-certificate-sync.sh b/scripts/cluster/install-certificate-sync.sh index 94616a9..1c7b041 100755 --- a/scripts/cluster/install-certificate-sync.sh +++ b/scripts/cluster/install-certificate-sync.sh @@ -12,6 +12,7 @@ hongkong_host_key=$(cluster_ssh "$CLUSTER_HONGKONG_HOST" \ echo 'invalid Hong Kong SSH host key' >&2 exit 1 } +hongkong_host_key_b64=$(printf '%s' "$hongkong_host_key" | base64 | tr -d '\n') public_key=$(cluster_ssh "$CLUSTER_NINGBO_HOST" 'bash -s' <<'REMOTE' set -euo pipefail @@ -26,18 +27,22 @@ REMOTE echo 'invalid certificate sync public key' >&2 exit 1 } -cluster_ssh "$CLUSTER_HONGKONG_HOST" bash -s -- "$public_key" <<'REMOTE' +public_key_b64=$(printf '%s' "$public_key" | base64 | tr -d '\n') +cluster_ssh "$CLUSTER_HONGKONG_HOST" bash -s -- "$public_key_b64" <<'REMOTE' set -euo pipefail -public_key=$1 +public_key=$(printf '%s' "$1" | base64 -d) +[[ $public_key == ssh-ed25519\ * ]] install -d -m 0700 /root/.ssh touch /root/.ssh/authorized_keys chmod 0600 /root/.ssh/authorized_keys +sed -i '/^ssh-ed25519$/d' /root/.ssh/authorized_keys grep -Fqx "$public_key" /root/.ssh/authorized_keys || printf '%s\n' "$public_key" >>/root/.ssh/authorized_keys REMOTE -cluster_ssh "$CLUSTER_NINGBO_HOST" bash -s -- "$hongkong_host_key" <<'REMOTE' +cluster_ssh "$CLUSTER_NINGBO_HOST" bash -s -- "$hongkong_host_key_b64" <<'REMOTE' set -euo pipefail -hongkong_host_key=$1 +hongkong_host_key=$(printf '%s' "$1" | base64 -d) +[[ $hongkong_host_key == ssh-ed25519\ * ]] install -d -m 0700 /root/.ssh known_hosts=/root/.ssh/known_hosts temporary=$(mktemp /root/.ssh/known_hosts.XXXXXX)