Skip to content

Instantly share code, notes, and snippets.

@kelbyers
Last active October 10, 2015 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelbyers/3723986 to your computer and use it in GitHub Desktop.
Save kelbyers/3723986 to your computer and use it in GitHub Desktop.
bash startup script for cygwin, charade, pageant
#!/bin/bash
# NOTE: this is no longer necessary, the current version of charade works well with
# keychain, and the instructions on installing and using charade explain how to use
# them together by adding the following to your .bash_profile:
# eval `keychain -Q --eval`
# cygwin bash profile startup script, based off a post found here:
# http://russelldavis.blogspot.com/2011/02/using-charade-to-proxy-cygwin-ssh-agent.html
# Uses charade: https://github.com/wesleyd/charade
echo -n "ssh-agent..."
if [[ -n "$SSH_AUTH_SOCK" ]]; then
ssh-add -l 2>/dev/null | grep : > /dev/null
if [ $? = 0 ]
then
GOT_AGENT=1
else
GOT_AGENT=0
fi
fi
if ((GOT_AGENT==0)); then
for FILE in $(find /tmp/ssh-???* -type s -user ${USERNAME} -name "agent.[0-9]*" 2> /dev/null)
do
SSH_AUTH_SOCK=${FILE}
SOCK_PID=$(ls ${FILE%/agent.*}/stdout.[0-9]*)
SOCK_PID=${SOCK_PID##*.}
PID=$(ps -fu${USERNAME}|awk '/charade/ && ( $2=='${SOCK_PID}' || $3=='${SOCK_PID}' || $2=='${SOCK_PID}' +1 ) {print $2}')
SSH_AUTH_SOCK=${FILE}; export SSH_AUTH_SOCK;
SSH_AGENT_PID=${PID}; export SSH_AGENT_PID;
ssh-add -l 2>/dev/null | grep : > /dev/null
if [ $? = 0 ]
then
GOT_AGENT=1
break
fi
rm -rf ${FILE%/agent.*}
done
fi
if [[ $GOT_AGENT != 1 ]]
then
eval `~/bin/charade -s`
fi
unset GOT_AGENT SOCK_PID
echo -e "\t\t$SSH_AGENT_PID"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment