#!/bin/bash

# mocha suv list
# mocha suv up
# mocha suv down
# mocha suv new

VAGRANT_MOCHADIR=/home/beckermj/Documents/Vagrant/mocha
VAGRANT_MACHINESDIR=$VAGRANT_MOCHADIR/machines

if [ "$1" == "list" ]; then

	ls $VAGRANT_MACHINESDIR

elif [ "$1" == "up" ]; then

	if [ "$2" != "" ]; then
		MACHINEPATH=$VAGRANT_MACHINESDIR/$2
		if [ -d "$MACHINEPATH" ]; then
			cd $MACHINEPATH
			vagrant up
		else
			echo "unknown machine named $2"
		fi
	else
		echo "usage: mocha suv up MACHINENAME"
	fi

elif [ "$1" == "down" ]; then

	if [ "$2" != "" ]; then

		MACHINEPATH=$VAGRANT_MACHINESDIR/$2
		if [ -d "$MACHINEPATH" ]; then
			cd $MACHINEPATH
			vagrant halt
		else
			echo "unknown machine named $2"
		fi
		
	else
		echo "usage: mocha suv down MACHINENAME"
	fi

elif [ "$1" == "shell" ]; then

	if [ "$2" != "" ]; then

		MACHINEPATH=$VAGRANT_MACHINESDIR/$2
		if [ -d "$MACHINEPATH" ]; then
			cd $MACHINEPATH
			vagrant ssh
		else
			echo "unknown machine named $2"
		fi
	else
		echo "usage: mocha suv shell MACHINENAME"
	fi

elif [ "$1" == "delete" ]; then

	if [ "$2" != "" ]; then

		MACHINEPATH=$VAGRANT_MACHINESDIR/$2
		if [ -d "$MACHINEPATH" ]; then
			cd $MACHINEPATH
			vagrant destroy
			if [ "$?" == "0" ]; then
				rm -rf $MACHINEPATH
			fi
		else
			echo "unknown machine named $2"
		fi
	else
		echo "usage: mocha suv delete MACHINENAME"
	fi

elif [ "$1" == "new" ]; then

	cd $VAGRANT_MOCHADIR
	
	if [ "$2" == "--transient" ]; then
		./provision --transient
	else
		./provision
	fi

else
	echo "usage: mocha suv new [--transient] | (up|down|shell|delete MACHINENAME) | list"

fi

