#!/bin/sh
#
# Author: Mark Felder <feld@FreeBSD.org>

# PROVIDE: jackett
# REQUIRE: LOGIN
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable jacket:
# jackett_enable="YES"
# Optionaly there is some other parameters
# jackett_user="jackett"
# jackett_group="jackett"
# jackett_data_dir="%%PREFIX%%/jackett"
# 

. /etc/rc.subr

name="jackett"
rcvar=jackett_enable

load_rc_config $name

: ${jackett_enable="NO"}
: ${jackett_user:="jackett"}
: ${jackett_group:="jackett"}
: ${jackett_data_dir:="%%PREFIX%%/jackett"}

pidfile="${jackett_data_dir}/jackett.pid"
procname="%%PREFIX%%/bin/mono"
command="/usr/sbin/daemon"
command_args="-f -p ${pidfile} ${procname} %%DATADIR%%/JackettConsole.exe -d ${jackett_data_dir}"
start_precmd=jackett_precmd

jackett_precmd()
{
	export XDG_CONFIG_HOME=${jackett_data_dir}

	# avoid root user warning
	export USER=${jackett_user}

	if [ ! -d ${jackett_data_dir} ]; then
		install -d -o ${jackett_user} ${jackett_data_dir}
	fi
}

run_rc_command "$1"
