Fredrik Fornwall
8 years ago
1 changed files with 15 additions and 23 deletions
@ -1,33 +1,25 @@ |
|||||
#!/bin/sh |
#!/data/data/com.termux/files/usr/bin/sh |
||||
# source-ssh-agent: Script to source for ssh-agent to work |
# source-ssh-agent: Script to source for ssh-agent to work. |
||||
# From http://mah.everybody.org/docs/ssh |
|
||||
|
|
||||
# Check if accidentaly executed instead of sourced: |
# Check if accidentaly executed instead of sourced: |
||||
if echo "$0" | grep -q source-ssh-agent; then |
if echo "$0" | grep -q source-ssh-agent; then |
||||
echo "source-ssh-agent: Do not execute directly - source me instead!" |
echo "source-ssh-agent: Do not execute directly - source me instead!" |
||||
exit 1 |
exit 1 |
||||
fi |
fi |
||||
|
|
||||
SSH_ENV="$HOME/.ssh/environment" |
export SSH_AUTH_SOCK=$PREFIX/tmp/ssh-agent |
||||
|
|
||||
start_agent () { |
start_agent () { |
||||
ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}" |
rm -f $SSH_AUTH_SOCK |
||||
chmod 600 "${SSH_ENV}" |
ssh-agent -a $SSH_AUTH_SOCK > /dev/null |
||||
. "${SSH_ENV}" > /dev/null |
ssh-add |
||||
ssh-add |
|
||||
} |
} |
||||
|
|
||||
if [ -f "${SSH_ENV}" ]; then |
MESSAGE=`ssh-add -L 2>&1` |
||||
. "${SSH_ENV}" > /dev/null |
if [ "$MESSAGE" = 'Could not open a connection to your authentication agent.' -o \ |
||||
if ps ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null; then |
"$MESSAGE" = 'Error connecting to agent: Connection refused' -o \ |
||||
# Agent already running, but it may be running without identities: |
"$MESSAGE" = 'Error connecting to agent: No such file or directory' ]; then |
||||
if ssh-add -L 2> /dev/null | grep -q 'no identities'; then |
start_agent |
||||
# .. in which case we add them: |
elif [ "$MESSAGE" = "The agent has no identities." ]; then |
||||
ssh-add |
ssh-add |
||||
fi |
|
||||
else |
|
||||
start_agent; |
|
||||
fi |
|
||||
else |
|
||||
start_agent; |
|
||||
fi |
fi |
||||
|
Loading…
Reference in new issue