-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinit-letsencrypt.sh
More file actions
executable file
·94 lines (83 loc) · 3.87 KB
/
init-letsencrypt.sh
File metadata and controls
executable file
·94 lines (83 loc) · 3.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env bash
# ── Warden — Let's Encrypt first-run certificate provisioning ──────────────────
#
# Run this once before starting Warden with HTTPS for the first time.
# After this succeeds, start the stack with:
#
# docker compose -f docker-compose.yml -f docker-compose.https.yml up -d
#
# Usage:
# chmod +x init-letsencrypt.sh
# ./init-letsencrypt.sh
#
# Required environment variables (in .env or exported):
# WARDEN_DOMAIN — your domain, e.g. warden.yourdomain.com
# CERTBOT_EMAIL — email for expiry notices from Let's Encrypt
set -euo pipefail
# ── Load .env if present ───────────────────────────────────────────────────────
if [ -f .env ]; then
# shellcheck disable=SC2046
export $(grep -v '^#' .env | grep -v '^$' | xargs)
fi
# ── Validate required variables ────────────────────────────────────────────────
if [ -z "${WARDEN_DOMAIN:-}" ]; then
echo "ERROR: WARDEN_DOMAIN is not set."
echo " Add WARDEN_DOMAIN=yourdomain.example.com to your .env file."
exit 1
fi
if [ -z "${CERTBOT_EMAIL:-}" ]; then
echo "ERROR: CERTBOT_EMAIL is not set."
echo " Add [email protected] to your .env file."
exit 1
fi
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Warden — Let's Encrypt certificate setup"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Domain : $WARDEN_DOMAIN"
echo " Email : $CERTBOT_EMAIL"
echo ""
# ── Create required directories ────────────────────────────────────────────────
mkdir -p ./certbot/conf ./certbot/www
# ── Check DNS before hitting Let's Encrypt rate limits ────────────────────────
echo "Checking DNS resolution for $WARDEN_DOMAIN..."
if ! host "$WARDEN_DOMAIN" > /dev/null 2>&1; then
echo ""
echo "WARNING: $WARDEN_DOMAIN does not resolve."
echo " Make sure your DNS A record points to this server's public IP"
echo " before continuing."
echo ""
read -rp "Continue anyway? [y/N] " confirm
[[ "$confirm" =~ ^[Yy]$ ]] || exit 1
fi
# ── Start nginx in HTTP-only mode for the ACME challenge ──────────────────────
echo ""
echo "Starting nginx (HTTP only) for ACME domain validation..."
docker compose up -d ui
# Wait for nginx to be ready
sleep 3
# ── Request the certificate ───────────────────────────────────────────────────
echo ""
echo "Requesting certificate from Let's Encrypt..."
docker compose run --rm certbot certonly \
--webroot \
--webroot-path=/var/www/certbot \
--email "$CERTBOT_EMAIL" \
--agree-tos \
--no-eff-email \
--domain "$WARDEN_DOMAIN"
echo ""
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo " Certificate obtained successfully!"
echo "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━"
echo ""
echo "Next steps:"
echo ""
echo " # Bring down the temporary HTTP-only stack"
echo " docker compose down"
echo ""
echo " # Start the full HTTPS stack"
echo " docker compose -f docker-compose.yml -f docker-compose.https.yml up -d"
echo ""
echo " Warden will be available at: https://$WARDEN_DOMAIN"
echo ""