#!/usr/bin/ksh

base=$0
USERSAKAIQUOTA="5000"


FILEPATH=$1
VOLTYPE=$2
INSTANCENAME=$3


VERBOSE="true"
VFLAG="-verbose"
FS=fs
VOS=vos
KLOG=klog
SEPARATOR=/.sakai/

CAMPUSACL="samerson rlidwka system:administrators rlidwka"
VMACL="samerson rlidwka system:administrators rlidwka"


# log user mount point creation
[ "$VERBOSE" ] && print "creating path $FILEPATH"

#### this portion klogs for the auth user, dependent upon instance

#### TODO: REMOVE Klog call below
$KLOG -cell home.ucdavis.edu 

## CHECK INSTANCE, AND SET ACL APPROPRIATELY
if [[ $INSTANCE == "smartsite" ]] then
	$INSTANCEACL=$CAMPUSACL
elif [[ $INSTANCE == "vetmed" ]] then
	$INSTANCEACL=$VMACL
else print $INSTANCEACL
fi	





# check if volume exists
if [[ $VOLTYPE == "user" ]] then
	print "this is user type volume check for.. "
	print "$FILEPATH$SEPARATOR$INSTANCENAME"
        if [[ ! -d $FILEPATH$SEPARATOR$INSTANCENAME ]] then
		print "directory doesn't exist for this user, try to create it"
		mkdir $FILEPATH$SEPARATOR$INSTANCENAME
		if [[ $? -ne 0  ]] then
			print "problem making directory under insance"
			exit 2
		else
		   # set acl on volume (directory)
		   $FS setacl $FILEPATH$SEPARATOR$INSTANCE $INSTANCEACL
		fi
	else
		print "directory exists for this instance"
		exit 1
	fi	
elif [[ $VOLTYPE == "project" ]] then
	print "this is project type volume check"
elif [[ $VOLTYPE == "course" ]] then
	print "this is a course type volume check"
else
	print "this is a misc volume check"
fi

if [[ ! -d $FILEPATH ]] then
	[ $VERBOSE ] && print "creating $FILEPATH"
	if [[ $? -ne 0 ]] then
		print "$base: error creating $FILEPATH"
		exit 1
	fi
fi
