Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save positiveque/080b275d7ec37e220c66c9e4d879d48f to your computer and use it in GitHub Desktop.

Select an option

Save positiveque/080b275d7ec37e220c66c9e4d879d48f to your computer and use it in GitHub Desktop.

Revisions

  1. @DrJume DrJume revised this gist Jun 22, 2021. 1 changed file with 0 additions and 0 deletions.
    Empty file modified delete-traefik-acme-certificates.sh
    100644 → 100755
    Empty file.
  2. @DrJume DrJume revised this gist Jun 22, 2021. 1 changed file with 5 additions and 5 deletions.
    10 changes: 5 additions & 5 deletions delete-traefik-acme-certificates.sh
    Original file line number Diff line number Diff line change
    @@ -8,18 +8,18 @@ ACME_FILE="acme.json"
    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
    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"
    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"
  3. @DrJume DrJume created this gist Jun 22, 2021.
    27 changes: 27 additions & 0 deletions delete-traefik-acme-certificates.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/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"