#!/bin/bash if [ "$(id -u)" != "0" ]; then echo -e "\033[31mThis script requires superuser rights.\033[0m" exit 0 fi if [ -z "$1" ]; then echo "Please provide SERVER_HOST as argument" exit 1 fi REMOTE_USER="root" SERVER_HOST=$1 SECRETS_PATH=/data/secrets/$SERVER_HOST/$SERVER_HOST.env source $SECRETS_PATH trap 'echo -e "\033[31mremote.sh: Something went wrong\033[0m"; exit 1' ERR set -e export DEBIAN_FRONTEND=noninteractive sshpass -p $SERVER_ORIGIN_PASSWORD ssh-copy-id -i ~/.ssh/id_ed25519.pub $REMOTE_USER@$SERVER_ORIGIN_DOMAIN trap - ERR echo "SSH public key for server host $SERVER_HOST complete installed on $SERVER_ORIGIN_DOMAIN"