#!/bin/bash
#
# This script blocks the machine from becoming available
#
# usage: setDATSstate state [option]
# 
# state: 
#	-available -  makes the machine available to the grid
#	-block	   -  blocks the machine from becoming available to the grid
#
# option:
#	-next -	  state exists until after the end time of			#		  the upcoming schedule [defalut]
#	-all  -   state exists unitl user runs set_DATS_schedule
#

. /etc/autobench.conf || . functions

AVAILABLE=available
BLOCKED=blocked
SCHEDULED=scheduled:

AVAIL_FILE=$AUTODIR/var/DATS_available
SCHED_FILE=$AUTODIR/var/DATS_schedule

if [ $# -lt 1 ]; then
	echo "Usage: setDATSstate -block | -available [-next | -all]"
	exit 1

elif [ "$1" = "-available" ]; then
	if [ $# -lt 2 ] || [ "$1" = "-next" ]; then
		echo -e $AVAILABLE '\n' $SCHEDULED  `date '+%D'` > $AVAIL_FILE
	else
		echo -e $AVAILABLE  > $SCHED_FILE
	fi

elif [ "$1" = "-block" ]; then
	if [ $# -lt 2 ] || [ "$1" = "-next" ]; then
		echo -e $BLOCKED '\n' $SCHEDULED  `date '+%D'` > $AVAIL_FILE
	else
		echo -e $BLOCKED  > $SCHED_FILE

	fi

else
	echo "Usage: setDATSstate -block | -available [-next | -all]"
	exit 1
fi

