2016-10-19 12:38:58 -07:00
|
|
|
#!/usr/bin/env bash
|
2016-10-06 03:45:57 -07:00
|
|
|
|
2017-12-05 22:39:10 -08:00
|
|
|
# Encrypt/decrypt and compress folders with gpg+tar.
|
2016-10-06 03:45:57 -07:00
|
|
|
# Usage:
|
2017-12-05 22:39:10 -08:00
|
|
|
# clump foldername # packs
|
|
|
|
# clump foldername.clump # unpacks
|
2016-10-06 03:45:57 -07:00
|
|
|
|
2016-11-14 17:39:04 -08:00
|
|
|
set -e
|
|
|
|
if (($# == 0)); then
|
2017-12-17 22:12:13 -08:00
|
|
|
>&2 echo "Usage: $0 <FILE|DIRECTORY> [DEST]"
|
|
|
|
exit 1
|
2016-10-06 03:45:57 -07:00
|
|
|
fi
|
|
|
|
|
2016-11-14 17:39:04 -08:00
|
|
|
ext='clump'
|
|
|
|
target="$1"
|
|
|
|
cmd=
|
|
|
|
if [[ -f $target ]]; then
|
2017-12-17 22:12:13 -08:00
|
|
|
cmd=unpack
|
2016-11-14 17:39:04 -08:00
|
|
|
elif [[ -d $target ]]; then
|
2017-12-17 22:12:13 -08:00
|
|
|
cmd=pack
|
2016-10-06 03:45:57 -07:00
|
|
|
else
|
2017-12-17 22:12:13 -08:00
|
|
|
>&2 echo "Not a valid target: '$target'"
|
|
|
|
exit 1
|
2016-10-06 03:45:57 -07:00
|
|
|
fi
|
|
|
|
|
2016-11-14 17:39:04 -08:00
|
|
|
case $cmd in
|
2017-12-17 22:12:13 -08:00
|
|
|
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"
|
|
|
|
;;
|
2016-10-06 03:45:57 -07:00
|
|
|
esac
|