Last active
August 29, 2015 14:05
-
-
Save raidzero/d22584978880c0c2afbe to your computer and use it in GitHub Desktop.
Rudimentary password manager
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
FILE=~/Dropbox/creds.txt | |
DISPPASS="$1" | |
read -s -p "Please enter master passphrase: " PASSPHRASE | |
printf "\n" | |
# decrypt to /tmp | |
[ -f /tmp/creds.txt ] && rm /tmp/creds.txt | |
echo "$PASSPHRASE" | gpg --batch -q -o /tmp/creds.txt --passphrase-fd 0 --cipher-algo AES256 --decrypt "$FILE" &> /dev/null | |
if [ $? -ne 0 ]; then | |
echo "Decryption error" | |
exit 1 | |
fi | |
# xsel or pbcopy present?? | |
XSEL_PRESENT=`which xsel` | |
PBCOPY_PRESENT=`which pbcopy` | |
if [ -z "$XSEL_PRESENT" ] && [ -z "$PBCOPY_PRESENT" ]; then | |
DISPPASS="yes" | |
fi | |
if [ -n "$XSEL_PRESENT" ]; then | |
COPY_CMD="xsel -b" | |
elif [ -n "$PBCOPY_PRESENT" ]; then | |
COPY_CMD="pbcopy" | |
fi | |
# present menu | |
clear | |
FILEDATA=`cat /tmp/creds.txt | nl` | |
#remove the tmpfile | |
rm /tmp/creds.txt | |
ACCTS=`echo "$FILEDATA" | awk -F ':::' '{print$1}'` | |
echo "$ACCTS" | |
while [ "$SELECTION" != "q" ]; do | |
printf "\nWhat would you like? (a to add, q to exit): " | |
read SELECTION | |
if [ "$SELECTION" == "a" ]; then | |
read -p "Name: " ACCT | |
ACCT_EXISTS=`echo "$ACCTS" | grep -i "$ACCT"` | |
if [ -z "$ACCT_EXISTS" ]; then | |
read -s -p "Password: " PASS | |
#decrypt file for adding | |
echo "$PASSPHRASE" | gpg --batch -q -o /tmp/creds.txt --passphrase-fd 0 --cipher-algo AES256 --decrypt "$FILE" | |
printf "\n$ACCT:::$PASS" >> /tmp/creds.txt | |
# encrypt it back | |
gpg -o "$FILE" --cipher-algo AES256 --symmetric -c /tmp/creds.txt | |
rm /tmp/creds.txt | |
else | |
clear | |
echo "Account exists!" | |
fi | |
continue | |
elif [ "$SELECTION" == "q" ]; then | |
break | |
else | |
DATA=`echo "$FILEDATA" | grep -wi $SELECTION | sed 's/:::/: /'` | |
PASS=`echo "$DATA" | awk -F ': *' '{print$2}'` | |
if [ "$DISPPASS" == "-d" ]; then | |
echo "$PASS" | |
else | |
echo "$PASS" | $COPY_CMD | |
echo "Password in clipboard" | |
fi | |
fi | |
done | |
echo "Goodbye" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment