#!/bin/sh


### BEGIN INIT INFO
# Provides:          restoreVMsStates
# Required-Start:
# Required-Stop:
# Default-Start:     S
# Default-Stop:      0 6
# Short-Description: Restores the state of VMs.
### END INIT INFO

# /m23/vms/bin/restoreVMsStates
# Restores the state of VMs.
# (C) Hauke Goos-Habermann <hhabermann@pc-kiel.de>


#Don't execute, if it should be stopped
if [ $# -gt 0 ] && [ $1 = "stop" ]
then
	exit 0
fi

#Start all machines that were started last
for vmcmd in `ls /m23/vms/runningVMs/`
do
	f="/m23/vms/runningVMs/$vmcmd"
	chown m23-vbox "$f"
	chmod +x "$f"
	sudo -i -u m23-vbox "$f"
done