14.11.2025 22:29, Stuart Henderson пишет:
> On 2025/11/14 14:10, Klemens Nanni wrote:
>>>  daemon_flags="-c /var/unbound/etc/unbound.conf"
>>
>> This is the default and can/should go, making our script even shorter.
> 
> yes I think that does make sense.
> 
>>>  . /etc/rc.d/rc.subr
>>>  
>>>  rc_pre() {
>>> +   local _config=$(while getopts :c: _opt $daemon_flags; do case $_opt { 
>>> (c) echo $OPTARG; } done)
>>> -   local _anchor=$(/usr/sbin/unbound-checkconf -o auto-trust-anchor-file)
>>> +   local _anchor=$(/usr/sbin/unbound-checkconf -o auto-trust-anchor-file 
>>> $_config)
>>
>> getopts with a leading : reads much nicer than spamlogd's sed(1) golf,
>> but it still looks like... too much. 
> 
> i much prefer the expanded version rather than this one-liner which
> relies on "For historical reasons, open and close braces may be used
> instead of in and esac"
> 
> maybe convert spamlogd to use this instead of the sed too?

If you think supporting multiple unbounds is sensible, then sure,
we should unify scripts as much as possible.

Looks like this with local and our usual ksh style;  yet untested,
I only run a single default unbound.


Index: spamlogd
===================================================================
RCS file: /cvs/src/etc/rc.d/spamlogd,v
diff -u -p -r1.6 spamlogd
--- spamlogd    21 Apr 2022 09:31:28 -0000      1.6
+++ spamlogd    14 Nov 2025 15:48:39 -0000
@@ -9,8 +9,11 @@ daemon="/usr/libexec/spamlogd"
 rc_reload=NO
 
 rc_pre() {
-       pflog=$(echo $daemon_flags | sed -En 's/.*-l *(pflog[0-9]+).*/\1/p')
-       pflog=${pflog:-pflog0}
+       local _opt pflog=pflog0
+
+       while getopts :l: _opt $daemon_flags; do
+               [[ $_opt == l ]] && pflog=$OPTARG
+       done
 
        if pfctl -si | grep -q Enabled; then
                ifconfig $pflog create
Index: unbound
===================================================================
RCS file: /cvs/src/etc/rc.d/unbound,v
diff -u -p -r1.9 unbound
--- unbound     9 Oct 2024 15:42:56 -0000       1.9
+++ unbound     14 Nov 2025 15:47:25 -0000
@@ -3,18 +3,23 @@
 # $OpenBSD: unbound,v 1.9 2024/10/09 15:42:56 kn Exp $
 
 daemon="/usr/sbin/unbound"
-daemon_flags="-c /var/unbound/etc/unbound.conf"
 
 . /etc/rc.d/rc.subr
 
 rc_pre() {
-       local _anchor=$(/usr/sbin/unbound-checkconf -o auto-trust-anchor-file)
+       local _anchor _config _opt
+
+       while getopts :c: _opt $daemon_flags; do
+               [[ $opt == c ]] && _config=$OPTARG
+       done
+
+       _anchor=$($daemon-checkconf -o auto-trust-anchor-file $_config)
 
        if [[ -n $_anchor && ! -f $_anchor ]]; then
-               /usr/sbin/unbound-anchor -v
+               $daemon-anchor -v $_config
        fi
 
-       /usr/sbin/unbound-checkconf
+       $daemon-checkconf $_config
 }
 
 rc_cmd $1

Reply via email to