#!/bin/sh

# Wrapper script for webfsd to parse configuration file
# Based on webfs.init from Debian package 1.21+ds1-12+b2

DAEMON="/usr/bin/webfsd"
CONFFILE="/etc/webfsd.conf"

test -f $DAEMON	|| exit 0
test -f $CONFFILE || exit 0

# read + verify config
. $CONFFILE
test "$web_root" = ""		&& exit 0

# build command line
ARGS="-F -r $web_root"
test "$web_host"	!= ""	&& ARGS="$ARGS -n $web_host"
test "$web_ip"		!= ""	&& ARGS="$ARGS -i $web_ip"
test "$web_port"	!= ""	&& ARGS="$ARGS -p $web_port"
test "$web_timeout"	!= ""	&& ARGS="$ARGS -t $web_timeout"
test "$web_conn"	!= ""	&& ARGS="$ARGS -c $web_conn"
test "$web_dircache"	!= ""	&& ARGS="$ARGS -a $web_dircache"
test "$web_index"	!= ""	&& ARGS="$ARGS -f $web_index"
if test "$web_accesslog" != ""; then
	if test "$web_logbuffering" = "true"; then
		ARGS="$ARGS -l $web_accesslog"
	else
		ARGS="$ARGS -L $web_accesslog"
	fi
fi
test "$web_syslog" = "true"	&& ARGS="$ARGS -s"
test "$web_virtual" = "true"	&& ARGS="$ARGS -v"
test "$web_user"	!= ""	&& ARGS="$ARGS -u $web_user"
test "$web_group"	!= ""	&& ARGS="$ARGS -g $web_group"
test "$web_cgipath"	!= ""	&& ARGS="$ARGS -x $web_cgipath"
test "$web_extras"	!= ""	&& ARGS="$ARGS $web_extras"

exec $DAEMON $ARGS

