#!/bin/sh
#
# $FreeBSD: ports/net/boinc-client/files/boinc.sh.in,v 1.2 2005/06/10 18:00:54 pav Exp $

# PROVIDE: boinc
# REQUIRE: LOGIN
# KEYWORD: FreeBSD shutdown

. /etc/rc.subr

name="boinc"
rcvar=`set_rcvar`

boinc_user=boinc
boinc_home=/var/db/boinc
program_file=boinc-client
program_path=/usr/local/lib/boinc/${program_file}
syslog_facility=daemon.err

load_rc_config $name
: ${boinc_enable="NO"}

start_cmd=boinc_start
stop_cmd=boinc_stop

boinc_start() {
	if checkyesno boinc_enable
	then
		if [ ! -x ${program_path} ]
		then
			logger -sp ${syslog_facility} -t ${program_file} \
				"unable to start: ${program_path} is missing."
			exit 72
		fi
		if ps axo ucomm | egrep ${program_file}; then
			logger -sp ${syslog_facility} -t ${program_file} \
			"unable to start: ${program_file} is already running."
			exit 72
		fi
		echo "Starting BOINC client."
		export LD_LIBRARY_PATH=/usr/local/lib/boinc
		idprio 31 su - ${boinc_user} -c "${program_path} ${boinc_flags} >/dev/null &"
	fi
}

boinc_stop() {
	killall ${program_file} 2> /dev/null
}

run_rc_command "$1"
