#!/bin/bash

# Exit immediately if a command exits with a non-zero status
set -e

# Configuration
REMOTE_USER="root"
REMOTE_DIR="/etc/ssl/certs"
CERT_FILE="/path/to/local/cert.crt"
KEY_FILE="/path/to/local/cert.key"

# List of remote hosts (IP addresses or hostnames)
HOSTS=(
  "192.168.1.10"
  "192.168.1.11"
  "192.168.1.12"
)

for HOST in "${HOSTS[@]}"; do
  echo "Processing $HOST..."

  # Copy certificate and key files
  scp "$CERT_FILE" "$KEY_FILE" "${REMOTE_USER}@${HOST}:${REMOTE_DIR}/"

  # Optional: Restart service on remote host (e.g., Nginx, Apache)
  #ssh "${REMOTE_USER}@${HOST}" "systemctl restart nginx"

  echo "Successfully updated $HOST"
done

echo "All certificates pushed successfully."
