Skip to content

Commit

Permalink
recv_gpg_keys: refactor the script to use .SRCINFO and keys/pgp/
Browse files Browse the repository at this point in the history
Use .SRCINFO instead of PKGBUILD to list the keys used to validate
packages.

Import keys from $PKG/keys/pgp/*.asc, and always perform such imports to
enable updating keys when the files get updated.
  • Loading branch information
fishilico committed Aug 6, 2024
1 parent 5571599 commit d6b4793
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions recv_gpg_keys.sh
Original file line number Diff line number Diff line change
@@ -1,27 +1,28 @@
#!/bin/bash
#!/usr/bin/env bash
# Receive every gpg keys used by packages
set -eu
cd "$(dirname -- "$0")"

# Import all keys from the packages
gpg --import ./*/keys/pgp/*.asc

# Import all keys from the cache
gpg --import _pgp_cache/*.asc

# Download missing keys from a keyserver
# GnuPG key server to use
GPG_KEYSRV="${GPG_KEYSRV:-hkp://keys.gnupg.net}"

cd "$(dirname -- "$0")" || exit $?
for DIR in $(find . -maxdepth 2 -name PKGBUILD -printf '%h\n' | sort)
do
validpgpkeys=()
if ! source "$DIR/PKGBUILD" ; then
echo >&2 "Failed to source $DIR/PKGBUILD"
exit 1
fi
PKG="${DIR#./}"
for GPGKEY in "${validpgpkeys[@]}" ; do
sed -n 's/^\s*validpgpkeys = //p' < "$DIR/.SRCINFO" | \
while IFS= read -r GPGKEY ; do
if gpg --list-keys "$GPGKEY" > /dev/null 2>&1 ; then
echo "$PKG: key $GPGKEY already received."
elif [ -e "_pgp_cache/$GPGKEY.asc" ] ; then
echo "$PKG: importing key from local cache"
gpg --import "_pgp_cache/$GPGKEY.asc" || exit $?
echo "$PKG: key $GPGKEY found."
else
echo "$PKG: receiving key..."
gpg --keyserver "$GPG_KEYSRV" --recv-keys "$GPGKEY" || exit $?
gpg --keyserver "$GPG_KEYSRV" --recv-keys "$GPGKEY"
fi
done
done

0 comments on commit d6b4793

Please sign in to comment.