8 ssh-agent-finder - Find a working ssh agent on the system so you get the same in each of your logon sessions
12 . ssh-agent-finder -Iva
25 .
/usr
/lib
/tool
/bash-utils
30 Usage
="Usage: $0 [-IkKav]
31 -I No interactive, use first socket
32 -k Use socket having keys (default)
33 -K Use socket not necessary having keys
36 if [ .
"$1" = .
--help ]
41 while getopts hIkKav opt
"$@"
48 K
) must_have_keys
='';;
49 a
) list_all_sockets
=1;;
57 if [ $must_have_keys ]
59 might_have_keys_or_not
=''
61 might_have_keys_or_not
=1
66 if [ "$0" != "$BASH_SOURCE" ]
85 for file in /tmp
/ssh-
*/agent.
* $HOME/.gnupg
/S.gpg-agent.
ssh $HOME/.cache
/keyring-
*/ssh
89 SSH_AUTH_SOCK
=$file capture2 ssh-add
-l
100 if [ $must_have_keys ]
107 # code == 2: non-functioning socket
113 if [[ ( ( $might_have_keys_or_not ||
$has_keys ) && ( $interactive ||
$verbose ) ) ||
$list_all_sockets ]]
116 if [ "$SSH_AUTH_SOCK" = "$file" ]
118 echo -n "(current) *** "
120 echo "SSH_AUTH_SOCK $file"
121 [ -n "$capture2_stdout" ] && echo "$capture2_stdout"
122 [ -n "$capture2_stderr" ] && echo "$capture2_stderr" >&2
125 if [[ $live_socket && ( ( $might_have_keys_or_not ||
$has_keys ) ||
$list_all_sockets ) ]]
130 [[ $might_have_keys_or_not ||
$has_keys ]] && default
=Y || default
=N
131 read -e -p "Use this socket? [$default] "
132 [ -n "$REPLY" ] || REPLY
=$default
135 [ "$REPLY" = Y
] && use
=1
141 export SSH_AUTH_SOCK
=$file
144 echo "export SSH_AUTH_SOCK='${file//\'/\'\\\'\'}'"