#!/bin/bash # SPDX-License-Identifier: Apache-2.0 script_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) cd $script_dir set -e ssh_command() { vm_name="$1" vm_file="tmp/overlay-network/tmp/vms/${vm_name}_install.yaml" ip="$(grep 'ip: ' $vm_file | awk '{ print $NF }')" port="$(grep 'port: ' $vm_file | cut -d "'" -f2)" echo ssh -p $port root@$ip } export ssh_command ssh_prod_brain1="$(ssh_command prod-brain-1)" ssh_prod_brain2="$(ssh_command prod-brain-2)" ssh_prod_brain3="$(ssh_command prod-brain-3)" ssh_prod_mon="$(ssh_command prod-brain-mon)" ssh_staging_brain1="$(ssh_command staging-brain-1)" ssh_staging_brain2="$(ssh_command staging-brain-2)" ssh_staging_brain3="$(ssh_command staging-brain-3)" ssh_staging_mon="$(ssh_command staging-brain-mon)" export ssh_bastion="$(ssh_command bastion-brain)" $ssh_bastion 'ssh-keygen -t ed25519 -f /root/.ssh/id_ed25519 -N ""' bastion_pubkey=$($ssh_bastion cat /root/.ssh/id_ed25519.pub) echo $bastion_pubkey | $ssh_prod_brain1 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_prod_brain2 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_prod_brain3 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_prod_mon tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_staging_brain1 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_staging_brain2 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_staging_brain3 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_staging_mon tee -a /root/.ssh/authorized_keys $ssh_bastion curl -o /root/prepare.sh \ https://gitea.detee.cloud/general/examples/raw/branch/master/surrealdb_tikv_prod/prepare_bastion.sh $ssh_bastion curl -o /root/prod_cluster.yaml \ https://gitea.detee.cloud/general/examples/raw/branch/master/surrealdb_tikv_prod/prod_cluster.yaml $ssh_bastion curl -o /root/staging_cluster.yaml \ https://gitea.detee.cloud/general/examples/raw/branch/master/surrealdb_tikv_prod/staging_cluster.yaml $ssh_bastion chmod +x /root/prepare.sh $ssh_bastion /root/prepare.sh