2014-12-29 15:56:44 +00:00
|
|
|
#!/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() {
|
2016-12-09 12:44:51 +00:00
|
|
|
gpg1 --homedir "${tmpdir}/.gnupg" --batch --no-tty --no-options --no-auto-check-trustdb --trustdb-name "${tmpdir}/trustdb.gpg" "$@"
|
2014-12-29 15:56:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
2016-12-09 12:44:51 +00:00
|
|
|
mygpg --no-default-keyring --primary-keyring "${KEYRING}" --import -- "${INFILES[@]}"
|
|
|
|
mygpg --no-default-keyring --primary-keyring "${KEYRING}" --list-keys
|
2014-12-29 15:56:44 +00:00
|
|
|
|
|
|
|
mv "${KEYRING}" "${OUTFILE}"
|
|
|
|
|
|
|
|
if [ -f "${tmpdir}/stdout" ]; then
|
|
|
|
cat "${tmpdir}/stdout"
|
|
|
|
fi
|