#!/bin/bash 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_brain1="$(ssh_command brain-1)" ssh_brain2="$(ssh_command brain-2)" ssh_brain3="$(ssh_command brain-3)" export ssh_bastion="$(ssh_command brain-bastion)" ssh_mon="$(ssh_command brain-mon)" $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_brain1 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_brain2 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_brain3 tee -a /root/.ssh/authorized_keys echo $bastion_pubkey | $ssh_mon tee -a /root/.ssh/authorized_keys cat prepare_bastion.sh | $ssh_bastion tee -a /root/prepare.sh > /dev/null $ssh_bastion chmod +x /root/prepare.sh $ssh_bastion /root/prepare.sh