helm/bin/gpgzip

41 lines
767 B
Plaintext
Raw Normal View History

#!/usr/bin/env bash
# Encrypt/decrypt and compress folders with gpg+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
2016-11-14 17:39:04 -08:00
elif [[ -d $target ]]; then
cmd=pack
else
>&2 echo "Not a valid target: '$target'"
exit 1
fi
2016-11-14 17:39:04 -08:00
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