29 lines
594 B
Bash
Executable File
29 lines
594 B
Bash
Executable File
#!/bin/sh
|
|
|
|
if ! test -n "$1"; then
|
|
printf "Usage: %s [ProtonMail address]" "$0"
|
|
exit 64 # syexits(3) EX_USAGE
|
|
fi
|
|
|
|
if ! command -v curl > /dev/null; then
|
|
printf "%s: Missing dependency: curl(1)\n" "$0"
|
|
exit 69 # sysexits(3) EX_UNAVAILABLE
|
|
fi
|
|
|
|
ADDR="$1"
|
|
URL="https://api.protonmail.ch/pks/lookup?op=get&search=$ADDR"
|
|
echo "Resolving $URL..."
|
|
RESPONSE="$(curl "$URL")"
|
|
|
|
if [ "$RESPONSE" = "No key found" ]; then
|
|
printf "%s\n" "RESPONSE"
|
|
exit 76 # sysexits(3) EX_PROTOCOL
|
|
else
|
|
TEMPKEY=$(mktemp /tmp/pubkey-dl.XXXXXX)
|
|
printf "%s" "$RESPONSE" > "$TEMPKEY"
|
|
fi
|
|
|
|
gpg --import "$TEMPKEY"
|
|
|
|
exit 0
|