summaryrefslogtreecommitdiff
path: root/devel/p4d/files/p4d.sh
blob: 7df60e5ce2acf42858290ac1cd66f8a7e0088170 (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/bin/sh
#
# $NetBSD: p4d.sh,v 1.1.1.1 2002/09/01 02:26:09 schmonz Exp $
#
# Perforce SCM server
#
# PROVIDE: p4d
# REQUIRE: DAEMON

[ -f /etc/rc.subr ] && . /etc/rc.subr

name="p4d"
rcvar=${name}
command="@PREFIX@/sbin/p4d"
start_cmd="p4d_start"
license_cmd="p4d_license"
extra_commands="license"

p4d_start()
{
	p4d_run ${p4d_flags} -d -q
}

p4d_license()
{
	p4d_run -V
}

p4d_run()
{
	eval "@SU@ -m @P4USER@ -c 'umask 037; @SETENV@ - `p4d_getenv` ${command} $@'"
}

p4d_getenv()
{
	p4d_getenv_debug
	p4d_getenv_journalfile
	p4d_getenv_logfile
	p4d_getenv_port
	p4d_getenv_rootdir
	p4d_getenv_tmp
}

p4d_getenv_debug()
{
	# Possibly specify debug output
	# p4d default: none
	if [ ! -z ${P4DEBUG} ]; then
		@ECHO@ -n " P4DEBUG=${P4DEBUG}"
	fi
}

p4d_getenv_journalfile()
{
	# Possibly specify the journal file
	# p4d default: "journal" if it exists, else none
	if [ ! -z ${P4JOURNAL} ]; then
		@ECHO@ -n " P4JOURNAL=${P4JOURNAL}"
	fi
}

p4d_getenv_logfile()
{
	# Always specify the log file
	# p4d default: stderr
	if [ -z ${P4LOG} ]; then
		P4LOG=@P4LOG@
	fi
	@ECHO@ -n " P4LOG=${P4LOG}"
}

p4d_getenv_port()
{
	# Possibly specify the port number
	# p4d default: 1666
	if [ ! -z ${P4PORT} ]; then
		@ECHO@ -n " P4PORT=${P4PORT}"
	fi
}

p4d_getenv_rootdir()
{
	# Always specify the root dir
	# p4d default: working directory
	if [ -z ${P4ROOT} ]; then
		P4ROOT=@P4ROOT@
	fi
	@ECHO@ -n " P4ROOT=${P4ROOT}"
}

p4d_getenv_tmp()
{
	# Possibly specify temp dir
	# p4d default: /tmp
	if [ ! -z ${TEMP} ]; then
		@ECHO@ -n " TMP=${TEMP}"
	elif [ ! -z ${TMP} ]; then
		@ECHO@ -n " TMP=${TMP}"
	fi
}

if [ -f /etc/rc.subr ]; then
	load_rc_config $name
	run_rc_command "$1"
else
	echo -n " ${name}"
	${start_cmd}
fi