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.
125 lines
2.3 KiB
125 lines
2.3 KiB
#!/usr/bin/env bash
|
|
|
|
set -eu
|
|
#set -x
|
|
|
|
#[ "$USER" = "gudavala" ] && set -x || :
|
|
|
|
NO_MASTER=0
|
|
|
|
# ATTENTION : Ce script ne doit rien afficher sur la sortie standard
|
|
# car utilisé pour la sauvegarde.
|
|
|
|
synopsis() {
|
|
cat << EOF
|
|
Usage : `basename $0` [-h] [option...] [login@]system [command]
|
|
EOF
|
|
}
|
|
|
|
help() {
|
|
cat << EOF
|
|
|
|
`basename $0` démarre une connexion ssh à destination d'un système virtuel.
|
|
|
|
`synopsis`
|
|
|
|
-h : affiche cette aide
|
|
-n : no master mode (utile dans certains cas)
|
|
|
|
Les options autorisées sont celles de ssh(1).
|
|
|
|
Exemple :
|
|
|
|
vdn-ssh -X root@vm-1 # -X pour recevoir les fenêtres graphiques de vm-1.
|
|
|
|
# Pour quitter le shell distant :
|
|
exit
|
|
|
|
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;;
|
|
-n) NO_MASTER=1;;
|
|
-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=""
|
|
|
|
GUEST_NAME="$1"
|
|
|
|
if echo $1 | grep -q -- '@'; then
|
|
LOGIN=`echo $1 | cut -d '@' -f 1`@
|
|
GUEST_NAME=`echo $1 | cut -d '@' -f 2`
|
|
fi
|
|
|
|
shift
|
|
|
|
COMMAND="$@"
|
|
}
|
|
|
|
# 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
|
|
|
|
#set -x
|
|
|
|
[ ! -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 -a $NO_MASTER != 1 ] && {
|
|
sshGuestControlMaster
|
|
SSH_MASTER="$SSH_OPTS -o ControlPersist=10m -o ControlMaster=auto -S $TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-guest-%r@%h:%p"
|
|
}
|
|
|
|
set +e
|
|
export TERM=xterm-256color
|
|
|
|
#if [ -z "$COMMAND" ]; then
|
|
# COMMAND="bash"
|
|
#fi
|
|
|
|
#COMMAND="export http_proxy=$http_proxy; export https_proxy=$https_proxy; $COMMAND"
|
|
#set -x
|
|
ssh $SSH_MASTER $SSH_OPTS -o ServerAliveInterval=5 $OPTS -p $SSH_REDIR_PORT ${LOGIN}localhost "$COMMAND"
|