#!/bin/sh -e
#
# Copyright (C) 2007,2008 Canonical, Ltd.
# Author: Jamie Strandboge <jamie@canonical.com>
# License: GPLv3
#
# Simple viewer script to start virt-viewer for listed VMs
#

ustconf="$HOME/.uqt-vm-tools.conf"
if [ -s "$ustconf" ]; then
    . "$ustconf"
else
    echo "Could not find '$ustconf'"
    exit 1
fi

. $UQT_VM_TOOLS/libvm.sh
abort_if_root

help() {
    echo "Usage: vm-view <vm1> <vm2>"
}

if [ -z "$1" ]; then
    help
    exit 1
fi

cd /tmp
for i in "$@" ; do
    if ! vm_exists $i ; then
        echo "'$i' does not exist"
        continue
    fi

    if ! vm_running $i ; then
        echo "'$i' is not running"
        continue
    fi

    nohup virt-viewer -c ${vm_connect} "$i" 2>/dev/null &
done

exit 0
