#!/bin/sh
# kFreeBSD do not accept scripts as interpreters, using #!/bin/sh and sourcing.
if [ true != "$INIT_D_SCRIPT_SOURCED" ] ; then
    set "$0" "$@"; INIT_D_SCRIPT_SOURCED=true . /lib/init/init-d-script
fi
### BEGIN INIT INFO
# Provides:          opendnssec-enforcer
# Required-Start:    $remote_fs $syslog
# Required-Stop:     $remote_fs $syslog
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: OpenDNSSEC Enforcer
# Description:       Daemon to create and enforce DNSSEC KASP policy
### END INIT INFO

NAME=opendnssec-enforcer
DAEMON=/usr/sbin/ods-enforcerd
DESC="OpenDNSSEC Enforcer"
PIDFILE=/run/opendnssec/enforcerd.pid

# Read configuration variable file if it is present
[ -r /etc/default/opendnssec ] && . /etc/default/opendnssec

do_tmpfiles() {
    local type path mode user group

    TMPFILES=/usr/lib/tmpfiles.d/$1.conf

    if [ -r "$TMPFILES" ]; then
	while read type path mode user group; do
            if [ "$type" = "d" ]; then
                mkdir -p "$path"
		chmod "$mode" "$path"
                chown "$user:$group" "$path"
            fi
        done
    fi
}

do_start_prepare() {
    do_tmpfiles $(basename $0)
    DAEMON_ARGS="$DAEMON_ARGS $ODS_ENFORCERD_OPT"
}
