#!/bin/sh

# source options

if [ $# -ne 1 ]; then
	echo "Usage: $0 OPTIONS_FILE"
	exit 2
fi

OPTIONS="$1"

if [ ! -r "$OPTIONS" ]; then
	echo "Cannot read options from \`$OPTIONS', exiting."
	exit 1
fi

. "$OPTIONS"

export SERVER NFS_HOME HACK_HOME SOURCE BIN DEST REPO META REPODIR METADIR

echo "Executing modification scenarios from $BIN:"

for FILE in `ls "$BIN"`
do
	SCENARIO="$BIN/$FILE"
	if [ ! -f "$SCENARIO" ]; then
		echo "\`$SCENARIO' is not an ordinary file, omitting..."
		continue
	fi
	if [ ! -x "$SCENARIO" ]; then
		echo "\`$SCENARIO' is not executable, omitting..."
		continue
	fi
	echo "[$FILE]"
	# oh...
	"$SCENARIO"
	RETVAL=$?
	if [ $RETVAL -ne 0 ]; then
		echo "Warning: \`$FILE' return value is $RETVAL (non-zero)"
	fi
done

echo "Modification complete."

