Skip to content

Instantly share code, notes, and snippets.

@DrJume
Last active November 26, 2024 13:40
Show Gist options
  • Save DrJume/64ff0ec0bdcfdadf98519b9422fca5ae to your computer and use it in GitHub Desktop.
Save DrJume/64ff0ec0bdcfdadf98519b9422fca5ae to your computer and use it in GitHub Desktop.
Select domains from traefik's acme.json to delete
#!/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