#!/bin/sh /etc/rc.common
# Copyright (C) 2011-2014 OpenWrt.org

START=00

USE_PROCD=1
PROG=/sbin/rngd

start_service() {
	local enabled=$(uci -q get system.@rngd[0].enabled)
	local precmd=$(uci -q get system.@rngd[0].precmd)
	local device=$(uci -q get system.@rngd[0].device)
	local watermark=$(uci -q get system.@rngd[0].fill_watermark)

	[ "$enabled" = "1" ] || return

	[ -z "$precmd" ] || ${precmd} ${device}

	[ -z "$device" ] || device="-r ${device}"
	[ -z "$watermark" ] || watermark="-W ${watermark}"

	procd_open_instance
	procd_set_param command "$PROG" -f ${device} ${watermark}
	procd_set_param stderr 1
	procd_close_instance
}
