Created
March 30, 2025 03:37
-
-
Save awbacker/ddfc5bdf588e83c3417db1d002731303 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export ORG="Scantrust" | |
echo "Importing GPG keys for all members of ${ORG}..." | |
for LOGIN in $(gh api --paginate "orgs/${ORG}/members" -q '.[].login'); do | |
NAME=$(gh api "users/${LOGIN}" -q '.name') | |
echo "[${NAME} - ${LOGIN}]" | |
# Fetch GPG keys from GitHub API and filter out any null keys | |
# Exit if no keys found | |
keys=$( | |
gh api "users/${LOGIN}/gpg_keys" \ | |
| jq -c '.[] | select(.raw_key != null and .raw_key != "")' | |
) | |
[ -z "$keys" ] && continue | |
echo "${keys}" | while read -r key_data; do | |
key_id=$(echo "${key_data}" | jq -r '.key_id') | |
raw_key=$(echo "${key_data}" | jq -r '.raw_key') | |
if ! gpg --list-keys "${key_id}" &>/dev/null; then | |
echo "${raw_key}" | gpg --import | |
else | |
echo " > ${key_id} already imported" | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment