25 lines
1.0 KiB
Bash
25 lines
1.0 KiB
Bash
#!/bin/sh
|
|
# Exit immediately if any command fails
|
|
set -e
|
|
|
|
# --- Configuration ---
|
|
REDIS_HOST="caddy-redis"
|
|
DOMAIN="mail.poppyglen.cc"
|
|
OUTPUT_DIR="/export"
|
|
|
|
# Define the exact keys for the certificate and private key files
|
|
CERT_REDIS_KEY="caddy/certificates/acme-v02.api.letsencrypt.org-directory/${DOMAIN}/${DOMAIN}.crt"
|
|
PKEY_REDIS_KEY="caddy/certificates/acme-v02.api.letsencrypt.org-directory/${DOMAIN}/${DOMAIN}.key"
|
|
|
|
echo "Fetching, parsing, and decoding certificate from Redis..."
|
|
# The new pipeline: Get from Redis -> Extract the .value field -> Decode from Base64 -> Save to file
|
|
redis-cli -h "${REDIS_HOST}" --raw GET "${CERT_REDIS_KEY}" | jq -r '.value' | base64 -d > "${OUTPUT_DIR}/${DOMAIN}.crt"
|
|
|
|
echo "Fetching, parsing, and decoding private key from Redis..."
|
|
redis-cli -h "${REDIS_HOST}" --raw GET "${PKEY_REDIS_KEY}" | jq -r '.value' | base64 -d > "${OUTPUT_DIR}/${DOMAIN}.key"
|
|
|
|
# Set correct permissions
|
|
chmod 644 "${OUTPUT_DIR}/${DOMAIN}.crt" "${OUTPUT_DIR}/${DOMAIN}.key"
|
|
|
|
echo "✅ Successfully exported and decoded certificate and key for ${DOMAIN}."
|