helm/bin/gpgzip
2017-12-06 01:39:10 -05:00

41 lines
831 B
Bash
Executable file

#!/usr/bin/env bash
# Encrypt/decrypt and compress folders with gpg+tar.
# Usage:
# clump foldername # packs
# clump foldername.clump # unpacks
set -e
if (($# == 0)); then
>&2 echo "Usage: $0 <FILE|DIRECTORY> [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