#!/bin/bash

# The username & password set in the drobo share
#  If no username was set use Anonymous and a blank password
drobo_user="Anonymous"
drobo_pass=""

# The ip of the drobo
drobo_ip=""

# Drobo network
drobo_network=`echo ${drobo_ip} | cut -f 1-3 -d .`

# The name of the share on the drobo
drobo_share=""

# Desktop Alias Name
alias_name="Drobo"

# The mount point to mount to
drobo_mount_point="/Volumes/${drobo_share}"

# The command to mount the share
drobomount="mount_smbfs //${drobo_user}:${drobo_pass}@${drobo_ip}/${drobo_share} ${drobo_mount_point}"

function isDroboMounted( ) {
	mount | grep -q ${drobo_mount_point}
	return $?
}


# Ensure we are actually on the network where we expect the drobo to be
ifconfig | grep -q ${drobo_network}
if [ ! $? -eq 0 ]
then
	exit 0
fi

# If the mount point doesn't exist we need to create it
if [ ! -d ${drobo_mount_point} ]
then
	# Make the mount point
	mkdir ${drobo_mount_point}
fi

# Make sure the link on the desktop exists
if [ ! -L ~/Desktop/${alias_name} ]
then
	ln -s ${drobo_mount_point} ~/Desktop/${alias_name}
fi

# Is the drobo mounted
isDroboMounted

if [ $? != 0 ]
then
	# Mount the dobo
	${drobomount}
fi

