Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 59 lines (49 sloc) 1.13 KB
#!/bin/bash
# parts adapted from: <https://github.com/poolpog/bash-otp/blob/master/otp.sh>
CMD=$1
NAME=$2
TOKEN=$3
TOKENS=~/docs/2fa
crypt de $TOKENS > /dev/null
trap "crypt en $TOKENS > /dev/null" EXIT
function get {
NAME=$1
TOKEN=`cat $TOKENS | grep $NAME | cut -d ':' -f2`
D=0
D="$( date +%S )"
if [ $D -gt 30 ] ; then D=$( echo "$D - 30"| bc ); fi
if [ $D -lt 0 ] ; then D="00"; fi
echo "copied to clipboard:"
while true; do
D="$( date +%S )"
X=$( oathtool --totp -b "$TOKEN" )
if [ $D = '59' -o $D = '29' ] ; then
echo "$D: $X"
else
echo -ne "$D: $X\r"
fi
echo -n $X | xsel -b
sleep 1
done
}
function add {
NAME=$1
TOKEN=$2
echo -e "${NAME}:$TOKEN" >> $TOKENS
exit 0
}
if [ -z $CMD ]; then
# if no command, interactive mode
echo "INTERACTIVE MODE"
echo "Enter: 'get <NAME>' or 'add <NAME> <TOKEN>'"
echo -n "> "
IFS=' ' read CMD NAME TOKEN
fi
if [ $CMD == 'get' ]; then
get $NAME
elif [ $CMD == 'add' ]; then
add $NAME $TOKEN
else
echo "Specify 'get' or 'add'"
exit 1
fi