diff --git a/.bashrc b/.bashrc index 0e85158..f521e8d 100644 --- a/.bashrc +++ b/.bashrc @@ -128,22 +128,9 @@ alias config='/usr/bin/git --git-dir=/home/sstent/.cfg/ --work-tree=/home/sstent # Configure ssh forwarding -export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock -# need `ps -ww` to get non-truncated command for matching -# use square brackets to generate a regex match for the process we want but that doesn't match the grep command running it! -ALREADY_RUNNING=$(ps -auxww | grep -q "[n]piperelay.exe -ei -s //./pipe/openssh-ssh-agent"; echo $?) -if [[ $ALREADY_RUNNING != "0" ]]; then - if [[ -S $SSH_AUTH_SOCK ]]; then - # not expecting the socket to exist as the forwarding command isn't running (http://www.tldp.org/LDP/abs/html/fto.html) - echo "removing previous socket..." - rm $SSH_AUTH_SOCK - fi - echo "Starting SSH-Agent relay..." - # setsid to force new session to keep running - # set socat to listen on $SSH_AUTH_SOCK and forward to npiperelay which then forwards to openssh-ssh-agent on windows - (setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork &) > /dev/null 2>&1 +. ~/bin/wsl-ssh-agent-forwarder + -fi dockerbuild() { docker build -t registry.service.dc1.consul:5000/${1} ~/ansible-home/compose/${1}/ docker push registry.service.dc1.consul:5000/${1} diff --git a/bin/mc b/bin/mc new file mode 100755 index 0000000..306513a Binary files /dev/null and b/bin/mc differ diff --git a/bin/npiperelay.exe b/bin/npiperelay.exe new file mode 100755 index 0000000..e0302e3 Binary files /dev/null and b/bin/npiperelay.exe differ diff --git a/bin/sshnodes.sh.save b/bin/sshnodes.sh.save new file mode 100755 index 0000000..4fca498 --- /dev/null +++ b/bin/sshnodes.sh.save @@ -0,0 +1,25 @@ +#!/bin/sh + +# Set Session Name +SESSION="sshnodes" +SESSIONEXISTS=$(tmux list-sessions | grep $SESSION) + +# Only create tmux session if it doesn't already exist +if [ "$SESSIONEXISTS" = "" ] +then + # Start New Session with our name + tmux new-session -d -s $SESSION + tmux rename-window -t sshnodes + tmux split-window -v + tmux split-window -h + tmux selectp -t 0 + tmux split-window -h + tmux send-keys -t 0 "autossh odroid1" C-m + tmux send-keys -t 1 "autossh odroid2" C-m + tmux send-keys -t 2 "autossh odroid3" C-m + tmux customize-mode +fi + +# Attach Session, on the Main window +tmux attach-session -t $SESSION:0 + diff --git a/bin/wsl-ssh-agent-forwarder b/bin/wsl-ssh-agent-forwarder new file mode 100755 index 0000000..7843923 --- /dev/null +++ b/bin/wsl-ssh-agent-forwarder @@ -0,0 +1,28 @@ +#!/bin/bash +# Usage: wsl-ssh-agent-forward [ -k | -r ] +# Options: +# -k Kill the current process (if exists) and do not restart it. +# -r Kill the current process (if exists) and restart it. +# Default operation is to start a process only if it does not exist. + +export SSH_AUTH_SOCK=$HOME/.ssh/agent.sock + +sshpid=$(ss -ap | grep "$SSH_AUTH_SOCK") +if [ "$1" = "-k" ] || [ "$1" = "-r" ]; then + sshpid=${sshpid//*pid=/} + sshpid=${sshpid%%,*} + if [ -n "${sshpid}" ]; then + kill "${sshpid}" + else + echo "'socat' not found or PID not found" + fi + if [ "$1" = "-k" ]; then + exit + fi + unset sshpid +fi + +if [ -z "${sshpid}" ]; then + rm -f $SSH_AUTH_SOCK + ( setsid socat UNIX-LISTEN:$SSH_AUTH_SOCK,fork EXEC:"$HOME/bin/npiperelay.exe -ei -s //./pipe/openssh-ssh-agent",nofork & ) >/dev/null 2>&1 +fi