2024-05-14 19:23:11 -04:00
|
|
|
#!/bin/sh
|
|
|
|
|
|
|
|
## SPDX-FileCopyrightText: 2024 Benjamin Grande M. S. <ben.grande.b@gmail.com>
|
|
|
|
##
|
|
|
|
## SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
|
|
|
|
set -eu
|
|
|
|
|
2024-08-06 12:15:24 -04:00
|
|
|
command -v git >/dev/null ||
|
|
|
|
{ printf '%s\n' "Missing program: git" >&2; exit 1; }
|
2024-07-11 09:25:51 -04:00
|
|
|
repo_toplevel="$(git rev-parse --show-toplevel)"
|
|
|
|
test -d "${repo_toplevel}" || exit 1
|
2024-07-19 09:29:17 -04:00
|
|
|
cd "${repo_toplevel}"
|
2024-07-11 09:25:51 -04:00
|
|
|
unset repo_toplevel
|
2024-07-19 09:29:17 -04:00
|
|
|
|
2024-08-06 11:04:16 -04:00
|
|
|
now="$(date -- +%s)"
|
2024-05-14 19:23:11 -04:00
|
|
|
fail="0"
|
2024-07-11 09:25:51 -04:00
|
|
|
find_tool="$(./scripts/best-program.sh fd fdfind find)"
|
|
|
|
|
|
|
|
if test -n "${1-}"; then
|
|
|
|
files=""
|
|
|
|
for f in "${@}"; do
|
|
|
|
test -f "${f}" || continue
|
|
|
|
test -r "${f}" || continue
|
|
|
|
extension="${f##*.}"
|
|
|
|
case "${extension}" in
|
|
|
|
asc|gpg) files="${files} ${f}";;
|
|
|
|
*) continue;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
else
|
|
|
|
case "${find_tool}" in
|
|
|
|
fd|fdfind)
|
|
|
|
files="$(${find_tool} . -H -t f -e asc -e gpg | sort -d)"
|
|
|
|
;;
|
|
|
|
find)
|
|
|
|
files="$(find . -type f \( -name '*.asc' -o -name '*.gpg' \) | sort -d)"
|
|
|
|
;;
|
2024-08-06 12:15:24 -04:00
|
|
|
*) printf '%s\n' "Unsupported find tool" >&2; exit 1;;
|
2024-07-11 09:25:51 -04:00
|
|
|
esac
|
|
|
|
fi
|
|
|
|
|
|
|
|
if test -z "${files}"; then
|
|
|
|
exit 0
|
2024-06-12 08:44:04 -04:00
|
|
|
fi
|
2024-07-11 09:25:51 -04:00
|
|
|
|
|
|
|
for key in ${files}; do
|
2024-05-15 09:58:00 -04:00
|
|
|
data="$(gpg --no-keyring --no-auto-check-trustdb --no-autostart \
|
2024-07-11 09:25:51 -04:00
|
|
|
--with-colons --show-keys "${key}")"
|
2024-08-06 12:15:24 -04:00
|
|
|
nr="$(printf '%s\n' "${data}" | grep -Ec -e '^(p|s)ub:')"
|
2024-07-11 09:25:51 -04:00
|
|
|
## Threshold in days.
|
|
|
|
threshold="${PGP_LINT_THRESHOLD:-30}"
|
|
|
|
tty_stderr=0
|
|
|
|
if test -t 2; then
|
|
|
|
tty_stderr=1
|
|
|
|
fi
|
2024-08-06 12:15:24 -04:00
|
|
|
printf '%s\n' "${data}" | awk -v fail="0" -v key="${key}" -v nr="${nr}" \
|
2024-07-11 09:25:51 -04:00
|
|
|
-v threshold="${threshold}" -v now="${now}" -v color="${tty_stderr}" \
|
|
|
|
-F ':' '
|
|
|
|
BEGIN {
|
|
|
|
MAGENTA = ""
|
|
|
|
YELLOW = ""
|
|
|
|
RED = ""
|
|
|
|
RESET = ""
|
|
|
|
if (color == 1) {
|
|
|
|
MAGENTA = "\033[1;35m"
|
|
|
|
YELLOW = "\033[1;33m"
|
|
|
|
RED = "\033[1;31m"
|
|
|
|
RESET = "\033[0m"
|
|
|
|
}
|
2024-05-14 19:23:11 -04:00
|
|
|
}
|
2024-05-15 09:58:00 -04:00
|
|
|
|
2024-07-11 09:25:51 -04:00
|
|
|
/^(p|s)ub:/{
|
2024-05-15 09:58:00 -04:00
|
|
|
|
2024-07-11 09:25:51 -04:00
|
|
|
nlines++
|
2024-05-15 09:58:00 -04:00
|
|
|
|
2024-07-11 09:25:51 -04:00
|
|
|
if ($7 == "") {
|
|
|
|
if (nlines == nr ) { if (fail == 1) { exit 1 } }
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($7 < now) {
|
2024-11-04 09:29:51 -05:00
|
|
|
message = MAGENTA key RESET ":" RED " expired" RESET ": " $5
|
2024-07-11 09:25:51 -04:00
|
|
|
print message >"/dev/stderr"
|
|
|
|
fail = 1
|
|
|
|
if (nlines == nr ) { if (fail == 1) { exit 1 } }
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (($7 - now) < (60 * 60 * 24 * threshold )) {
|
|
|
|
remaining_days = int(($7 - now) / (60 * 60 * 24))
|
|
|
|
message_prefix = MAGENTA key RESET ":" YELLOW " expires in "
|
|
|
|
message_suffix = remaining_days " days" RESET ": " $5
|
|
|
|
message = message_prefix message_suffix
|
|
|
|
print message >"/dev/stderr"
|
|
|
|
fail = 1
|
|
|
|
if (nlines == nr ) { if (fail == 1) { exit 1 } }
|
|
|
|
next
|
|
|
|
}
|
|
|
|
|
|
|
|
if (fail == 1) {
|
|
|
|
exit 1
|
|
|
|
}
|
|
|
|
}' || fail="1"
|
2024-05-14 19:23:11 -04:00
|
|
|
done
|
|
|
|
|
|
|
|
if test "${fail}" = "1"; then
|
|
|
|
exit 1
|
|
|
|
fi
|