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

45 lines
1.3 KiB
Bash
Executable File

#!/bin/sh
# Copyright (c) 2022 Emma Tebibyte
# SPDX-License-Identifier: AGPL-3.0-or-later
# Protonkey is free software: you can redistribute it and/or modify it
# under the terms of the GNU Affero General Public License as published by the
# Free Software Foundation, either version 3 of the License, or (at your
# option) any later version.
#
# Protonkey is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see https://www.gnu.org/licenses/.
if ! test -n "$1"; then
printf "Usage: %s [ProtonMail address]\n" "$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