#!/bin/sh
# Starte VMs

VMWARECMD=/usr/local/bin/vmware-cmd

case "$1" in
    start)
        echo -n 'Starting all VMware local VMs:'
	for vm in `$VMWARECMD -l` ; do
	    if $VMWARECMD $vm getstate | grep -i -q "off" ; then
		echo -n $vm
		$VMWARECMD $vm start
	    fi
	done
    ;;

    stop)
        echo -n 'Stoping all VMware local VMs:'
	for vm in `$VMWARECMD -l` ; do
	    if $VMWARECMD $vm getstate | grep -i -q "on" ; then
		echo -n $vm
		$VMWARECMD $vm stop
	    fi
	done
    ;;

    status)
        echo 'Status of all VMware local VMs:'
	for vm in `$VMWARECMD -l` ; do
	    echo "$vm :"
	    $VMWARECMD $vm getconnectedusers
	    $VMWARECMD $vm getstate
	    $VMWARECMD $vm getheartbeat
	done
    ;;

    restart)
        "$0" stop && "$0" start
    ;;

   *)
	echo "Usage: `basename "$0"` {start|stop|status|restart}"
	exit 1
esac

exit 0
