#! /bin/sh

# AFSClearCache	Check to see whether the AFS cache should be cleared
#
# chkconfig: 35 59 21
# description:  Clears the AFS cache if the file /AFSClearCache exists
#

. /etc/rc.d/init.d/functions

if [ -f /etc/sysconfig/afs ]; then
  . /etc/sysconfig/afs
else
  exit 0
fi

# Safe kickout
[[ -z "$CACHEDIR" ]] && exit 0
[[ -d "$CACHEDIR" ]] || exit 0

case "$1" in 
  start)
	if [ -f /AFSClearCache ]; then
          action $"Clearing AFS Cache: " rm -rf $CACHEDIR/* > /dev/null 2>&1
	  rm -f /AFSClearCache
	fi
	touch /var/lock/subsys/AFSClearCache
	;;
  status)
	if [ -f /AFSClearCache ]; then
	  echo $"AFS Cache will be cleared on reboot."
        fi
        ;;
  stop)
	if [ -f /AFSClearCache ]; then
	  echo $"AFS Cache will be cleared on reboot."
	fi
	rm -f /var/lock/subsys/AFSClearCache
	;;
  *)
	echo Usage: 'AFSClearCache <start|stop|status>'
esac

exit 0