thibthibaut
3/20/2017 - 2:47 PM

The world simplest password manager

The world simplest password manager

#!/bin/bash
#------------------------------------------------------------------------------
# passmgr.sh 
# The world simplest password manager ever
# by Aehter Luminifer
# Dependancies:
# * pwgen
# * gpg
# Version: 3.14
# Licence :
# "THE BEER-WARE LICENSE" (Revision 42):
# Thibaut Vercueil wrote this file. As long as you retain this notice you
# can do whatever you want with this stuff. If we meet some day, and you think
# this stuff is worth it, you can buy me a beer in return Thibaut Vercueil
#------------------------------------------------------------------------------


#Test if database exists
if [ ! -f "~/passwords.gpg" ]; then
	touch ~/passwords.gpg
fi
if [ "$1" == "-a" ]; then
	if [ "$2" == "" ]; then
		echo "Please give a name to the password!"
		exit
	fi
	echo "Adding new password to database..."
	pw=`pwgen -s -y 12 1` #Generate password
	gpg --output /tmp/pw -d ~/passwords.gpg #Decrypt current passwords
	echo "$2 $pw" >> /tmp/pw #Add new password
	shred -f -n 10 -u -z ~/passwords.gpg #Remove old database
	gpg --output ~/passwords.gpg --symmetric /tmp/pw #Rewritte database
	shred -f -n 10 -u -z /tmp/pw #Remove clear file
	echo "Done"
elif [ "$1" == "-r" ]; then
	if [ "$2" == "" ]; then
		echo "Please provide a name to search in DB"
		exit
	fi
	echo "Retriving password from database"
	gpg --output /tmp/pw -d ~/passwords.gpg #Decrypt current passwords
	result=`cat /tmp/pw | grep $2` #Look for the entry
	shred -f -n 10 -u -z /tmp/pw #Remove clear file
	if [ "$result" == "" ]; then
		echo "No entry found for $2"
	else
		echo "$result" 
	fi
	echo "Done"
else 
	echo "Welcome to passmgr.sh by aether!"
	echo "Usage:"
	echo "To add a new password: ./passmgr.sh -a facebook"
	echo "To retrieve a password: ./passmgr.sh -r facebook"
	echo "Big Bisous is watching you!"
fi