69 lines
1.2 KiB
Bash
69 lines
1.2 KiB
Bash
|
#!/bin/bash
|
||
|
|
||
|
# syntax: $0 [-o <keyring outfile>] [--] <keyfiles...>
|
||
|
|
||
|
# export a key from your keyring:
|
||
|
# gpg -a --export --export-options export-minimal your@id
|
||
|
|
||
|
set -e
|
||
|
|
||
|
tmpdir=$(mktemp --tmpdir -d create-gpgring-XXXXXXX)
|
||
|
trap 'rm -rf "${tmpdir}"' EXIT
|
||
|
|
||
|
mygpg() {
|
||
|
gpg --homedir "${tmpdir}/.gnupg" --batch --no-tty --no-options --no-default-keyring --no-auto-check-trustdb --trustdb-name "${tmpdir}/trustdb.gpg" "$@"
|
||
|
}
|
||
|
|
||
|
unset INFILES
|
||
|
INFILES=()
|
||
|
|
||
|
OUTFILE=
|
||
|
|
||
|
while [ $# -gt 0 ]; do
|
||
|
case "$1" in
|
||
|
-o)
|
||
|
shift
|
||
|
if [ $# -eq 0 ]; then
|
||
|
echo "Missing parameter value for -o" >&2
|
||
|
exit 2
|
||
|
fi
|
||
|
OUTFILE="$1"
|
||
|
;;
|
||
|
--)
|
||
|
shift
|
||
|
INFILES+=("$@")
|
||
|
shift $#
|
||
|
;;
|
||
|
-*)
|
||
|
echo "Uknown option: '$1'" >&2
|
||
|
exit 2
|
||
|
;;
|
||
|
*)
|
||
|
INFILES+=("$1")
|
||
|
;;
|
||
|
esac
|
||
|
shift || true
|
||
|
done
|
||
|
|
||
|
if [ -z "${OUTFILE}" -o "${OUTFILE}" = "-" ]; then
|
||
|
OUTFILE="${tmpdir}/stdout"
|
||
|
fi
|
||
|
|
||
|
if [ -z "${INFILES[*]}" -o "${INFILES[*]}" = "-" ]; then
|
||
|
INFILES=("${tmpdir}/stdin")
|
||
|
cat > "${INFILES[0]}"
|
||
|
fi
|
||
|
|
||
|
export HOME="${tmpdir}"
|
||
|
|
||
|
KEYRING="${tmpdir}/keyring"
|
||
|
|
||
|
mygpg --keyring "${KEYRING}" --import -- "${INFILES[@]}"
|
||
|
mygpg --keyring "${KEYRING}" --list-keys
|
||
|
|
||
|
mv "${KEYRING}" "${OUTFILE}"
|
||
|
|
||
|
if [ -f "${tmpdir}/stdout" ]; then
|
||
|
cat "${tmpdir}/stdout"
|
||
|
fi
|