-
Notifications
You must be signed in to change notification settings - Fork 0
/
otp
executable file
·51 lines (46 loc) · 1.02 KB
/
otp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
scriptname=$(basename $0)
keyfile="$2"
if [[ -z "$keyfile" ]]; then keyfile="$HOME/.otpkeys"; fi
findfile=0
if cat "$keyfile" > /dev/null 2>&1; then
findfile=0
else
findfile=1
fi
scriptdir="${BASH_SOURCE%/*}"
if [[ ! -d "$scriptdir" ]]; then scriptdir="$PWD"; fi
if [[ ! $findfile -eq 0 ]]
then
echo "No keyfile found. "
echo "Currently looking for "
echo " $keyfile"
echo " but it is not there"
echo ""
echo "Fixes: Either create the file or specify a keyfile"
echo "with"
echo " ./otp keyname keyfile"
exit
fi
if [ -z $1 ]
then
echo "$scriptname: Service Name Needed"
echo ""
echo "Usage:"
echo " otp keyname (keyfile)"
echo ""
echo "Examples:"
echo " otp google"
echo " otp google mykeyfile"
echo ""
echo "Configuration: $keyfile"
echo "Format: name=key"
exit
fi
otpkey=$(cat "$keyfile" | grep "$1" | cut -d"=" -f 2 | sed "s/ //g")
if [ -z "$otpkey" ]
then
echo "$scriptname: Bad Service Name"
exit
fi
/usr/bin/python "$scriptdir/token.py" --totp "$otpkey"