Skip to content

Instantly share code, notes, and snippets.

@DJStompZone
Created April 25, 2026 12:53
Show Gist options
  • Select an option

  • Save DJStompZone/7d8918d244a7bb2037df39f419199917 to your computer and use it in GitHub Desktop.

Select an option

Save DJStompZone/7d8918d244a7bb2037df39f419199917 to your computer and use it in GitHub Desktop.
Brother Printer Certificate Export
#!/usr/bin/env bash
set -euo pipefail
DOMAIN="printer.stomp.zone"
CERT_DIR="/var/lib/caddy/.local/share/caddy/certificates/acme-v02.api.letsencrypt.org-directory/${DOMAIN}"
CERT_FILE="${CERT_DIR}/${DOMAIN}.crt"
KEY_FILE="${CERT_DIR}/${DOMAIN}.key"
YEAR="$(date +%Y)"
MONTH="$(date +%-m)"
case "$MONTH" in
1|2|3) QUARTER="Q1" ;;
4|5|6) QUARTER="Q2" ;;
7|8|9) QUARTER="Q3" ;;
10|11|12) QUARTER="Q4" ;;
esac
OUT_FILE="/var/lib/caddy/exports/${DOMAIN}.${YEAR}-${QUARTER}.p12"
PASS_FILE="/root/.brother-printer-p12-pass-${YEAR}-${QUARTER}"
install -d -m 0750 -o root -g root "$(dirname "$OUT_FILE")"
if [[ ! -f "$CERT_FILE" || ! -f "$KEY_FILE" ]]; then
echo "Missing cert or key for ${DOMAIN}" >&2
exit 1
fi
if [[ ! -f "$PASS_FILE" ]]; then
umask 077
openssl rand -base64 24 > "$PASS_FILE"
fi
openssl pkcs12 -export -legacy -out "$OUT_FILE" -inkey "$KEY_FILE" -in "$CERT_FILE" -certfile /etc/ssl/certs/ca-certificates.crt -name "$DOMAIN" -passout "file:${PASS_FILE}"
chmod 0600 "$OUT_FILE"
echo "Exported: $OUT_FILE"
echo "Password file: $PASS_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment