#!/bin/sh
# $FreeBSD: multimedia/webcamd/files/webcamd.in 300896 2012-07-14 13:54:48Z beat $
#
# PROVIDE: webcamd
# REQUIRE: DAEMON
#
# Add the following line to /etc/rc.conf[.local] to enable webcamd:
#
# webcamd_enable="YES"
#

webcamd_enable=${webcamd_enable-"NO"}
hald_enable=${hald_enable-"NO"}

. /etc/rc.subr

name=webcamd
rcvar=webcamd_enable
iface=${3-0}
command=/usr/local/sbin/webcamd
command_args="-B -U webcamd -G webcamd"

start_precmd="${name}_prestart"

webcamd_prestart()
{
  if checkyesno hald_enable ; then
	command_args="$command_args -H"
  fi
}

pidfile="/var/run/webcamd.*.$iface.pid"

load_rc_config $name

if [ "$2" = "vflip" ] || [ "$3" = "vflip" ]; then
	command_args="$command_args -m v4l2.vflip=1"
fi

if [ "$2" = "hflip" ] || [ "$3" = "hflip" ]; then
	command_args="$command_args -m v4l2.hflip=1"
fi

if [ $# -gt 1 ]; then
	pidfile="webcamd.dummy"
	command_args="$command_args -d $2 -i $iface"
	# Only run the rc command if the appropriate arguments are specified:	
	run_rc_command $1
fi
