#!/bin/bash # Run a command on the machine that is hosting the current working # directory. To make this work, assume local and remote have the same # directory structure, and that the paths for NFS mounts have a # particular canonical form (from "readlink -f") # set -x PWD=$(pwd) ABS=$(readlink -f $PWD) if [ -z "$1" ]; then COMMAND="cd $PWD; exec bash" else # ssh command needs quoting COMMAND="cd $PWD; exec $(printf ' %q' "$@")" fi TTY=$(tty) [ 0 == $? ] && TTY_ARGS=-t exec_on_host() { exec ssh $TTY_ARGS -A $1 "$COMMAND" } path_field() { echo $ABS | cut -d/ -f$1 } # Not a /net node [ "net" != "$(path_field 2)" ] && exec "$@" # /net node. These are all of the form # 2 3 # /net/$HOST HOST=$(path_field 3) # Some special cases that do not follow the 'vol' case below. MAYBE_HOST=$(path_field 4) case "$MAYBE_HOST" in panda|core) exec_on_host $MAYBE_HOST ;; vol) # Handle below ;; *) exec_on_host $HOST ;; esac # Two options here: either it is an LXC filesystem exported by the # host, in which case we want to log into the LXC. Otherwise, treat # it as an exported directory on $HOST. # LXC directories are of the form # 2 3 4 5 6 7 # /net/$HOST/vol/$VOLUME_ID/$LXC_NAME/rootfs [ "rootfs" != "$(path_field 7)" ] && exec_on_host $HOST LXC_NAME=$(path_field 6) exec_on_host "$LXC_NAME"