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.
IUT/vdn/bin/vdn-restore-extra-eth

100 lines
1.8 KiB

#!/usr/bin/env bash
set -eu
VAR=""
synopsis() {
cat << EOF
Usage : `basename $0` [-h] system
EOF
}
help() {
cat << EOF
`basename $0` restaure l'état de l'interface suppémentaire utilisée pour
joindre la machine virtuelle (précisée en argument).
Exemple : `basename $0` bigboss
`synopsis`
-h : affiche cette aide
EOF
}
usage() {
synopsis
exit 1
}
args() {
local opt
while getopts "h" opt; do
case $opt in
h) help; exit 0;;
?) usage;;
esac
done
shift $(($OPTIND - 1))
[ $# -ne 1 ] && usage
GUEST_NAME="$1"
}
# Programme principal
VDN_PATH=$(readlink -f $(dirname $0)/..); . $VDN_PATH/bin/functions.sh
args "$@"
setGuestVars $GUEST_NAME
GUEST_OWNER=$USER
loadGuestVars $GUEST_NAME
vdn-infos $GUEST_NAME GUEST_NAME > /dev/null || exit 1
if ! $VDN_PATH/bin/vdn-alive $GUEST_NAME; then
error "Le système $GUEST_NAME n'est pas démarré !"
fi
[ ! -e $TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-serial ] && \
error "$TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-serial not found !"
echo "ok"
CMD="
stty -echo
PS1=
ls /tmp
iptables -F
iptables -F -t nat
iptables -L
iptables -L -t nat
eth=\$(ip a | egrep '^[0-9]+:' | sed -re 's/^.*(eth[0-9]+).*$/\1/' | tail -n 1)
echo eth=\$eth
ip a flush \$eth
dhclient \$eth
ip a show dev \$eth
ip a show dev \$eth | grep -q 10.0.2.15 && echo ok || echo ERROR
"
#echo socat STDIO UNIX-CLIENT:$TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-serial
(echo "$CMD"; sleep 1) | socat STDIO UNIX-CLIENT:$TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-serial
echo
#echo "$CMD" | socat STDIO UNIX-CLIENT:$TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-serial
#socat STDIO UNIX-CLIENT:$TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-serial
#cat << EOF | socat STDIO UNIX-CLIENT:$TMPDIR/vdn-$GUEST_NAME-$GUEST_OWNER-serial
#ip a | egrep '^[0-9]+:' | sed -re 's/^.*(eth[0-9]+).*$/\1/' | tail -n 1"
#EOF