Skip to content

Instantly share code, notes, and snippets.

@DosAmp
Last active December 23, 2015 11:09
Show Gist options
  • Save DosAmp/6626136 to your computer and use it in GitHub Desktop.
Save DosAmp/6626136 to your computer and use it in GitHub Desktop.
Because sometimes there is no use in obscuring a script’s purpose in its name.
#!/bin/bash
GPG_EXTRA_OPTIONS="--compress-algo none"
RECIPIENT="--default-recipient-self"
OUTDIR=
QUIET=
while getopts "h\?r:o:q" o
do
case "$o" in
h|\?) echo "Usage: $0 [-r RECIPIENT] [-o OUTDIR] [-q] FILE..."
exit 0 ;;
r) RECIPIENT="-r $OPTARG" ;;
o) [ -d "$OPTARG" ] && OUTDIR="$OPTARG" ;;
q) QUIET=1 ;;
esac
done
shift $((OPTIND-1))
while [ $# -gt 0 ]; do
file="$1"
if [ -r "$file" ]; then
outdir="${OUTDIR:-$(dirname "$file")}"
filehash=$(sha1sum "$file" | awk "{print \$1}")
outfile=$filehash.gpg
tar -c -C "$(dirname "$file")" "$(basename "$file")" | \
gpg -e $RECIPIENT $GPG_EXTRA_OPTIONS -o "${outdir}/${outfile}"
if [ -z $QUIET ]; then
printf "$filehash\t$(basename "$file")\n"
fi
fi
shift
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment