tvl-depot/users/wpcarro/configs/.gnupg/import.sh
William Carroll d9142b952a refactor(wpcarro/gnupg): Improve UX for gnupg/{import,export}.sh
TL;DR:
- Ensure that export.sh -> import.sh -> export.sh can round-trip without
  intermediate tools.
- Remove default values for variables like ${1}, which only seem to complicate
  things.
- Add `trap cleanup EXIT` to scripts.
- Remove noisy full-paths from `zip` (note: a more intuitive, less configurable
  `zip`, `unzip` should exist).

Change-Id: Ibbd98d1f0156639138175fcb89e9dfbd17fdae5f
Reviewed-on: https://cl.tvl.fyi/c/depot/+/4993
Tested-by: BuildkiteCI
Reviewed-by: wpcarro <wpcarro@gmail.com>
2022-01-18 22:27:20 +00:00

28 lines
625 B
Bash
Executable file

#!/usr/bin/env bash
set -euo pipefail
# Run this script to import all of the information exported by `export.sh`.
# Usage: ./import.sh path/to/export.zip
if [ -z "${1+x}" ]; then
echo "You must specify the path to export.zip. Exiting..."
exit 1
fi
destination="$(mktemp -d)"
function cleanup() {
rm -rf "${destination}"
}
trap cleanup EXIT
unzip "${1}" -d "${destination}" >/dev/null
gpg --import "${destination}/public.asc"
gpg --import "${destination}/secret.asc"
gpg --import-ownertrust "${destination}/ownertrust.txt"
# Run this at the end to output some verification
gpg --list-keys
gpg --list-secret-keys