d9142b952a
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>
29 lines
785 B
Bash
Executable file
29 lines
785 B
Bash
Executable file
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
# Run this script to export all the information required to transport your GPG
|
|
# information.
|
|
# Usage: ./export.sh
|
|
# TODO: run this periodically as a job.
|
|
|
|
output="$(pwd)/export.zip"
|
|
destination="$(mktemp -d)"
|
|
|
|
function cleanup() {
|
|
rm -rf "${destination}"
|
|
}
|
|
trap cleanup EXIT
|
|
|
|
gpg --armor --export >"${destination}/public.asc"
|
|
gpg --armor --export-secret-keys >"${destination}/secret.asc"
|
|
gpg --armor --export-ownertrust >"${destination}/ownertrust.txt"
|
|
|
|
# Strangely enough this appears to be the only way to create a zip of a
|
|
# directory that doesn't contain the (noisy) full paths of each item from the
|
|
# source filesystem. (i.e. -j doesn't cooperate with -r)
|
|
pushd "${destination}"
|
|
zip -r "${output}" ./*
|
|
popd
|
|
|
|
echo "$(realpath ${output})"
|