-
Notifications
You must be signed in to change notification settings - Fork 1
/
ssh-find-auth-sock
executable file
·43 lines (34 loc) · 1.05 KB
/
ssh-find-auth-sock
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
#!/bin/sh
# cpennello 2015-02-04 Find SSH authorization socket for $USER and print
# its path to standard out. If not found, return exit status 1.
set -e
search() {
basedir=$1
dirprefix=$2
sockprefix=$3
# -maxdepth 1 since we can't look inside /tmp/lost+found on some hosts
# without root privileges. In general though, we just don't need to
# look more deeply than the first level of directories in $basedir.
sock_dirs=`find $basedir -maxdepth 1 -type d -and -user $USER \
-and -name "$dirprefix*"`
if [ -z "$sock_dirs" ]; then
exit 1
fi
# Note that if $sockprefix is unspecified, this still works.
socks=`find $sock_dirs -type s -and -name "$sockprefix*"`
if [ -z "$socks" ]; then
exit 1
fi
# Print the path to the first one only if multiple were found.
sock=`echo "$socks" | head -n 1`
echo $sock
}
search_Darwin() {
# Macs have other weird sockets in directories with this prefix. We
# want only Listeners.
search /private/tmp com.apple.launchd. Listeners
}
search_Linux() {
search /tmp ssh-
}
search_`uname`