From ed80ddfd4cca5dddb5c9b5483b2c791afd0ea286 Mon Sep 17 00:00:00 2001 From: Dennis Camera Date: Sun, 31 Aug 2025 12:25:49 +0200 Subject: [PATCH] [type/__start_on_boot] Add support for NetBSD --- type/__start_on_boot/explorer/state | 60 ++++++++++++++++++++++++++++- type/__start_on_boot/gencode-remote | 11 ++++-- type/__start_on_boot/manifest | 24 ++++++++++-- 3 files changed, 88 insertions(+), 7 deletions(-) diff --git a/type/__start_on_boot/explorer/state b/type/__start_on_boot/explorer/state index 5e589b7a7..e13ef1a0b 100755 --- a/type/__start_on_boot/explorer/state +++ b/type/__start_on_boot/explorer/state @@ -2,6 +2,7 @@ # # 2012-2019 Nico Schottelius (nico-cdist at schottelius.org) # 2013 Daniel Heule (hda at sfs.biz) +# 2025 Dennis Camera (dennis.camera at riiengineering.ch) # # This file is part of skonfig-base. # @@ -96,6 +97,63 @@ else state='absent' service -e | grep "/${name}$" && state='present' ;; + (netbsd) + NL=$(printf '\n.'); NL=${NL%?} + + if test -x /usr/sbin/service + then + # NetBSD >= 7.0 + rcvar=$(/usr/sbin/service "${name}" rcvar) + else + # NetBSD < 7.0 + rc_script=$( + # shellcheck source=/dev/null + . /etc/rc.conf + for _d in ${rc_directories:-/etc/rc.d} + do + if test -f "${_d}/${name}" && test -x "${_d}/${name}" + then + printf '%s/%s\n' "${_d}" "${name}" + + fi + done) + test -x "${rc_script}" || { + printf 'service %s could not be found' "${name}" >&2 + exit 1 + } + + rcvar=$("${rc_script}" rcvar) + fi + + # remove service name comment + rcvar=${rcvar#'#'*"${NL}"} + # only first variable (at the time of writing there can’t be more + # than one anyway) + rcvar=${rcvar%%"${NL}"*} + # some (older) versions of NetBSD prefix the rcvar with $ + rcvar=${rcvar#\$} + + case ${rcvar} + in + (*=*) + # OK + extra=${rcvar%%=*} + + case ${rcvar#*=} + in + ([Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1) + state='present' ;; + (*) + state='absent' ;; + esac + ;; + ('') + # this service is not enableable + printf 'The service %s is not enableable\n' "${name}" >&2 + exit 1 + ;; + esac + ;; (openbsd) state='absent' # OpenBSD 5.7 and higher @@ -109,4 +167,4 @@ else esac fi -echo "${state}" +printf '%s%s\n' "${state}" "${extra:+ ${extra}}" diff --git a/type/__start_on_boot/gencode-remote b/type/__start_on_boot/gencode-remote index 75b056be2..a0aaade98 100755 --- a/type/__start_on_boot/gencode-remote +++ b/type/__start_on_boot/gencode-remote @@ -21,7 +21,7 @@ # state_should=$(cat "${__object:?}/parameter/state") -state_is=$(cat "${__object:?}/explorer/state") +read -r state_is _ <"${__object:?}/explorer/state" || : init=$(cat "${__global:?}/explorer/init") target_runlevel=$(cat "${__object:?}/parameter/target_runlevel") @@ -62,8 +62,8 @@ in ;; - (freebsd) - : # handled in manifest + (freebsd|netbsd) + # handled in manifest ;; (openbsd) @@ -104,6 +104,11 @@ in echo "'/etc/init.d/${name}' disable" ;; + + (freebsd|netbsd) + # handled in manifest + ;; + (openbsd) # OpenBSD 5.7 and higher echo "rcctl disable '${name}'" diff --git a/type/__start_on_boot/manifest b/type/__start_on_boot/manifest index ef5de454e..2a4577afa 100755 --- a/type/__start_on_boot/manifest +++ b/type/__start_on_boot/manifest @@ -2,6 +2,7 @@ # # 2018 Kamila Součková (kamila at ksp.sk) # 2018 Jonas Weber (github at jonasw.de) +# 2025 Dennis Camera (dennis.camera at riiengineering.ch) # # This file is part of skonfig-base. # @@ -19,10 +20,11 @@ # along with skonfig-base. If not, see . # -state_should=$(cat "${__object:?}/parameter/state") -state_is=$(cat "${__object:?}/explorer/state") name=${__object_id:?} +state_should=$(cat "${__object:?}/parameter/state") +read -r state_is extra <"${__object:?}/explorer/state" || : + # Short circuit if nothing is to be done [ "${state_should}" = "${state_is}" ] && exit 0 @@ -43,7 +45,23 @@ in --value "\"${value}\"" \ --delimiter '=' ;; + (netbsd) + rcvar=${extra} + : "${rcvar:?rcvar detection failed}" + __key_value "/etc/rc.conf:${rcvar}" \ + --file /etc/rc.conf \ + --delimiter '=' --exact_delimiter \ + --key "${rcvar}" \ + --value "$( + case ${state_should} + in + (present) + echo YES ;; + (absent) + echo NO ;; + esac)" + ;; (*) - : # handled in gencode-remote + # handled in gencode-remote ;; esac