#!/bin/sh

# PROVIDE: immich_deduper
# REQUIRE: LOGIN
# KEYWORD: shutdown
#
# immich_deduper_enable (bool):	Set to NO by default.
# immich_deduper_user (str):	User to run as, default immich.
# immich_deduper_group (str):	Group to run as, default immich.

. /etc/rc.subr

name=immich_deduper
rcvar=immich_deduper_enable
desc="Immich duplicate photo finder"

load_rc_config $name

: ${immich_deduper_enable:="NO"}
: ${immich_deduper_user:="immich"}
: ${immich_deduper_group:="immich"}

pidfile=/var/run/${name}/${name}.pid
childpidfile=/var/run/${name}/${name}_child.pid
logfile=/var/log/${name}.log
start_precmd=immich_deduper_precmd
command=/usr/sbin/daemon
command_args="-f -H -t ${name} -P ${pidfile} -p ${childpidfile} \
	-o ${logfile} /usr/local/bin/immich-deduper"

immich_deduper_precmd()
{
	# Keep what the service creates itself out of other users' reach
	umask 027

	install -d -m 750 -o ${immich_deduper_user} \
		-g ${immich_deduper_group} /var/run/${name}
	[ -f ${logfile} ] || install -m 640 -o ${immich_deduper_user} \
		-g ${immich_deduper_group} /dev/null ${logfile}
}

run_rc_command "$1"
