aboutsummaryrefslogtreecommitdiffstats
path: root/www/amphetadesk/files/amphetadesk.in
blob: 8b4bb6ed2a4bb52b5009dec2a489493d8cca3dfc (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
#!/bin/sh
#
# $FreeBSD$
#
# Under a BSDL license. Copyright 2005. Mario S F Ferreira <lioux@FreeBSD.org>

# PROVIDE: amphetadesk
# REQUIRE: LOGIN
# KEYWORD: shutdown

#
# Add the following lines to /etc/rc.conf to enable amphetadesk:
#
#amphetadesk_enable="YES"
#amphetadesk_user=""
#amphetadesk_pidfile=""
#

. %%RC_SUBR%%

name="amphetadesk"
rcvar=`set_rcvar`
command="%%PREFIX%%/bin/AmphetaDesk"
procname="%%PERL%%"

load_rc_config "${name}"
: ${amphetadesk_enable="NO"}
: ${amphetadesk_user=""}

if [ -n "${amphetadesk_user}" ]; then
  eval realpath ~${amphetadesk_user} >/dev/null 2>&1 &&
    amphetadesk_homedir="$(eval realpath ~${amphetadesk_user})"
fi

if [ -n "${amphetadesk_user}" -a -z "${amphetadesk_pidfile}" -a -n "${amphetadesk_homedir}" ]; then
  amphetadesk_pidfile="${amphetadesk_homedir}/.${name}/AmphetaDesk.pid"
fi

pidfile="${amphetadesk_pidfile:-${HOME}/.${name}/AmphetaDesk.pid}"

start_cmd="start_cmd"

start_precmd="amphetadesk_check_vars"
stop_precmd="amphetadesk_check_vars"
status_precmd="amphetadesk_check_vars"

amphetadesk_check_vars()
{
  if [ -z "${amphetadesk_user}" ]; then
    amphetadesk_user=$(whoami)
  fi

  if [ "x${amphetadesk_user}" = "xroot" ]; then
    err 1 "You have to set amphetadesk_user to a non-root user for security reasons"
  fi
}

start_cmd()
{
  su -l ${amphetadesk_user} \
    -c "env PIDFILE=${pidfile} ${command} &"
}

run_rc_command "$1"