#!/bin/sh
#
# $FreeBSD: ports/sysutils/fusefs-kmod/files/fusefs.in,v 1.5 2007/12/17 17:22:09 alepulver Exp $
#
# PROVIDE: fusefs
# REQUIRE: sysctl
# BEFORE: mountlate
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf.local or /etc/rc.conf
# to enable this service:
#
# fusefs_enable (bool):		Set to NO by default.
#				Set it to YES to enable fusefs.
#

. %%RC_SUBR%%

kmod="%%PREFIX%%/modules/fuse.ko"
name="fusefs"
rcvar=${name}_enable

start_cmd="fusefs_start"
stop_cmd="fusefs_stop"

fusefs_start()
{
	if kldstat | grep -q fuse\\.ko; then
		echo "${name} is already running."
		return 0
	fi
	echo "Starting ${name}."
	kldload $kmod
}

fusefs_stop()
{
	if ! kldstat | grep -q fuse\\.ko; then
		echo "${name} is not running."
		return 1
	fi
	echo "Stopping ${name}."
# Unmount FUSE filesystems in reverse order (in case they are nested) with
# a delay of one second after, to allow 'umount' finish.
	mount | sed -e '1!G;h;$!d' | while read dev d1 mountpoint d2; do
		case "$dev" in
		/dev/fuse[0-9]*)
			echo "fusefs: unmounting ${mountpoint}."
			umount $mountpoint ; sleep 1
			;;
		esac
	done
	kldunload $kmod
}
load_rc_config $name

: ${fusefs_enable="NO"}

run_rc_command "$1"


syntax highlighted by Code2HTML, v. 0.9.1