#!/bin/sh
#
# Copyright (C) 2019 by Intevation GmbH
# Authors:
# Thomas Arendsen Hein <thomas@intevation.de>
#
# check if OpenPGP keys in a specific keyring are about to expire

# run check this number of days in the future:
DAYS=35

# regexp of long keyids to ignore:
SOME_KEY="exampleabcd1234" # no encryption subkey
IGNORE="^($SOME_KEY)$"

KEYRING="$HOME/.gnupg/pubring.gpg"

GPG="gpg --no-options --trust-model always --no-default-keyring --keyring $KEYRING"

$GPG --with-colons --list-public-keys \
| awk -F: -v IGNORE="$IGNORE" '$1 == "pub" && $5 !~ IGNORE { print $5 }' \
| while read recipient; do
    echo test | faketime -f +"$DAYS"d $GPG -q -er "$recipient" >/dev/null 2>&1 \
    || $GPG --list-public-keys "$recipient"
done
