#!/usr/bin/env bash # Helper for encrypting/decrypting folders with gpg and tar. # Usage: # clump foldername # packs # clump foldername.clump # unpacks set -e if (($# == 0)); then >&2 echo "Usage: $0 [DEST]" exit 1 fi ext='clump' target="$1" cmd= if [[ -f $target ]]; then cmd=unpack elif [[ -d $target ]]; then cmd=pack else >&2 echo "Not a valid target: '$target'" exit 1 fi case $cmd in p|pack) if [[ -f $target.$ext ]]; then >&2 echo "Destination file already exists" exit 2 fi tar -pcvf - "$target" | gpg -c > "$target.$ext" echo "Packed into $target.$ext" ;; u|unpack) tmpfile=$(mktemp) gpg -d "$target" > "$tmpfile" && tar -pxvf "$tmpfile" rm -f "$tmpfile" ;; esac