Guest User

win32_ssh_agent_bridge.sh

a guest
Mar 8th, 2021
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.21 KB | None | 0 0
  1. # Run it with: (You may add it to your ~/.bashrc)
  2.  
  3. ( nohup setsid win32_ssh_agent_bridge.sh 2> >(nohup setsid tee /tmp/openssh-ssh-agent.err.log > /dev/null 2>&1) > /tmp/openssh-ssh-agent.log & )
  4.  
  5. # ---- win32_ssh_agent_bridge.sh starts ----
  6.  
  7. #!/bin/bash
  8. PIDFILE=/var/run/openssh-ssh-agent.$(awk '/btime/{print $2}' /proc/stat).pid
  9. if [ -f $PIDFILE ]
  10. then
  11.   PID=$(cat $PIDFILE)
  12.   ps -p $PID > /dev/null 2>&1
  13.   if [ $? -eq 0 ]
  14.   then
  15.     echo "[ssh-agent bridge already running]"
  16.     exit 1
  17.   else
  18.     ## Process not found assume not running
  19.     echo $$ > $PIDFILE
  20.     if [ $? -ne 0 ]
  21.     then
  22.       echo "[ssh-agent bridge] Could not create PID file" >&2
  23.       exit 1
  24.     fi
  25.   fi
  26. else
  27.   echo $$ > $PIDFILE
  28.   if [ $? -ne 0 ]
  29.   then
  30.     echo "[ssh-agent bridge] Could not create PID file" >&2
  31.     exit 1
  32.   fi
  33. fi
  34. # Main script ... Do work here
  35. echo [ssh-agent bridge start]
  36. unlink /tmp/openssh-ssh-agent > /dev/null 2>&1
  37. PLINK_PATH=$(which -a plink | tail -1)
  38. ln -sf "$PLINK_PATH" /usr/local/bin/plink_for_agent
  39. socat UNIX-LISTEN:/tmp/openssh-ssh-agent,umask=066,fork EXEC:"/usr/local/bin/plink_for_agent -serial //./pipe/openssh-ssh-agent",pipes
  40. echo [ssh-agent bridge ended] >&2
  41. # End
  42. rm $PIDFILE
Advertisement
Add Comment
Please, Sign In to add comment