-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathts-certgen.sh
39 lines (34 loc) · 1.18 KB
/
ts-certgen.sh
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
#!/bin/sh
#-----------------------------------------------------------------------------
# Tailscale Certificate Generation Script
#
# Purpose:
# - Generates and renews Tailscale SSL/TLS certificates
# - Designed for automated execution via cron
# - Ensures continuous certificate validity
#
# Usage:
# - Requires TS_DOMAIN_NAME environment variable
# - Certificates are stored in /certs directory
# - Exit codes: 0 (success), 1 (error)
#-----------------------------------------------------------------------------
# Environment Validation
# Check if domain name is configured
if [ -z "$TS_DOMAIN_NAME" ]; then
echo "[ERROR] Missing TS_DOMAIN_NAME environment variable"
echo "[INFO] Please set TS_DOMAIN_NAME to your Tailscale domain"
exit 1
fi
# Certificate Generation
# Navigate to certificate directory and generate new cert
echo "[INFO] Starting certificate generation for ${TS_DOMAIN_NAME}"
if ! cd /certs/; then
echo "[ERROR] Failed to access certificate directory"
exit 1
fi
echo "[INFO] Requesting certificate from Tailscale..."
if ! tailscale cert $TS_DOMAIN_NAME; then
echo "[ERROR] Certificate generation failed"
exit 1
fi
echo "[SUCCESS] Certificate generated successfully"