summaryrefslogtreecommitdiff
path: root/misc/setiathome/files/setiathome.sh
blob: 937a973fe5ee0bc230503fb55d1314630f17c591 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/sh
#
# $NetBSD: setiathome.sh,v 1.1 2003/04/09 15:52:29 jmmv Exp $
#

# PROVIDE: setiathome
# REQUIRE: LOGIN
# KEYWORD: shutdown

. /etc/rc.subr

sah_user="nobody"
sah_group="nobody"
sah_homedir="/var/db/setiathome"

name="setiathome"
rcvar=$name
command="/usr/pkg/bin/${name}"
pidfile="${sah_homedir}/pid.sah"
extra_commands="config"

setiathome_config() {
	if [ ! -d ${sah_homedir} ]; then
		mkdir ${sah_homedir}
		chmod 755 ${sah_homedir}
		chown ${sah_user}:${sah_group} ${sah_homedir}
	fi

	su -fm ${sah_user} -c "cd ${sah_homedir} && exec ${command} -login"
	return 0
}

setiathome_start() {
	if [ ! -f ${sah_homedir}/key.sah ]; then
		run_rc_command config
	fi

	echo "Starting ${name}."
	su -fm ${sah_user} -c "cd ${sah_homedir} && exec ${command} \
		${command_args} &" 2>/dev/null 1>/dev/null
}

setiathome_poststop() {
	rm -f ${sah_homedir}/pid.sah
}

config_cmd=setiathome_config
start_cmd=setiathome_start
stop_postcmd=setiathome_poststop

load_rc_config $name
run_rc_command "$1"