2016-10-19 12:38:58 -07:00
|
|
|
#!/usr/bin/env bash
|
2016-10-06 03:45:57 -07:00
|
|
|
|
2016-11-14 17:39:04 -08:00
|
|
|
# Helper for encrypting/decrypting folders with gpg and tar.
|
2016-10-06 03:45:57 -07:00
|
|
|
# Usage:
|
|
|
|
# clump foldername # packs
|
|
|
|
# clump foldername.clump # unpacks
|
|
|
|
|
2016-11-14 17:39:04 -08:00
|
|
|
set -e
|
|
|
|
if (($# == 0)); then
|
2016-10-06 03:45:57 -07:00
|
|
|
>&2 echo "Usage: $0 <FILE|DIRECTORY> [DEST]"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-11-14 17:39:04 -08:00
|
|
|
ext='clump'
|
|
|
|
target="$1"
|
|
|
|
cmd=
|
|
|
|
if [[ -f $target ]]; then
|
|
|
|
cmd=unpack
|
|
|
|
elif [[ -d $target ]]; then
|
|
|
|
cmd=pack
|
2016-10-06 03:45:57 -07:00
|
|
|
else
|
2016-11-14 17:39:04 -08:00
|
|
|
>&2 echo "Not a valid target: '$target'"
|
2016-10-06 03:45:57 -07:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-11-14 17:39:04 -08:00
|
|
|
case $cmd in
|
2016-10-06 03:45:57 -07:00
|
|
|
p|pack)
|
2016-11-14 17:39:04 -08:00
|
|
|
if [[ -f $target.$ext ]]; then
|
2016-10-06 03:45:57 -07:00
|
|
|
>&2 echo "Destination file already exists"
|
|
|
|
exit 2
|
|
|
|
fi
|
2016-11-14 17:39:04 -08:00
|
|
|
tar -pcvf - "$target" | gpg -c > "$target.$ext"
|
|
|
|
echo "Packed into $target.$ext"
|
2016-10-06 03:45:57 -07:00
|
|
|
;;
|
|
|
|
u|unpack)
|
2016-11-14 17:39:04 -08:00
|
|
|
tmpfile=$(mktemp)
|
|
|
|
gpg -d "$target" > "$tmpfile" && tar -pxvf "$tmpfile"
|
|
|
|
rm -f "$tmpfile"
|
2016-10-06 03:45:57 -07:00
|
|
|
;;
|
|
|
|
esac
|