The Road to Elysium

April 10, 2008

Simple password storage script

Filed under: Snippets — jorge @ 08:08
#!/bin/bash
 
##
 #  sps is free software; you can redistribute it and/or modify
 #  it under the terms of the GNU General Public License as published by
 #  the Free Software Foundation; either version 2 of the License, or
 #  (at your option) any later version.
 #
 #  sps is distributed in the hope that it will be useful,
 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 #  GNU General Public License for more details.
 # 
 #  You should have received a copy of the GNU General Public License
 #  along with sps; if not, write to the Free Software
 #  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 #
################################################################################
 #  
 #  This is the sps (Simple Password Storage) script v0.0.1.
 #  Create a file with user,password,category, and encrypt it with gpg -c <file>.
 #  To get a password, use ./sps <grepstring>.
 #  To edit your entries, use ./sps -e.
 #  
 #  Jorge Barrera Grandon <jorge@atlantiscrew.net>
 #  Atlantis Crew <http://www.atlantiscrew.net>
 #
 ##
 
 
# User defined variables
 
PWFILE="/home/jorge/passwords.gpg"
EDITOR="vim"
 
# End of user defined variables
 
 
TMP_PWF="/tmp/.sps"
CLEAR=`which clear`
GPG=`which gpg`
AWK=`which awk`
GREP=`which grep`
TPUT=`which tput`
EDIT=`which $EDITOR`
CHMOD=`which chmod`
 
 
if [ "$#" -ne 1 ]; then
 
    echo "Use: `basename $0` <grepstring>"
 
elif [ "$1" = "-e" ]; then
 
    $CLEAR
    echo "File being decrypted for editing."
    $GPG --no-mdc-warning -q -d $PWFILE > $TMP_PWF
    $EDIT $TMP_PWF
    $CLEAR
    echo "Done with editing - encrypting file again."
    $GPG --output $PWFILE -c $TMP_PWF
    $CHMOD 600 $PWFILE
    rm $TMP_PWF
 
else
 
    $CLEAR
    $TPUT smcup
    $GPG --no-mdc-warning -q -d $PWFILE |
    $AWK 'BEGIN { FS=","; OFS=" / "} { print "\033[1m"$3":\033[0m\t" $1, $2 }'|
    $GREP -i $@
    echo ""
    read -n1 -p "Press any key to exit.."
    $TPUT rmcup
 
fi

No Comments »

No comments yet.

RSS feed for comments on this post. TrackBack URL

Leave a comment

Powered by WordPress