Solved sysrc for /boot/loader.conf ?

Depends on what you want to modify. If you want to add items I suggest an editor (add comments to what/why and the key/value). If you want to use `sysrc(8)` on some values (-e.g., keys without dots) it "should work" as above (with the -f flag).

I have also created a tool which I use in automation you can try/use; my tool certainly is not perfect (-i.e., not "mission critical") but it does a pretty good job most of the time and is dependency free (compile and run).
 
I think a brief look at the `sysrc(8)` code is/may be interesting (to some).

If you start reading the source for `sysrc`, you'd essentially want (read: start paying attention to) this part from the source.
Code:
# If `-f file' was passed, set $rc_conf_files to an
# explicit value, modifying the default behavior of
# source_rc_confs().
#
if [ "${RC_CONFS+set}" ]; then
    [ "$SHOW_ALL" = "1" -a "$SERVICE" -a \
        ! "$DEFAULT" ] || rc_conf_files=
    rc_conf_files="$rc_conf_files $RC_CONFS"
    rc_conf_files="${rc_conf_files# }"
    rc_conf_files="${rc_conf_files% }"
fi

source_rc_confs

Which results in:
RC_CONFS = TRUE.
SERVICE = FALSE.
DEFAULT = FALSE.

Now, if we ignore the comments, we need to step back up to the `getopt()` portion to find out why I said the above conditions.

Code:
while getopts aAcdDeEf:Fhij:lLnNqR:s:vxX flag; do
    case "$flag" in
    a) SHOW_ALL=${SHOW_ALL:-1} ;;
    A) SHOW_ALL=2 ;;
    c) CHECK_ONLY=1 ;;
    d) DESCRIBE=1 ;;
    D) DEFAULT=1 RC_CONFS= ;;
    e) SHOW_EQUALS=1 ;;
    E) EXISTING_ONLY=1 ;;
    f) DEFAULT= RC_CONFS="$RC_CONFS${RC_CONFS:+ }$OPTARG" ;;

As this shows, because we just give the `-f` switch, `sysrc` will just default the "RC_CONFS" var to the `optarg` and operate on that file.

I, at least, found this interesting (others may feel like I'm just rambling but...*meh*).
 
Back on a BSD machine now. For what it's worth, I double checked /boot/defaults/loader.conf and there is a fair number of unsupported parameters which will not work with `sysrc(8)` so please keep that in mind (do not get too comfortable with the sysrc workflow with loader.conf).
 
Back
Top