aboutsummaryrefslogtreecommitdiff
path: root/net/wireproxy/files/wireproxy.in
blob: 019337445fd5b26d2cae2929c5d12b5d7d9030f2 (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

# PROVIDE: wireproxy
# REQUIRE: LOGIN NETWORKING
# KEYWORD: shutdown

# Add the following lines to /etc/rc.conf to enable wireproxy:
# wireproxy_enable (bool):	Set to "NO" by default.
#		Set it to "YES" to enable wireproxy.
# wireproxy_checkconfig (bool):	Set to "YES" by default.
#		Set it to "YES" to check configuration when starting.
# wireproxy_configfile (str):	Set to "%%PREFIX%%/etc/wireproxy.conf" by default.
#		Path to configuration file.
# wireproxy_logfile (str):	Set to "/var/log/wireproxy.log" by default.
#		Path to log file.
# wireproxy_user (str):		Set to "nobody" by default.
#		User to run wireproxy.
# wireproxy_flags (str):	Set to "" by default.
#		Extra flags passed to start command.

. /etc/rc.subr

name=wireproxy
rcvar=wireproxy_enable
desc="WireGuard client that exposes itself as a SOCKS5/HTTP proxy"

load_rc_config ${name}

: ${wireproxy_enable:=NO}
: ${wireproxy_checkconfig=YES}
: ${wireproxy_configfile="%%PREFIX%%/etc/wireproxy.conf"}
: ${wireproxy_logfile=/var/log/wireproxy.log}
: ${wireproxy_user=nobody}

procname="%%PREFIX%%/bin/wireproxy"
pidfile="/var/run/${name}.pid"
daemonpidfile="/var/run/daemon_${name}.pid"
required_files="${wireproxy_configfile}"
command=/usr/sbin/daemon
command_args="-f -H -o ${wireproxy_logfile} -p ${pidfile} -P ${daemonpidfile} ${procname} -c ${wireproxy_configfile}"

start_precmd="${name}_precmd"
stop_postcmd="rm -f ${pidfile} ${daemonpidfile}"
configtest_cmd="${name}_configtest"
extra_commands=configtest

wireproxy_precmd()
{
	/usr/bin/install -m 600 -o ${wireproxy_user} /dev/null ${pidfile}
	/usr/bin/install -m 600 -o ${wireproxy_user} /dev/null ${daemonpidfile}
	/usr/bin/install -m 640 -o ${wireproxy_user} /dev/null ${wireproxy_logfile}

	if checkyesno wireproxy_checkconfig; then
		wireproxy_configtest
	fi
}

wireproxy_configtest()
{
	echo "Performing sanity check on ${name} configuration:"
	${procname} --configtest --config ${wireproxy_configfile}
}

run_rc_command "$1"