Add key+=append syntax to sysrc(8).

Reviewed by:	shurd
MFC after:	3 days
X-MFC-to:	stable/10 stable/9
This commit is contained in:
Devin Teske 2014-11-03 23:43:41 +00:00
parent 3fe8969a74
commit a7bdf21cf7
2 changed files with 27 additions and 7 deletions

View File

@ -40,7 +40,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig"
#
# Version information
#
SYSRC_VERSION="6.1 Jul-18,2014"
SYSRC_VERSION="6.2 Nov-3,2014"
#
# Options
@ -80,7 +80,7 @@ die()
#
usage()
{
f_err "Usage: %s [OPTIONS] name[=value] ...\n" "$pgm"
f_err "Usage: %s [OPTIONS] name[[+]=value] ...\n" "$pgm"
f_err "Try \`%s --help' for more information.\n" "$pgm"
die
}
@ -94,7 +94,7 @@ help()
local optfmt="\t%-11s%s\n"
local envfmt="\t%-17s%s\n"
f_err "Usage: %s [OPTIONS] name[=value] ...\n" "$pgm"
f_err "Usage: %s [OPTIONS] name[[+]=value] ...\n" "$pgm"
f_err "OPTIONS:\n"
f_err "$optfmt" "-a" \
@ -529,6 +529,11 @@ status=$SUCCESS
while [ $# -gt 0 ]; do
NAME="${1%%=*}"
case "$NAME" in
*+) mode=APPEND NAME="${NAME%+}" ;;
*) mode=ASSIGN
esac
[ "$DESCRIBE" ] && \
echo "$NAME: $( f_sysrc_desc "$NAME" )"
@ -593,14 +598,25 @@ while [ $# -gt 0 ]; do
#
if [ ! "$SHOW_VALUE" ]; then
echo "$NAME"
f_sysrc_set "$NAME" "${1#*}"
case "$mode" in
APPEND)
before=$( f_sysrc_get "$NAME" )
f_sysrc_set "$NAME" "$before${1#*=}"
;;
*)
f_sysrc_set "$NAME" "${1#*=}"
esac
else
if [ "$SHOW_FILE" ]; then
before=$( f_sysrc_find "$NAME" )
else
before=$( f_sysrc_get "$NAME" )
fi
if f_sysrc_set "$NAME" "${1#*=}"; then
if case "$mode" in
APPEND) f_sysrc_set "$NAME" "$before${1#*=}" ;;
*) f_sysrc_set "$NAME" "${1#*=}"
esac
then
if [ "$SHOW_FILE" ]; then
after=$( f_sysrc_find "$NAME" )
else

View File

@ -24,7 +24,7 @@
.\"
.\" $FreeBSD$
.\"
.Dd Jul 18, 2014
.Dd November 3, 2014
.Dt SYSRC 8
.Os
.Sh NAME
@ -35,7 +35,7 @@
.Op Fl cdDeFhinNqvx
.Op Fl f Ar file
.Op Fl j Ar jail | Fl R Ar dir
.Ar name Ns Op = Ns Ar value
.Ar name Ns Op Ns Oo + Oc Ns = Ns Ar value
.Ar ...
.Nm
.Op Fl cdDeFhinNqvx
@ -135,6 +135,10 @@ It shares the `-e' and `-n' options
and also has the same
.Ql name[=value]
syntax for making queries/assignments.
In addition
.Pq unlike Xr sysctl 8 ,
.Ql name+=value
is supported for appending values.
.Pp
However, while
.Xr sysctl 8