forked from mogensen/keychain
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkeychain.sh
executable file
·52 lines (45 loc) · 862 Bytes
/
keychain.sh
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
52
#!/bin/bash
GETPASS=0
GETUSER=0
DEBUG=0
KEYCHAIN=""
while [ "$1" != "" ]
do
case $1
in
-p) GETPASS=1;
shift 1;;
-u) GETUSER=1;
shift 1;;
-s) SERVICE=$2;
shift 2;;
-k) KEYCHAIN=$2;
shift 2;;
-d) DEBUG=1;
shift 1;;
*) echo "Option [$1] not one of [p, u, s, k, d]"; # Error (!)
exit;;
esac
done
if test $DEBUG -gt 0 ; then
echo "DEBUG INFO"
echo " -p = $GETPASS"
echo " -u = $GETUSER"
echo " -s = $SERVICE"
echo " -k = $KEYCHAIN"
echo " -d = $DEBUG"
fi
SEC=`security find-generic-password -s $SERVICE -g $KEYCHAIN 2>&1`
function getAttribute() {
echo `echo "$SEC" | grep "$1" | cut -d \" -f 4`
}
# Get username (account)
if test $GETUSER -gt 0 ; then
getAttribute "acct"
exit 0
fi
# Get password
if test $GETPASS -gt 0 ; then
echo `echo "$SEC" | grep "password" | cut -d \" -f 2`
exit 0
fi