Skip to content

Commit d21080f

Browse files
authored
Merge pull request #154 from riiengineering/feature/type/__start_on_boot/netbsd-support
__start_on_boot: Add support for NetBSD
2 parents b3194d4 + ed80ddf commit d21080f

3 files changed

Lines changed: 88 additions & 7 deletions

File tree

type/__start_on_boot/explorer/state

Lines changed: 59 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# 2012-2019 Nico Schottelius (nico-cdist at schottelius.org)
44
# 2013 Daniel Heule (hda at sfs.biz)
5+
# 2025 Dennis Camera (dennis.camera at riiengineering.ch)
56
#
67
# This file is part of skonfig-base.
78
#
@@ -96,6 +97,63 @@ else
9697
state='absent'
9798
service -e | grep "/${name}$" && state='present'
9899
;;
100+
(netbsd)
101+
NL=$(printf '\n.'); NL=${NL%?}
102+
103+
if test -x /usr/sbin/service
104+
then
105+
# NetBSD >= 7.0
106+
rcvar=$(/usr/sbin/service "${name}" rcvar)
107+
else
108+
# NetBSD < 7.0
109+
rc_script=$(
110+
# shellcheck source=/dev/null
111+
. /etc/rc.conf
112+
for _d in ${rc_directories:-/etc/rc.d}
113+
do
114+
if test -f "${_d}/${name}" && test -x "${_d}/${name}"
115+
then
116+
printf '%s/%s\n' "${_d}" "${name}"
117+
118+
fi
119+
done)
120+
test -x "${rc_script}" || {
121+
printf 'service %s could not be found' "${name}" >&2
122+
exit 1
123+
}
124+
125+
rcvar=$("${rc_script}" rcvar)
126+
fi
127+
128+
# remove service name comment
129+
rcvar=${rcvar#'#'*"${NL}"}
130+
# only first variable (at the time of writing there can’t be more
131+
# than one anyway)
132+
rcvar=${rcvar%%"${NL}"*}
133+
# some (older) versions of NetBSD prefix the rcvar with $
134+
rcvar=${rcvar#\$}
135+
136+
case ${rcvar}
137+
in
138+
(*=*)
139+
# OK
140+
extra=${rcvar%%=*}
141+
142+
case ${rcvar#*=}
143+
in
144+
([Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
145+
state='present' ;;
146+
(*)
147+
state='absent' ;;
148+
esac
149+
;;
150+
('')
151+
# this service is not enableable
152+
printf 'The service %s is not enableable\n' "${name}" >&2
153+
exit 1
154+
;;
155+
esac
156+
;;
99157
(openbsd)
100158
state='absent'
101159
# OpenBSD 5.7 and higher
@@ -109,4 +167,4 @@ else
109167
esac
110168
fi
111169
112-
echo "${state}"
170+
printf '%s%s\n' "${state}" "${extra:+ ${extra}}"

type/__start_on_boot/gencode-remote

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
#
2222

2323
state_should=$(cat "${__object:?}/parameter/state")
24-
state_is=$(cat "${__object:?}/explorer/state")
24+
read -r state_is _ <"${__object:?}/explorer/state" || :
2525
init=$(cat "${__global:?}/explorer/init")
2626
target_runlevel=$(cat "${__object:?}/parameter/target_runlevel")
2727

@@ -62,8 +62,8 @@ in
6262
;;
6363

6464

65-
(freebsd)
66-
: # handled in manifest
65+
(freebsd|netbsd)
66+
# handled in manifest
6767
;;
6868

6969
(openbsd)
@@ -104,6 +104,11 @@ in
104104
echo "'/etc/init.d/${name}' disable"
105105
;;
106106

107+
108+
(freebsd|netbsd)
109+
# handled in manifest
110+
;;
111+
107112
(openbsd)
108113
# OpenBSD 5.7 and higher
109114
echo "rcctl disable '${name}'"

type/__start_on_boot/manifest

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#
33
# 2018 Kamila Součková (kamila at ksp.sk)
44
# 2018 Jonas Weber (github at jonasw.de)
5+
# 2025 Dennis Camera (dennis.camera at riiengineering.ch)
56
#
67
# This file is part of skonfig-base.
78
#
@@ -19,10 +20,11 @@
1920
# along with skonfig-base. If not, see <http://www.gnu.org/licenses/>.
2021
#
2122

22-
state_should=$(cat "${__object:?}/parameter/state")
23-
state_is=$(cat "${__object:?}/explorer/state")
2423
name=${__object_id:?}
2524

25+
state_should=$(cat "${__object:?}/parameter/state")
26+
read -r state_is extra <"${__object:?}/explorer/state" || :
27+
2628
# Short circuit if nothing is to be done
2729
[ "${state_should}" = "${state_is}" ] && exit 0
2830

@@ -43,7 +45,23 @@ in
4345
--value "\"${value}\"" \
4446
--delimiter '='
4547
;;
48+
(netbsd)
49+
rcvar=${extra}
50+
: "${rcvar:?rcvar detection failed}"
51+
__key_value "/etc/rc.conf:${rcvar}" \
52+
--file /etc/rc.conf \
53+
--delimiter '=' --exact_delimiter \
54+
--key "${rcvar}" \
55+
--value "$(
56+
case ${state_should}
57+
in
58+
(present)
59+
echo YES ;;
60+
(absent)
61+
echo NO ;;
62+
esac)"
63+
;;
4664
(*)
47-
: # handled in gencode-remote
65+
# handled in gencode-remote
4866
;;
4967
esac

0 commit comments

Comments
 (0)