#!/usr/bin/env sh # pgp-wkd - A web key directory for pgp-keys # # Copyright (C) 2025 Benedikt Peetz # SPDX-License-Identifier: CC-BY-SA-4.0 # # This file is part of pgp-wkd. # # You should have received a copy of the License along with this program. # If not, see . die() { echo "$@" exit 1 } help() { cat <'. EOF } add() { key_id="$1" key_email="$2" key_hash="$3" cd "$(git rev-parse --show-toplevel)" || die "No source dir!" dir="./src/.well-known/openpgpkey/$key_email/hu" full_key_id="$(gpg --list-keys --with-colons "$key_id" | awk -F: '/^uid:/ { print $10 }' | tail -n 1)" mkdir --parents "$dir" gpg --no-armor --export "$key_id" >"$dir/$key_hash" && printf "%s%s%s%s\n" '`' "$dir/$key_hash" '`' " -> $full_key_id" >>stored_keys.md && echo "Key export done!" } for arg in "$@"; do case "$arg" in "--help" | "-h") help exit 0 ;; esac done key_id="$1" key_email="$2" key_hash="$3" shift 3 [ -z "$key_id" ] && die "No KEY_ID specified, see '--help'!" [ -z "$key_email" ] && die "No KEY_EMAIL_DOMAIN specified, see '--help'!" [ -z "$key_hash" ] && die "No KEY_HASH specified, see '--help'!" [ -n "$*" ] && die "The arguments '$*' are not recognized; see '--help' for a list!" add "$key_id" "$key_email" "$key_hash" # vim: ft=sh