#!/bin/sh -

#
# This script shuts down Xsan on the local system in preparation for
# upgrading an existing version of Xsan.
#

launchctl="/usr/libexec/StartupItemContext /bin/launchctl"

if [ -f /System/Library/CoreServices/ServerVersion.plist ]; then
	Is_Server=yes
else
	Is_Server=no
fi

#
# In this case, all we need to do is stop Xsan itself.
#
if [ -f /System/Library/LaunchDaemons/com.apple.xsan.plist ]; then
	${launchctl} unload /System/Library/LaunchDaemons/com.apple.xsan.plist
	sleep 5
	/sbin/kextunload /System/Library/Extensions/acfsctl.kext
	/sbin/kextunload /System/Library/Extensions/acfs.kext
elif [ -x /System/Library/StartupItems/acfs/acfs ]; then
	/usr/libexec/StartupItemContext /System/Library/StartupItems/acfs/acfs stop
	rm -Rf /System/Library/StartupItems/acfs
fi

if [ ${Is_Server} != "yes" ]; then
	if [ -e /System/Library/LaunchDaemons/com.apple.serialnumberd.plist ]; then
		${launchctl} unload /System/Library/LaunchDaemons/com.apple.serialnumberd.plist
	fi
	if [ -f /System/Library/LaunchDaemons/com.apple.SNServer.plist ]; then
		${launchctl} unload \
		    /System/Library/LaunchDaemons/com.apple.SNServer.plist
	fi
	if [ -x /System/Library/StartupItems/SerialNumberSupport/SerialNumberSupport ]; then
		/usr/libexec/StartupItemContext /System/Library/StartupItems/SerialNumberSupport/SerialNumberSupport stop
	fi
	/usr/bin/killall serialnumberd 2> /dev/null
fi
