apt-config/create-gpgring.sh

69 lines
1.2 KiB
Bash
Executable File

#!/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() {
gpg1 --homedir "${tmpdir}/.gnupg" --batch --no-tty --no-options --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 --no-default-keyring --primary-keyring "${KEYRING}" --import -- "${INFILES[@]}"
mygpg --no-default-keyring --primary-keyring "${KEYRING}" --list-keys
mv "${KEYRING}" "${OUTFILE}"
if [ -f "${tmpdir}/stdout" ]; then
cat "${tmpdir}/stdout"
fi