#!/bin/sh /etc/rc.common

TPWS_DEFAULT=/usr/bin/tpws
TPWS_USER_DEFAULT=daemon

START=99
STOP=01
USE_PROCD=1

tpws_instance()
{
	config_get "$@"

	local enabled port opt

	config_get_bool enabled "$1" enabled 0
	[ "$enabled" -eq 1 ] || return 1

	config_get port "$1" port
	config_get opt "$1" opt

	local COMMAND="$TPWS --user=$TPWS_USER --port=$port $opt"
	procd_open_instance
	procd_set_param command $COMMAND
	procd_close_instance
}

start_service()
{
	config_load tpws
	config_get TPWS_USER defaults user $TPWS_USER_DEFAULT
	config_get TPWS defaults tpws $TPWS_DEFAULT
	config_foreach tpws_instance tpws
}
