helm/bin/clump.sh

41 lines
847 B
Bash
Raw Normal View History

#!/usr/bin/env bash
2016-11-14 17:39:04 -08:00
# Helper for encrypting/decrypting folders with gpg and tar.
# Usage:
# clump foldername # packs
# clump foldername.clump # unpacks
2016-11-14 17:39:04 -08:00
set -e
if (($# == 0)); then
>&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
else
2016-11-14 17:39:04 -08:00
>&2 echo "Not a valid target: '$target'"
exit 1
fi
2016-11-14 17:39:04 -08:00
case $cmd in
p|pack)
2016-11-14 17:39:04 -08:00
if [[ -f $target.$ext ]]; then
>&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"
;;
u|unpack)
2016-11-14 17:39:04 -08:00
tmpfile=$(mktemp)
gpg -d "$target" > "$tmpfile" && tar -pxvf "$tmpfile"
rm -f "$tmpfile"
;;
esac