Skip to content

Instantly share code, notes, and snippets.

@prologic
Created February 22, 2015 22:14
Show Gist options
  • Save prologic/e0a4f16ae1e7063596ee to your computer and use it in GitHub Desktop.
Save prologic/e0a4f16ae1e7063596ee to your computer and use it in GitHub Desktop.
created by github.com/tr3buchet/gister
#!/bin/bash
function getpass() {
if [[ -f $HOME/.passwd.cpt ]]; then
password=$(ccrypt -c $HOME/.passwd.cpt | egrep $1 | cut -f 3 -d ":")
else
password=$(egrep $1 $HOME/.passwd | cut -f 3 -d ":")
fi
if [[ $password == "" ]]; then
echo "No matching password found!"
else
echo -n $password | copy
echo "Password copied to clipboard!"
fi
}
function showpass() {
if [[ -f $HOME/.passwd.cpt ]]; then
password=$(ccrypt -c $HOME/.passwd.cpt | egrep $1 | cut -f 3 -d ":")
else
password=$(egrep $1 $HOME/.passwd | cut -f 3 -d ":")
fi
if [[ $password == "" ]]; then
echo "No matching password found!"
else
echo -n $password
fi
}
function remotepass() {
NAME=${1}
# XXX: Make the default hostname configurable via a $HOME/.passwdrc ?
HOST=${2:-daisy}
ssh -q -t ${HOST} "bash -l -c 'showpass ${NAME}'"
}
function addpass() {
NAME=${1}
USER=${2}
PASS=${3:-$(mkpasswd)}
if [[ -f $HOME/.passwd.cpt ]]; then
echo "Decrypting Password Database ..."
ccdecrypt $HOME/.passwd.cpt
fi
echo "${NAME}:${USER}:${PASS}" >> $HOME/.passwd
echo "Encrypting Password Database ..."
ccencrypt $HOME/.passwd
echo -n $PASS | copy
echo "Password created and copied to clipboard!"
}
function syncpasswd() {
if [[ -f $HOME/.passwd ]]; then
echo "Encrypting Password Database ..."
ccencrypt $HOME/.passwd
fi
# XXX: Generlize this
scp .passwd.cpt daisy:.passwords/apn.com.au.cpt
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment