#! /bin/sh
#======================================================================
# Copyright 2008 (C) Nicira, Inc.
# 
# This file is part of NOX.
# 
# NOX is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# NOX is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with NOX.  If not, see <http://www.gnu.org/licenses/>.
#======================================================================
set_title() {
    printf "\033]0;$1\007" # Set xterm title
}
screen -wipe
echo "Waiting for $1 VM..."
set_title "Waiting for $1 VM..."
while true; do
    for d in /var/run/screen/S-$LOGNAME/*.$1; do
        if test -e "$d"; then
	    set_title "$1 VM"
            screen -r $1
            if ! test -e "$d"; then
                stop-test-vm
            fi
            if test "$2" = "--once"; then
                exit 0
            fi
	    echo "Waiting for $1 VM..."
	    set_title "Waiting for $1 VM..."
        fi
    done
    sleep 2
done
