about summary refs log tree commit diff
path: root/users/wpcarro/configs/.gnupg/export.sh
diff options
context:
space:
mode:
Diffstat (limited to 'users/wpcarro/configs/.gnupg/export.sh')
-rwxr-xr-xusers/wpcarro/configs/.gnupg/export.sh25
1 files changed, 15 insertions, 10 deletions
diff --git a/users/wpcarro/configs/.gnupg/export.sh b/users/wpcarro/configs/.gnupg/export.sh
index bb047e9e3b91..31def2beb179 100755
--- a/users/wpcarro/configs/.gnupg/export.sh
+++ b/users/wpcarro/configs/.gnupg/export.sh
@@ -1,24 +1,29 @@
 #!/usr/bin/env bash
 
-set -e
+set -euo pipefail
 
 # Run this script to export all the information required to transport your GPG
 # information.
-# Usage: ./export.sh [directory]
+# Usage: ./export.sh
 # TODO: run this periodically as a job.
 
-destination="${1:-$(mktemp -d)}"
+output="$(pwd)/export.zip"
+destination="$(mktemp -d)"
 
-if [ ! -d "${destination}" ]; then
-  echo "${destination} does not exist. Creating it..."
-  mkdir -p "${destination}"
-fi
+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"
 
-zip -r "${destination}.zip" "${destination}"
-rm -rf "${destination}"
+# 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 "${destination}.zip")
+echo "$(realpath ${output})"