Forked from DrJume/delete-traefik-acme-certificates.sh
Created
November 26, 2024 13:40
-
-
Save positiveque/080b275d7ec37e220c66c9e4d879d48f to your computer and use it in GitHub Desktop.
Select domains from traefik's acme.json to delete
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# tested with traefik v2.4.8 | |
ACME_FILE="acme.json" | |
# get jq from https://stedolan.github.io/jq/ | |
SELECTED_DOMAINS=$(jq -r '.letsencrypt.Certificates[].domain.main' "$ACME_FILE" | fzf -m --height '40%' --reverse --border) | |
if [[ -z "$SELECTED_DOMAINS" ]]; then | |
echo "Nothing changed." | |
exit | |
fi | |
cp --force -p --backup=numbered "$ACME_FILE" "$ACME_FILE" | |
cp -p "$ACME_FILE" "${ACME_FILE}.new" | |
for domain in $SELECTED_DOMAINS; do | |
echo "Deleting certificate for '$domain'" | |
# get sponge by installing the moreutils package | |
jq "del(.letsencrypt.Certificates[] | select(.domain.main == \"$domain\"))" "${ACME_FILE}.new" | sponge "${ACME_FILE}.new" | |
done | |
cp --attributes-only --preserve=mode,ownership "$ACME_FILE" "${ACME_FILE}.new" | |
mv "${ACME_FILE}.new" "$ACME_FILE" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment