#!/usr/bin/env sh
# pgp-wkd - A web key directory for pgp-keys
#
# Copyright (C) 2025 Benedikt Peetz <benedikt.peetz@b-peetz.de>
# 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 <https://creativecommons.org/licenses/by-sa/4.0/legalcode.txt>.
die() {
echo "$@"
exit 1
}
help() {
cat <<EOF
A helper script to add an pgp key to the wkd.
USAGE:
mk_key FQDN EMAIL_ADDRESS
OPTIONS:
--help | -h
Display this help and exit.
ARGUMENTS:
FQDN
The email domain of this key. For example 'key@example.org' would
have an KEY_EMAIL_DOMAIN of 'example.org'.
EMAIL_ADDRESS
Add these keys with this email address included in their user ID.
EOF
}
add() {
fqdn="$1"
email_address="$2"
cd "$(git rev-parse --show-toplevel)" || die "No source dir!"
sq network wkd publish src --method=advanced --create --cert-email="$email_address" --domain="$fqdn" &&
printf "%s\n" "$fqdn ($email_address)" >>stored_keys.md &&
echo "Key export done!"
}
for arg in "$@"; do
case "$arg" in
"--help" | "-h")
help
exit 0
;;
esac
done
fqdn="$1"
email_address="$2"
shift 2
[ -z "$fqdn" ] && die "No FQDN specified, see '--help'!"
[ -z "$email_address" ] && die "No EMAIL_ADDRESS specified, see '--help'!"
[ -n "$*" ] && die "The arguments '$*' are not recognized; see '--help' for a list!"
add "$fqdn" "$email_address"
# vim: ft=sh