aboutsummaryrefslogtreecommitdiff
path: root/www/privoxy/files/privoxy.in
blob: 9518a784fc6aeba1bb6435f23c4864164733da71 (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
#!/bin/sh
#
# $FreeBSD$
#
#
# PROVIDE: privoxy
# REQUIRE: DAEMON
# BEFORE: LOGIN
#
# This rc script understands the following variables
# which are read from /etc/rc.conf:
#
# privoxy_enable  (bool): Set to "NO" by default.
#                         Set it to "YES" to enable Privoxy.
# privoxy_config   (str): Privoxy's configuration file. Default is:
#                         %%PREFIX%%/etc/privoxy/config.
# privoxy_flags    (str): List of additional Privoxy options you want
#                         to use. None set by default.
# privoxy_pidfile  (str): Default is /var/run/privoxy/privoxy.pid.
# privoxy_user     (str): Privoxy Daemon user. Default is privoxy.
#
# Usage:
# %%PREFIX%%/etc/rc.d/privoxy [fast|force|one](start|stop|restart|rcvar|status|poll)

. /etc/rc.subr

name="privoxy"
rcvar=privoxy_enable
load_rc_config ${name}

: ${privoxy_enable="NO"}
: ${privoxy_config="%%PREFIX%%/etc/privoxy/config"}
: ${privoxy_logdir="/var/log/privoxy"}
: ${privoxy_user="privoxy"}
: ${privoxy_piddir="/var/run/privoxy"}
: ${privoxy_pidfile="${privoxy_piddir}/privoxy.pid"}

privoxy_prestart () {
    if [ ! -e "${privoxy_config}" ]; then
        echo "config file not found. Copying the example file to ${privoxy_config}."
        cp %%PREFIX%%/share/examples/privoxy/config "${privoxy_config}"
        chown "${privoxy_user}:${privoxy_user}" "${privoxy_config}";
    fi
    actionfile="%%PREFIX%%/etc/privoxy/match-all.action"
    if [ ! -e "${actionfile}" ]; then
        echo "${actionfile} not found. Copying the example file."
        cp %%PREFIX%%/share/examples/privoxy/match-all.action "${actionfile}"
        chown "${privoxy_user}:${privoxy_user}" "${actionfile}"
    fi
    if [ ! -e "${privoxy_logdir}" ]; then
        echo "${privoxy_logdir} not found. Creating ..."
        mkdir "${privoxy_logdir}"
        chown "${privoxy_user}:${privoxy_user}" "${privoxy_logdir}"
        chmod 0750 "${privoxy_logdir}"
    fi
    if [ ! -d "${privoxy_piddir}" ]; then
        mkdir -p "${privoxy_piddir}"
        chown "${privoxy_user}:${privoxy_user}" "${privoxy_piddir}"
    fi
}

start_precmd="privoxy_prestart"

command="%%PREFIX%%/sbin/privoxy"
command_args="${privoxy_flags} --pidfile ${privoxy_pidfile} ${privoxy_config}"

run_rc_command "$1"