-
Notifications
You must be signed in to change notification settings - Fork 0
/
.bashrc-ssh-agent
executable file
·51 lines (46 loc) · 1.07 KB
/
.bashrc-ssh-agent
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
#!/usr/bin/env bash
if test -z "$LOCALPORT" -o "$LOCALPORT" = 22; then
agent_file=~/.config/system-config/ssh-agent
else
agent_file=~/.config/system-config/ssh-agent-$LOCALPORT
fi
start_ssh_agent() {
(
set -e
umask 077
mkdir -p ~/.config/system-config/
ssh-agent > $agent_file.$$
grep "^echo" -v $agent_file.$$ > $agent_file.$$.2
rm $agent_file.$$
mv $agent_file.$$.2 $agent_file
)
. $agent_file
}
if test ! -e $agent_file; then
echo 1>&2 no ssh-agent found, restart it
start_ssh_agent
else
. $agent_file
fi
if ssh-add -l >/dev/null 2>&1; then
val=$?
else
val=$?
fi
if test $val = 2; then
echo 1>&2 "can't connect to ssh-agent, restart it"
rm $agent_file
start_ssh_agent
fi
if test $val != 0 -a -e ~/.ssh/id_rsa && tty >/dev/null 2>&1; then
echo "Need add the rsa"
if test "$SSH_CLIENT"; then
if test -e ~/.ssh/add-id_rsas; then
bash ~/.ssh/add-id_rsas;
else
ssh-add ~/.ssh/id_rsa
fi
else
do-ssh-add
fi
fi