Commit | Line | Data |
---|---|---|
59f0d218 FF |
1 | #!/bin/sh |
2 | # source-ssh-agent: Script to source for ssh-agent to work | |
3 | # From http://mah.everybody.org/docs/ssh | |
4 | ||
5 | # Check if accidentaly executed instead of sourced: | |
6 | if echo "$0" | grep -q source-ssh-agent; then | |
7 | echo "source-ssh-agent: Do not execute directly - source me instead!" | |
8 | exit 1 | |
9 | fi | |
10 | ||
11 | SSH_ENV="$HOME/.ssh/environment" | |
12 | ||
13 | start_agent () { | |
14 | ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" | |
15 | chmod 600 "${SSH_ENV}" | |
16 | . "${SSH_ENV}" > /dev/null | |
17 | ssh-add | |
18 | } | |
19 | ||
20 | if [ -f "${SSH_ENV}" ]; then | |
21 | . "${SSH_ENV}" > /dev/null | |
22 | if ps ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null; then | |
23 | # Agent already running, but it may be running without identities: | |
24 | if ssh-add -L 2> /dev/null | grep -q 'no identities'; then | |
25 | # .. in which case we add them: | |
26 | ssh-add | |
27 | fi | |
28 | else | |
29 | start_agent; | |
30 | fi | |
31 | else | |
32 | start_agent; | |
33 | fi |