about summary refs log tree commit diff stats
path: root/scripts/mk_key.sh
blob: 85ea8afddf2353a2c7a3b5d6ecfcfb4b771048b3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/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