You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
119 lines
2.2 KiB
119 lines
2.2 KiB
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
|
|
synopsis() {
|
|
cat << EOF
|
|
Usage : `basename $0` [-h] [option...] [login@]system:[path] mountpoint
|
|
EOF
|
|
}
|
|
|
|
help() {
|
|
cat << EOF
|
|
|
|
`basename $0` monte un répertoire du système virtuel dans un répertoire de l'hôte.
|
|
|
|
Remarque : nécessite fuse et sshfs.
|
|
|
|
`synopsis`
|
|
|
|
-h : affiche cette aide
|
|
|
|
Les options autorisées sont celles de sshfs(1).
|
|
|
|
Exemple :
|
|
|
|
mkdir /tmp/d
|
|
vdn-sshfs test@vm-1: /tmp/d # le HOME de test sur vm-1 est monté dans /tmp/d
|
|
|
|
# Pour démonter
|
|
fusermount -u /tmp/d
|
|
|
|
EOF
|
|
}
|
|
|
|
usage() {
|
|
synopsis
|
|
exit 1
|
|
}
|
|
|
|
|
|
args() {
|
|
OPTS=""
|
|
while [ $# -ne 0 ]; do
|
|
reg='^-'
|
|
if [[ "$1" =~ $reg ]]; then
|
|
OPTS="$OPTS $1"
|
|
case "$1" in
|
|
-h) help; exit 0;;
|
|
-b|-c|-D|-e|-F|-I|-i|-L|-l|-m|-O|-o|-p|-R|-S|-w)
|
|
OPTS="$OPTS $2"; shift;;
|
|
esac
|
|
shift
|
|
else
|
|
break
|
|
fi
|
|
done
|
|
|
|
LOGIN=""
|
|
DIR=""
|
|
GUEST_NAME="$1"
|
|
|
|
if echo $1 | grep -q -- '@'; then
|
|
LOGIN=`echo $1 | cut -d '@' -f 1`@
|
|
GUEST_NAME=`echo $1 | cut -d '@' -f 2`
|
|
|
|
if ! echo $GUEST_NAME | grep -q -- ':'; then
|
|
usage
|
|
fi
|
|
|
|
DIR=$(echo $GUEST_NAME | cut -d ':' -f 2)
|
|
GUEST_NAME=$(echo $GUEST_NAME | cut -d ':' -f 1)
|
|
fi
|
|
|
|
shift
|
|
|
|
set +u
|
|
MOUNT_DIR="$1"
|
|
[ -z "$MOUNT_DIR" -o -n "$2" ] && usage
|
|
set -u
|
|
}
|
|
|
|
# Programme principal
|
|
|
|
GUEST_OWNER=$USER
|
|
|
|
VDN_PATH=$(readlink -f $(dirname $0)/..); . $VDN_PATH/bin/functions.sh
|
|
|
|
args "$@"
|
|
|
|
#if [ $GUEST_NAME = nested ]; then
|
|
# SSH_REDIR_PORT=2222
|
|
#else
|
|
[ ! -e $TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-redirs ] &&
|
|
error "Impossible de joindre $GUEST_NAME"
|
|
|
|
SSH_REDIR_PORT=`cat $TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-redirs | \
|
|
sed -rne 's/^tcp:([0-9]+):22(:|$).*$/\1/p'`
|
|
|
|
[ -z "$SSH_REDIR_PORT" ] && error "Impossible de joindre $GUEST_NAME"
|
|
#fi
|
|
|
|
# No master mode when X11 forwarding
|
|
echo $OPTS | grep -q -- -X && {
|
|
#echo "Workaround X11 forwarding" >&2
|
|
SSH_GUEST_MASTER=0
|
|
}
|
|
|
|
SSH_MASTER=""
|
|
[ $SSH_GUEST_MASTER = 1 ] && {
|
|
sshGuestControlMaster
|
|
SSH_MASTER="$SSH_OPTS -o ControlPersist=10m -o ControlMaster=auto,ControlPath=$TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-guest-%r@%h:%p"
|
|
}
|
|
|
|
|
|
set +e
|
|
|
|
#ssh $SSH_MASTER $SSH_OPTS -o ServerAliveInterval=5 $OPTS -p $SSH_REDIR_PORT ${LOGIN}localhost "$COMMAND"
|
|
sshfs ${LOGIN}localhost:$DIR $MOUNT_DIR $SSH_MASTER $SSH_OPTS -o ServerAliveInterval=5 $OPTS -p $SSH_REDIR_PORT
|