#!/usr/bin/env bash set -euo pipefail REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)" cd "$REPO_ROOT" LIMIT="" EXTRA_ARGS=() usage() { cat <&2 usage >&2 exit 1 ;; esac done ensure_ssh_key() { local key="${HOME}/.ssh/id_ed25519" if [[ -f "$key" ]]; then echo "==> SSH key already exists: $key" return 0 fi echo "==> Generating SSH key: $key" ssh-keygen -t ed25519 -N "" -f "$key" -C "$(whoami)@$(hostname)" } ensure_gitea_ssh_config() { local ssh_dir="${HOME}/.ssh" local config="${ssh_dir}/config" mkdir -p "$ssh_dir" chmod 700 "$ssh_dir" if [[ -f "$config" ]] && grep -qE '^Host[[:space:]]+git\.aimloperations\.com$' "$config"; then echo "==> SSH config already has git.aimloperations.com" return 0 fi if [[ -f "$config" && -s "$config" ]]; then printf '\n' >>"$config" fi cat >>"$config" <<'EOF' Host git.aimloperations.com User git Port 30009 AddressFamily inet EOF chmod 600 "$config" echo "==> Added git.aimloperations.com to ${config}" } ensure_ssh_key ensure_gitea_ssh_config CMD=(ansible-playbook playbooks/site.yml "${EXTRA_ARGS[@]}") if [[ -n "$LIMIT" ]]; then CMD+=(--limit "$LIMIT") echo "==> Targeting host: $LIMIT" else echo "==> Targeting all webservers" fi exec "${CMD[@]}"