Skip to content

Instantly share code, notes, and snippets.

@ptarjan
Created May 25, 2009 00:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ptarjan/117322 to your computer and use it in GitHub Desktop.
Save ptarjan/117322 to your computer and use it in GitHub Desktop.
gpg-encrypt . A simple script for keeping a file gpg encrypted.
#!/bin/sh
filename="passwords.gpg"
if [ $EDITOR ]
then
editor=$EDITOR
elif [ -f /usr/bin/editor ]
then
editor=/usr/bin/editor
else
editor=vi
fi
if [ $# = 0 ]
then
echo "No filename specified. Using default $filename"
elif [ $# > 1 ]
then
echo "$0 [filename.gpg]"
exit 2
fi
if [ -f `which shred` ]
then
rm=shred
else
rm=rm
fi
tmp=`mktemp` || exit 1
# don't show typing
stty -echo
read -p "Password: " passw; echo
stty echo
if [ ! -f $filename ]
then
echo "$filename doesn't exist. Starting from empty file."
elif [ ! -w $filename ]
then
echo "$filename isn't writable."
exit 1
else
# decrypt into the tmp file
echo "$passw" | gpg -q -d --passphrase-fd 0 $filename > $tmp
if [ $? != 0 ]; then
# if gpg didn't work, exit
$rm $tmp
exit $?;
fi
fi
$editor $tmp
echo "$passw" | gpg -q -c --passphrase-fd 0 --output $filename $tmp
$rm $tmp
if [ $? != 0 ]; then
# if gpg didn't work, exit
exit $?;
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment