4 usage
="Usage: $0 [-bc] [COMMAND [ARGS...]]"
7 case "${SHELL-/bin/sh}" in
11 force
=nil chosen
= commands
=
12 while [ $# -gt
0 ]; do
14 -h |
--help) echo "$usage"; exit 0 ;;
15 -c |
--cshell |
--tcsh
) style
=csh chosen
=t
;;
16 -b |
--bourne |
--bash |
--zsh
) style
=sh chosen
=t
;;
17 -f |
--force
) force
=t
;;
19 -*) echo >&2 "$usage"; exit 1 ;;
24 [ $# -gt
0 ] && style
=commands
25 case $chosen,$style in
27 echo >&2 "$0: output style and commands? you're odd"
32 ## Some useful variables.
33 hostname
=${HOST-$(hostname)}
34 user
=${USER-${LOGNAME-$(id -un)}} uid
=${UID-$(id -u)}
35 dir
=$TMPDIR/.ssh-agent.
$hostname.
$user
36 socket
=$dir/sock
; pid
=$dir/pid
39 ## Should I start a new agent?
43 case ${SSH_AUTH_SOCK+t} in
45 set +e
; ssh-add
-l
>/dev
/null
2>&1; rc
=$?
; set -e
46 if [ $rc -lt
2 ]; then foundp
=t
; fi
53 "$HOME/.cache/keyring-"*"/ssh" \
54 "/run/user/$uid/keyring/ssh" \
58 set +e
; ssh-add
-l
>/dev
/null
2>&1; rc
=$?
; set -e
59 if [ $rc -lt
2 ]; then foundp
=t
; break; fi
74 case $p in *:*) d
=${p%%:*} p
=${p#*:} ;; *) d
=$p p
= ;; esac
75 if [ -x
"${d+$d/}setsid" ]; then runes
="$runes setsid"; break; fi
76 case $p in "") break ;; esac
78 set +e
; ssh-add
-l
>/dev
/null
2>&1; rc
=$?
; set -e
79 if [ $rc -ge
2 ]; then
80 if [ -f
"$pid" ]; then
81 kill $
(cat "$pid") >/dev
/null
2>&1 ||
:
83 rm -f
"$socket" "$pid"
84 (cd /; exec $runes ssh-agent
-d
-a
"$socket" </dev
/null
>/dev
/null
2>&1)&
91 ### Run a program, or export the details
93 sh
) echo "SSH_AUTH_SOCK='$SSH_AUTH_SOCK'; export SSH_AUTH_SOCK" ;;
94 csh
) echo "setenv SSH_AUTH_SOCK '$SSH_AUTH_SOCK'" ;;
95 commands
) exec "$@" ;;