Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion type/__start_on_boot/explorer/state
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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
Expand All @@ -109,4 +167,4 @@ else
esac
fi

echo "${state}"
printf '%s%s\n' "${state}" "${extra:+ ${extra}}"
11 changes: 8 additions & 3 deletions type/__start_on_boot/gencode-remote
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -62,8 +62,8 @@ in
;;


(freebsd)
: # handled in manifest
(freebsd|netbsd)
# handled in manifest
;;

(openbsd)
Expand Down Expand Up @@ -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}'"
Expand Down
24 changes: 21 additions & 3 deletions type/__start_on_boot/manifest
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand All @@ -19,10 +20,11 @@
# along with skonfig-base. If not, see <http://www.gnu.org/licenses/>.
#

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

Expand All @@ -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