#!/bin/sh

# $FreeBSD$
#
# PROVIDE: lidarr
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# Add the following lines to /etc/rc.conf to enable lidarr:
# lidarr_enable="YES"

. /etc/rc.subr
name=lidarr
rcvar=${name}_enable
load_rc_config $name

: ${lidarr_enable="NO"}
: ${lidarr_user:="lidarr"}
: ${lidarr_group:="lidarr"}
: ${lidarr_data_dir:="/config"}

pidfile="${lidarr_data_dir}/lidarr.pid"
command="/usr/sbin/daemon"
procname="/usr/local/bin/mono"
command_args="-f ${procname} /usr/local/share/Lidarr/Lidarr.exe -- data=${lidarr_data_dir} --nobrowser"

start_precmd=lidarr_precmd
lidarr_precmd() {
if [ ! -d ${lidarr_data_dir} ]; then
install -d -o ${lidarr_user} -g ${lidarr_group} ${lidarr_data_dir}
fi

export XDG_CONFIG_HOME=${lidarr_data_dir}
}

run_rc_command "$1"