#!/usr/bin/env bash set -euo pipefail ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd)" ENV_FILE="${ROOT_DIR}/.env.prod" CERTBOT_EMAIL="" usage() { cat <&2 usage >&2 exit 1 ;; esac done if [[ ! -f "$ENV_FILE" ]]; then echo "Missing ${ENV_FILE}" >&2 exit 1 fi # shellcheck disable=SC1090 set -a source "$ENV_FILE" set +a if [[ -z "${CLEARNET_DOMAIN:-}" ]]; then echo "CLEARNET_DOMAIN is not set in .env.prod" >&2 exit 1 fi if [[ -z "$CERTBOT_EMAIL" ]]; then echo "Pass --email for Let's Encrypt registration." >&2 usage >&2 exit 1 fi mkdir -p "${ROOT_DIR}/deploy/certbot/www" "${ROOT_DIR}/deploy/certs" docker run --rm \ -v "${ROOT_DIR}/deploy/certbot/www:/var/www/certbot" \ -v "${ROOT_DIR}/deploy/certs:/etc/letsencrypt" \ certbot/certbot certonly \ --webroot \ -w /var/www/certbot \ -d "$CLEARNET_DOMAIN" \ --email "$CERTBOT_EMAIL" \ --agree-tos \ --non-interactive if [[ ! -f "${ROOT_DIR}/deploy/certs/live/${CLEARNET_DOMAIN}/fullchain.pem" ]]; then echo "Expected certificates at deploy/certs/live/${CLEARNET_DOMAIN}" >&2 exit 1 fi echo "Certificates issued at deploy/certs/live/${CLEARNET_DOMAIN}" echo "Reload nginx: docker compose --env-file .env.prod -f docker-compose.prod.yml exec nginx nginx -s reload"