#!/bin/bash set -euo pipefail CMD="${SSH_ORIGINAL_COMMAND:-${1:-}}" if [[ "$CMD" =~ ^cert-[a-zA-Z0-9._-]+$ ]]; then APP="${CMD#cert-}" # Write temporary HTTP-only config so nginx can serve ACME challenges cat > "/opt/hantim/docker/nginx/conf.d/$APP.conf" < "docker/$APP/.env" chmod 600 "docker/$APP/.env" fi fi cd "docker/$APP" if grep -q '^\s*build:' compose.yml 2>/dev/null; then docker compose build else if ! docker compose pull; then echo "Image not yet available for $APP — skipping. It will deploy when the app repo is first pushed." exit 0 fi fi if [ "$APP" = "nginx" ]; then # Fail loudly if any certs are missing — issue them first with: app.sh cert for conf in /opt/hantim/docker/nginx/conf.d/*.*.conf; do cert_name=$(basename "$conf" .conf) if [ ! -d "/etc/letsencrypt/live/$cert_name" ]; then echo "ERROR: Missing certificate for $cert_name" echo " Run: app.sh cert $cert_name" exit 1 fi done # Test config before applying — a bad config would take down all sites docker compose run --rm -T nginx nginx -t fi docker compose up -d --remove-orphans if [ "$APP" = "nginx" ]; then docker exec nginx nginx -s reload fi