#!/bin/sh

# PROVIDE: cpupowerd
# REQUIRE: DAEMON
# BEFORE:  LOGIN
# KEYWORD: nojail
#
# Add the following line to /etc/rc.conf[.local] to enable cpupowerd
#
# cpupowerd_enable (bool):      Set to "NO" by default.
#                               Set it to "YES" to enable cpupowerd.
# cpupowerd_config (str):       Custom config file for cpupowerd.
#                               (default /usr/local/etc/cpupowerd.conf)
# cpupowerd_flags (str):        Custom additional arguments to be passed
#                               to cpupowerd (default -d -c cpupowerd.conf).
#

. /etc/rc.subr

name="cpupowerd"
rcvar=cpupowerd_enable
command=/usr/local/sbin/${name}
start_precmd="${name}_precmd"

load_rc_config $name

# set default
: ${cpupowerd_enable="NO"}
: ${cpupowerd_config="/usr/local/etc/cpupowerd.conf"}

command_args="-d -c ${cpupowerd_config} ${cpupowerd_flags}"

cpupowerd_precmd()
{
	if [ ! -c "/dev/cpuctl0" ]; then
		kldload cpuctl
	fi
}

run_rc_command "$1"
