#!/bin/sh
#
# $Id: $
#
# captive.init	Script to start/stop captive-related filesystems
#
# Author:       Alexey Morozov <morozov@altlinux.org>
#
# chkconfig: 2345 95 05
# description: mounts and unmounts captive filesystems

WITHOUT_RC_COMPAT=1

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

captive_start()
{
    action $"Checking if captive filesystems can be mounted:" modprobe lufs
    [ $? -ne 0 ] && return $?
    action $"Mounting captive filesystems:" mount -a -t captive-ntfs,captive-cdfs
    touch /var/lock/subsys/captive
}

captive_stop()
{
    action $"Unmounting captive filesystems:" umount -a -t captive-ntfs,captive-cdfs
    rm -f /var/lock/subsys/captive
}

captive_status()
{
# it's not needed for mtab cause it's autogenerated
#    if grep -v '^[[:space:]]*#' /etc/mtab | awk '{print $3}' | grep -q ^captive-; then
    if awk '{print $3}' /etc/mtab | grep -q ^captive-; then
	echo "Captive subsystem is on";
    else
	echo "Captive subsystem is off";
    fi
}
 
# See how we were called.
case "$1" in
  start)
	captive_start
	;;
  stop)
	captive_stop
	;;
  status)
	captive_status
	;;
  restart|reload)
	captive_stop
	captive_start
	;;
  condrestart)
	if test -f /var/lib/subsys/captive; then
	    captive_stop
	    captive_start
	fi
	;;
  condstop)
	test -f /var/lib/subsys/captive && captive_top
	;;
  *)
	msg_usage "${0##*/} {start|stop|restart|reload|status|condrestart|condstop}"
	exit 1
esac

exit 0
