From owner-svn-src-stable@FreeBSD.ORG Mon Mar 23 19:12:57 2015 Return-Path: Delivered-To: svn-src-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id F067F179; Mon, 23 Mar 2015 19:12:56 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D0D26E0B; Mon, 23 Mar 2015 19:12:56 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t2NJCuIG047371; Mon, 23 Mar 2015 19:12:56 GMT (envelope-from dteske@FreeBSD.org) Received: (from dteske@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t2NJCuuF047369; Mon, 23 Mar 2015 19:12:56 GMT (envelope-from dteske@FreeBSD.org) Message-Id: <201503231912.t2NJCuuF047369@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: dteske set sender to dteske@FreeBSD.org using -f From: Devin Teske Date: Mon, 23 Mar 2015 19:12:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r280390 - stable/10/usr.sbin/sysrc X-SVN-Group: stable-10 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.18-1 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 23 Mar 2015 19:12:57 -0000 Author: dteske Date: Mon Mar 23 19:12:55 2015 New Revision: 280390 URL: https://svnweb.freebsd.org/changeset/base/280390 Log: MFC revisions 274068, 274119, 279624: r274068: Add key+=append syntax to sysrc(8) r279624: Add key-=remove syntax r274119: Add EXAMPLES-section entries for new syntax Reviewed by: shurd (r274068) Thanks to: seanc Relnotes: sysrc(8) now supports key+=append and key-=remove Modified: stable/10/usr.sbin/sysrc/sysrc stable/10/usr.sbin/sysrc/sysrc.8 Directory Properties: stable/10/ (props changed) Modified: stable/10/usr.sbin/sysrc/sysrc ============================================================================== --- stable/10/usr.sbin/sysrc/sysrc Mon Mar 23 18:54:37 2015 (r280389) +++ stable/10/usr.sbin/sysrc/sysrc Mon Mar 23 19:12:55 2015 (r280390) @@ -1,6 +1,6 @@ #!/bin/sh #- -# Copyright (c) 2010-2014 Devin Teske +# Copyright (c) 2010-2015 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -40,7 +40,7 @@ BSDCFG_SHARE="/usr/share/bsdconfig" # # Version information # -SYSRC_VERSION="6.1 Jul-18,2014" +SYSRC_VERSION="6.3 Mar-4,2015" # # 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,12 @@ status=$SUCCESS while [ $# -gt 0 ]; do NAME="${1%%=*}" + case "$NAME" in + *+) mode=APPEND NAME="${NAME%+}" ;; + *-) mode=REMOVE NAME="${NAME%-}" ;; + *) mode=ASSIGN + esac + [ "$DESCRIBE" ] && \ echo "$NAME: $( f_sysrc_desc "$NAME" )" @@ -589,18 +595,70 @@ while [ $# -gt 0 ]; do fi # - # If `-N' is passed, simplify the output + # Determine both `before' value and appropriate `new' value # - if [ ! "$SHOW_VALUE" ]; then - echo "$NAME" - f_sysrc_set "$NAME" "${1#*}" - else + case "$mode" in + APPEND) + before=$( f_sysrc_get "$NAME" ) + add="${1#*=}" + delim="${add%"${add#?}"}" # first character + oldIFS="$IFS" + case "$delim" in + ""|[$IFS]|[a-zA-Z0-9]) delim=" " ;; + *) IFS="$delim" + esac + new="$before" + for a in $add; do + [ "$a" ] || continue + skip= + for b in $before; do + [ "$b" = "$a" ] && skip=1 break + done + [ "$skip" ] || new="$new$delim$a" + done + new="${new#"$delim"}" IFS="$oldIFS" + unset add delim oldIFS a skip b + [ "$SHOW_FILE" ] && before=$( f_sysrc_find "$NAME" ) + ;; + REMOVE) + before=$( f_sysrc_get "$NAME" ) + remove="${1#*=}" + delim="${remove%"${remove#?}"}" # first character + oldIFS="$IFS" + case "$delim" in + ""|[$IFS]|[a-zA-Z0-9]) delim=" " ;; + *) IFS="$delim" + esac + new= + for b in $before; do + [ "$b" ] || continue + add=1 + for r in $remove; do + [ "$r" = "$b" ] && add= break + done + [ "$add" ] && new="$new$delim$b" + done + new="${new#"$delim"}" IFS="$oldIFS" + unset remove delim oldIFS b add r + [ "$SHOW_FILE" ] && before=$( f_sysrc_find "$NAME" ) + ;; + *) if [ "$SHOW_FILE" ]; then before=$( f_sysrc_find "$NAME" ) else before=$( f_sysrc_get "$NAME" ) fi - if f_sysrc_set "$NAME" "${1#*=}"; then + new="${1#*=}" + esac + + # + # If `-N' is passed, simplify the output + # + if [ ! "$SHOW_VALUE" ]; then + echo "$NAME" + f_sysrc_set "$NAME" "$new" + else + if f_sysrc_set "$NAME" "$new"; then if [ "$SHOW_FILE" ]; then after=$( f_sysrc_find "$NAME" ) else Modified: stable/10/usr.sbin/sysrc/sysrc.8 ============================================================================== --- stable/10/usr.sbin/sysrc/sysrc.8 Mon Mar 23 18:54:37 2015 (r280389) +++ stable/10/usr.sbin/sysrc/sysrc.8 Mon Mar 23 19:12:55 2015 (r280390) @@ -1,4 +1,4 @@ -.\" Copyright (c) 2011-2014 Devin Teske +.\" Copyright (c) 2011-2015 Devin Teske .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without @@ -24,7 +24,7 @@ .\" .\" $FreeBSD$ .\" -.Dd Jul 18, 2014 +.Dd March 4, 2015 .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,15 @@ It shares the `-e' and `-n' options and also has the same .Ql name[=value] syntax for making queries/assignments. +In addition +.Pq but unlike Xr sysctl 8 , +.Ql name+=value +is supported for adding items to values +.Pq see APPENDING VALUES +and +.Ql name-=value +is supported for removing items from values +.Pq see SUBTRACTING VALUES . .Pp However, while .Xr sysctl 8 @@ -183,6 +192,115 @@ modifying these integral files (yet taki grow unwieldy should .Nm be called repeatedly). +.Sh APPENDING VALUES +When using the +.Ql key+=value +syntax to add items to existing values, +the first character of the value is taken as the delimiter separating items +.Pq usually Qo \ Qc or Qo , Qc . +For example, in the following statement: +.Bl -tag -width indent+ +.It \ +.Nm +cloned_interfaces+=" gif0" +.El +.Pp +the first character is a space, informing +.Nm +that existing values are to be considered separated by whitespace. +If +.Ql gif0 +is not found in the existing value for +.Va cloned_interfaces , +it is added +.Pq with delimiter only if existing value is non-NULL . +.Pp +For convenience, if the first character is alpha-numeric +.Pq letters A-Z, a-z, or numbers 0-9 , +.Nm +uses the default setting of whitespace as separator. +For example, the above and below statements are equivalent since +.Dq gif0 +starts with an alpha-numeric character +.Pq the letter Li g : +.Pp +.Bl -tag -width indent+ +.It \ +.Nm +cloned_interfaces+=gif0 +.El +.Pp +Take the following sequence for example: +.Bl -tag -width indent+ +.It \ +.Nm +cloned_interfaces= # start with NULL +.It \ +.Nm +cloned_interfaces+=gif0 +.Dl # NULL -> `gif0' Pq NB: no preceding delimiter +.It \ +.Nm +cloned_interfaces+=gif0 # no change +.It \ +.Nm +cloned_interfaces+="tun0 gif0" +.Dl # `gif0' -> `gif0 tun0' Pq NB: no duplication +.El +.Pp +.Nm +prevents the same value from being added if already there. +.Sh SUBTRACTING VALUES +When using the +.Ql key-=value +syntax to remove items from existing values, +the first character of the value is taken as the delimiter separating items +.Pq usually Qo \ Qc or Qo , Qc . +For example, in the following statement: +.Pp +.Dl Nm cloned_interfaces-=" gif0" +.Pp +the first character is a space, informing +.Nm +that existing values are to be considered separated by whitespace. +If +.Ql gif0 +is found in the existing value for +.Va cloned_interfaces , +it is removed +.Pq extra delimiters removed . +.Pp +For convenience, if the first character is alpha-numeric +.Pq letters A-Z, a-z, or numbers 0-9 , +.Nm +uses the default setting of whitespace as separator. +For example, the above and below statements are equivalent since +.Dq gif0 +starts with an alpha-numeric character +.Pq the letter Li g : +.Pp +.Bl -tag -width indent+ +.It \ +.Nm +cloned_interfaces-=gif0 +.El +.Pp +Take the following sequence for example: +.Bl -tag -width indent+ +.It \ +.Nm +foo="bar baz" # start +.It \ +.Nm +foo-=bar # `bar baz' -> `baz' +.It \ +.Nm +foo-=baz # `baz' -> NULL +.El +.Pp +.Nm +removes all occurrences of all items provided +and collapses extra delimiters between items. .Sh ENVIRONMENT The following environment variables are referenced by .Nm : @@ -243,6 +361,16 @@ Working on other files, such as -f /etc/crontab MAILTO .Dl returns the value of the MAILTO setting Pq if configured . .Pp +Appending to existing values: +.Pp +.Nm +\&cloned_interfaces+=gif0 +.Dl appends Qo gif0 Qc to $cloned_interfaces Pq see APPENDING VALUES . +.Pp +.Nm +\&cloned_interfaces-=gif0 +.Dl removes Qo gif0 Qc from $cloned_interfaces Pq see SUBTRACTING VALUES . +.Pp In addition to the above syntax, .Nm also supports inline