diff --git a/dns/blocky/Makefile b/dns/blocky/Makefile index d17daad65956..5035aaffca74 100644 --- a/dns/blocky/Makefile +++ b/dns/blocky/Makefile @@ -1,32 +1,32 @@ PORTNAME= blocky DISTVERSIONPREFIX= v DISTVERSION= 0.20 -PORTREVISION= 2 +PORTREVISION= 3 CATEGORIES= dns MASTER_SITES= https://raw.githubusercontent.com/${GH_ACCOUNT}/${GH_PROJECT}/${DISTVERSIONFULL}/:gomod DISTFILES= go.mod:gomod MAINTAINER= eduardo@FreeBSD.org COMMENT= Fast and lightweight DNS proxy as ad-blocker WWW= https://0xerr0r.github.io/blocky/ LICENSE= APACHE20 LICENSE_FILE= ${WRKSRC}/LICENSE USES= go:modules USE_GITHUB= yes GH_ACCOUNT= 0xERR0R USE_RC_SUBR= blocky GO_MODULE= github.com/${GH_ACCOUNT}/${GH_PROJECT} GO_TARGET= main.go:${PREFIX}/sbin/${PORTNAME} GO_BUILDFLAGS= -ldflags "-w -s \ -X github.com/0xERR0R/blocky/util.Version=${DISTVERSION} \ -X github.com/0xERR0R/blocky/util.BuildTime=`date '+%Y%m%d-%H%M%S'`" SUB_FILES= pkg-message post-install: ${INSTALL_DATA} ${FILESDIR}/blocky-config.yml.sample ${STAGEDIR}${PREFIX}/etc/blocky-config.yml.sample .include diff --git a/dns/blocky/files/blocky.in b/dns/blocky/files/blocky.in index 24a92028836a..2b625f8be55d 100644 --- a/dns/blocky/files/blocky.in +++ b/dns/blocky/files/blocky.in @@ -1,36 +1,54 @@ #!/bin/sh # PROVIDE: blocky # REQUIRE: DAEMON NETWORKING # KEYWORD: shutdown # # Add the following to /etc/rc.conf[.local] to enable this service # # blocky_enable (bool): Set to NO by default. -# Set it to YES to enable blocky. -# blocky_config (str): Set to /usr/local/etc/blocky/config.yml by default. -# +# Set it to YES to enable blocky. +# blocky_config (str): Set to /usr/local/etc/blocky-config.yml by default. +# Set it to a path to use that config file. +# blocky_user (str): Services run as root by default. Set to a user name +# to run blocky as that user. Note: non-root users +# might need permission to bind to ports. +# blocky_group (str): Set to the user's primary group by default. +# Set it to a group name for daemon file ownership. +# blocky_flags (str): Enter extra flags to append to the blocky command. . /etc/rc.subr name=blocky rcvar=blocky_enable load_rc_config ${name} : ${blocky_enable:=NO} : ${blocky_config:="%%PREFIX%%/etc/blocky-config.yml"} +: ${blocky_group:=} : ${blocky_flags:=} -pidfile=/var/run/blocky.pid -command="%%PREFIX%%/sbin/blocky" +if [ -n "${blocky_user}" ] && [ -z "${blocky_group}" ]; then + # Detect the daemon user's primary group + blocky_group=$(id -gn "${blocky_user}") +fi + +pidfile="/var/run/${name}.pid" +blocky_path="%%PREFIX%%/sbin/blocky" + +command="/usr/sbin/daemon" +procname="/usr/local/sbin/blocky" +command_args="-c -f -p ${pidfile} ${blocky_path} \ + -c ${blocky_config} ${blocky_flags}" -start_cmd="${name}_start" +start_precmd="blocky_precmd" -blocky_start() +# Sets up a pidfile the daemon user can access +blocky_precmd() { - echo -n "Starting ${name}." - /usr/sbin/daemon -p ${pidfile} -f ${command} -c ${blocky_config} ${blocky_flags} + install -o "${blocky_user:-root}" -g "${blocky_group:-wheel}" \ + -m 0600 /dev/null "${pidfile}" } run_rc_command "$1" diff --git a/dns/blocky/files/pkg-message.in b/dns/blocky/files/pkg-message.in index 953a51c3cce8..70f077c66f2a 100644 --- a/dns/blocky/files/pkg-message.in +++ b/dns/blocky/files/pkg-message.in @@ -1,14 +1,29 @@ [ { type: install message: < is the UID of your user): + + net.inet.ip.portrange.reservedhigh=0 + security.mac.portacl.rules=uid::tcp:53,uid::udp:53 + Please refer to the documentation located at https://0xerr0r.github.io/blocky/ for further information. EOM } ]