-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcertbot.sh
More file actions
54 lines (47 loc) · 1.36 KB
/
certbot.sh
File metadata and controls
54 lines (47 loc) · 1.36 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
#!/usr/bin/env bash
set -euo pipefail
# ---------- helpers ----------
log() { echo -e "\n==> $*"; }
need_cmd() { command -v "$1" >/dev/null 2>&1; }
if [[ "${EUID}" -ne 0 ]]; then
echo "Please run as root: sudo $0"
exit 1
fi
# ---------- install certbot ----------
log "Installing Certbot..."
apt-get update -y
apt-get install -y certbot
# ---------- install nginx plugin if nginx is installed ----------
if need_cmd nginx; then
log "Installing Certbot Nginx plugin..."
apt-get install -y python3-certbot-nginx
fi
# ---------- install apache plugin if apache is installed ----------
if need_cmd apache2; then
log "Installing Certbot Apache plugin..."
apt-get install -y python3-certbot-apache
fi
# ---------- setup auto-renewal ----------
log "Setting up auto-renewal..."
systemctl enable certbot.timer
systemctl start certbot.timer
log "Done."
echo ""
echo "=========================================="
echo " Certbot Installation Complete!"
echo "=========================================="
echo ""
echo "Version: $(certbot --version)"
echo ""
echo "Get certificate (Nginx):"
echo " certbot --nginx -d example.com -d www.example.com"
echo ""
echo "Get certificate (standalone):"
echo " certbot certonly --standalone -d example.com"
echo ""
echo "Test renewal:"
echo " certbot renew --dry-run"
echo ""
echo "List certificates:"
echo " certbot certificates"
echo ""