emma
/
protonkey
Archived
1
0
Fork 0
This repository has been archived on 2024-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
protonkey/protonkey

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