bin/clump: refactor
This commit is contained in:
parent
781ff33832
commit
ae737424b8
37
bin/clump
37
bin/clump
|
@ -1,41 +1,40 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
# Script for encrypting and decrypting folders, using GPG and tar
|
# Helper for encrypting/decrypting folders with gpg and tar.
|
||||||
# Usage:
|
# Usage:
|
||||||
# clump foldername # packs
|
# clump foldername # packs
|
||||||
# clump foldername dest # packs to specific location
|
|
||||||
# clump foldername.clump # unpacks
|
# clump foldername.clump # unpacks
|
||||||
# clump foldername.clump dest # unpacks to specific location
|
|
||||||
|
|
||||||
if [ "$#" -eq 0 ]; then
|
set -e
|
||||||
|
if (($# == 0)); then
|
||||||
>&2 echo "Usage: $0 <FILE|DIRECTORY> [DEST]"
|
>&2 echo "Usage: $0 <FILE|DIRECTORY> [DEST]"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
EXT="clump"
|
ext='clump'
|
||||||
TARGET="$1"
|
target="$1"
|
||||||
COMMAND=
|
cmd=
|
||||||
if [ -f "$TARGET" ]; then
|
if [[ -f $target ]]; then
|
||||||
COMMAND=unpack
|
cmd=unpack
|
||||||
elif [ -d "$TARGET" ]; then
|
elif [[ -d $target ]]; then
|
||||||
COMMAND=pack
|
cmd=pack
|
||||||
else
|
else
|
||||||
>&2 echo "Not a valid target: '$TARGET'"
|
>&2 echo "Not a valid target: '$target'"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
case "$COMMAND" in
|
case $cmd in
|
||||||
p|pack)
|
p|pack)
|
||||||
if [ -f "$TARGET.$EXT" ]; then
|
if [[ -f $target.$ext ]]; then
|
||||||
>&2 echo "Destination file already exists"
|
>&2 echo "Destination file already exists"
|
||||||
exit 2
|
exit 2
|
||||||
fi
|
fi
|
||||||
tar -pcvf - "$TARGET" | gpg -c > "$TARGET.$EXT"
|
tar -pcvf - "$target" | gpg -c > "$target.$ext"
|
||||||
echo "Packed into $TARGET.$EXT"
|
echo "Packed into $target.$ext"
|
||||||
;;
|
;;
|
||||||
u|unpack)
|
u|unpack)
|
||||||
TMPFILE=$(mktemp)
|
tmpfile=$(mktemp)
|
||||||
gpg -d "$TARGET" > "$TMPFILE" && tar -pxvf "$TMPFILE"
|
gpg -d "$target" > "$tmpfile" && tar -pxvf "$tmpfile"
|
||||||
rm -f "$TMPFILE"
|
rm -f "$tmpfile"
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
Loading…
Reference in a new issue