#! /bin/bash
#
# captive          mount/unmount the captive-* (FUSE) filesystems.
#
# chkconfig: 2345 99 01
# description: Captive allows applications running under the GNU/Linux
#              operating system to access NTFS drives. File system driver
#              compatibility with VFAT, ISO9660 and EXT2 is also provided.

# Source function library.
. /etc/init.d/functions

# Never drop this lock - we need to catch manually mounts on system shutdown.
touch /var/lock/subsys/captive


start() {
	# In fact this part is done during the boot anyway.
	grep -q '\<captive-.*\<auto\>' /etc/fstab || return

	fses="$(echo /sbin/mount.captive-*|sed 's#/sbin/mount[.]##g'|tr ' ' ,)"
	if [ -z "$fses" ]; then
		return
	fi
	action $"Mounting captive filesystems: " mount -a -t "$fses"
	RETVAL=$?
	echo
	return $RETVAL
}

stop() {
	# I did not find any way how to identify (or even mark) "captive-*"
	# filesystems between the mounted ones.
	# Devicename really must be set to the real devicename as otherwise
	# mount(8) would try to mount "captive-*" twice during boot.
	action $"Unmounting captive (FUSE) filesystems: " umount -a -t fuse
	RETVAL=$?
	return $RETVAL
}

restart() {
	stop
	start
}	

case "$1" in
  start)
  	start
	;;
  stop)
  	stop
	;;
  restart)
  	restart
	;;
  *)
	echo $"Usage: $0 {start|stop|restart}"
	exit 1
esac
