#!/bin/sh MASTER=11edf02e95ceac1fa58d4444f82f8cd4ae9c1cf5 # command tu run via the ssh socket run() { # no test if running init if [ "$MASTER" != "" ] then # test if distant has OUR git ssh -S "$1" XXX '[ -e /usr/bin/git ] && [ -d .git ] && git rev-list --reverse master 2>/dev/null | head -1' | grep "$MASTER" > /dev/null else ssh -S "$1" XXX '[ -e /usr/bin/git ]' fi if [ $? -eq 0 ] then # if yes push updates tmp=$(mktemp ~/.sshgit.XXXXXX) echo "#!/bin/sh" > $tmp echo "exec ssh -S $1 \"\$@\"" >> $tmp chmod +x $tmp GIT_SSH=$tmp git push --all ssh://XXX/~ > /dev/null 2> /dev/null rm -f $tmp ssh -S "$1" XXX 'git checkout -f > /dev/null' fi } # command tu run via the ssh socket runscp() { files=$(git ls-files) cd for i in $files do scp -q -o "ControlPath $1" -p $i XXX:~/$i done } # test if we are the child which can connect via the master if [ "$1" == "-=0" ] then go=0 # limit to 60 retries x 1s for i in $(seq 1 60) do sleep 1 # try to connect via master ssh -S "$2" -O check xxx 2>/dev/null if [ $? -eq 0 ] then go=1 break fi done # run the stealth command if [ $go -eq 1 ] then sleep 1 # bug if we go too fast if [ "$4" == "1" ] then # init mode = no init check MASTER="" # init mode = git init ssh -S "$2" XXX '[ -e /usr/bin/git ] && [ ! -d .git ] && git init > /dev/null' fi # test for rsync mode if [ "$4" == "2" ] then runscp "$2" else run "$2" fi fi # remove master socket if we created it if [ "$3" == "0" ] then rm -f "$2" fi exit 0 fi init=0 # test if we are in init mode if [ "$1" == "-=" ] then init=1 # remove -= shift fi # test if we are in scp mode if [ "$1" == "-=scp" ] then init=2 # remove -=scp shift fi # we are in a real ssh command master=0 sock="" for i in "$@" do # test if master is already provided if [ "$i" == "-M" ] then master=1 fi # retrieve socket if provided if [ "$i" == "-S" ] then sock="."; fi if [ "$i" == "." ] then sock="$i" fi done # create socket name if needed if [ "$sock" == "" ] then sock=$(mktemp -u -t sshx.XXXXXX) fi # launch child which will use our master socket $0 -=0 "$sock" "$master" "$init" & # run original command adding a master socket if [ $master -eq 1 ] then exec ssh "$@" else exec ssh -S "$sock" -M "$@" fi