aboutsummaryrefslogtreecommitdiffstats
path: root/net-p2p/mldonkey/files/mlnet.in
blob: 8405a66675cd1521d0f80726f673f16bbc72fc49 (plain) (blame)
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
#!/bin/sh
#
# $FreeBSD$
#
# Under a BSDL license. Copyright 2005. Mario S F Ferreira <lioux@FreeBSD.org>

# PROVIDE: mlnet
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable mlnet:
#
#mlnet_enable="YES"
#mlnet_user=""
#mlnet_flags=""
#mlnet_logfile=""
#

. %%RC_SUBR%%

name="mlnet"
rcvar=`set_rcvar`
command="%%PREFIX%%/bin/${name}"
procname="%%PREFIX%%/bin/${name}-real"

load_rc_config "${name}"
: ${mlnet_enable="NO"}
: ${mlnet_user="$(whoami)"}
: ${mlnet_flags=""}
: ${mlnet_logfile=""}

pidfile="$(eval echo ~${mlnet_user}/.mldonkey/$(basename ${procname}).pid)"
required_dirs="$(eval echo ~${mlnet_user})"

mlnet_check_vars()
{
  if [ "x${mlnet_user}" = "xroot" ]; then
    warn "You have to set mlnet_user to a non-root user for security reasons"
    return 1
  fi

  return 0
}

start_precmd="mlnet_check_vars"
start_cmd="start_cmd"
start_cmd()
{
  if [ -n "${mlnet_logfile}" ]; then
    mlnet_logcommand="-log_file ${mlnet_logfile}"
  else
    mlnet_logfile="/dev/null"
  fi

  if [ "x${mlnet_user}" = "x$(whoami)" ]; then
    eval "${command} \
    ${mlnet_logcommand} \
    ${mlnet_flags} \
    >> ${mlnet_logfile} 2>&1 &"
  else
    su -l ${mlnet_user} -c "${command} \
    ${mlnet_logcommand} \
    ${mlnet_flags} \
    >> ${mlnet_logfile} 2>&1 &"
  fi
}

stop_precmd="mlnet_check_vars"

run_rc_command "$1"