Date: Tue, 19 Oct 2010 10:50:29 -0700 From: Devin Teske <dteske@vicor.com> To: freebsd-rc@freebsd.org Cc: Julian Elischer <julian@freebsd.org> Subject: Re: sysrc(8) -- a sysctl(8)-like utility for managing rc.conf(5) Message-ID: <1287510629.25599.2.camel@localhost.localdomain> In-Reply-To: <1287448781.5713.3.camel@localhost.localdomain> References: <1286925182.32724.18.camel@localhost.localdomain> <1286996709.32724.60.camel@localhost.localdomain> <1287448781.5713.3.camel@localhost.localdomain>
next in thread | previous in thread | raw e-mail | index | archive | help
On Mon, 2010-10-18 at 17:39 -0700, Devin Teske wrote: > On Wed, 2010-10-13 at 12:05 -0700, Devin Teske wrote: > > On Tue, 2010-10-12 at 16:13 -0700, Devin Teske wrote: > > > Hey all, > > > > > > [...] > > > > > > Behold... sysrc(8) v2.0 > > > > > > #!/bin/sh > > > [...] > > > > Version 2.1 is available here: http://druidbsd.sf.net/ > > Version 2.2 now. > Same links. > > I added `-R dir' for specifying an alternate root (other than `/') > directory (mostly for handling jails). Version 2.3 now. Same links. I added `-j jail' for specifying a jail id or name to operate within (requires jls(8); overrides `-R dir'). > > > > > Direct links: > > http://druidbsd.sf.net/download/sysrc.gz (download gzipped) > > http://druidbsd.sf.net/download/sysrc.txt (view as text) > > > > Here's the changes: > > > --- sysrc.2_2 2010-10-18 17:38:51.000000000 -0700 +++ sysrc 2010-10-19 10:40:33.000000000 -0700 @@ -2,8 +2,8 @@ # -*- tab-width: 4 -*- ;; Emacs # vi: set tabstop=4 :: Vi/ViM # -# Revision: 2.2 -# Last Modified: October 18th, 2010 +# Revision: 2.3 +# Last Modified: October 19th, 2010 ############################################################ COPYRIGHT # # (c)2010. Devin Teske. All Rights Reserved. @@ -30,7 +30,8 @@ # SUCH DAMAGE. # # AUTHOR DATE DESCRIPTION -# dteske 2010.10.18 Add `-R dir' for operating in different root-dir +# dteske 2010.10.19 Add `-j jail' for operating within jails (see jls(8)). +# dteske 2010.10.18 Add `-R dir' for operating in different root-dir. # dteske 2010.10.13 Allow `-f file' multiple times. # dteske 2010.10.12 Updates per freebsd-hackers thread. # dteske 2010.09.29 Initial version. @@ -56,6 +57,8 @@ # -n Show only variable values, not their names. # -N Show only variable names, not their values. # -R dir Operate within the root directory `dir' rather than `/'. +# -j jail The jid or name of the jail to operate within (overrides +# `-R dir'; requires jls(8)). # # ENVIRONMENT: # RC_DEFAULTS Location of `/etc/defaults/rc.conf' file. @@ -91,6 +94,7 @@ progname="${0##*/}" # DESCRIBE= IGNORE_UNKNOWNS= +JAIL= RC_CONFS= ROOTDIR= SHOW_ALL= @@ -175,6 +179,10 @@ usage() "Show only variable names, not their values." eprintf "$optfmt" "-R dir" \ "Operate within the root directory \`dir' rather than \`/'." + eprintf "$optfmt" "-j jail" \ + "The jid or name of the jail to operate within (overrides" + eprintf "$optfmt" "" \ + "\`-R dir'; requires jls(8))." eprintf "\n" eprintf "ENVIRONMENT:\n" @@ -456,6 +464,14 @@ sysrc_set() fi # + # If not found, append new value to last file and return. + # + if [ "$not_found" ]; then + echo "$varname=\"$new_value\"" >> "$file" + return $SUCCESS + fi + + # # Perform sanity checks. # if [ ! -w $file ]; then @@ -465,14 +481,6 @@ sysrc_set() fi # - # If not found, append new value to last file and return. - # - if [ "$not_found" ]; then - echo "$varname=\"$new_value\"" >> "$file" - return $SUCCESS - fi - - # # Operate on the matching file, replacing only the last occurrence. # local new_contents="`lrev $file 2> /dev/null | \ @@ -585,10 +593,12 @@ $LINE" # # Process command-line options # -while getopts hf:aAdevinNR: flag; do +while getopts hf:aAdevinNR:j: flag; do case "$flag" in h) usage;; - f) RC_CONFS="$RC_CONFS${RC_CONFS:+ }$OPTARG";; + f) [ "$OPTARG" ] || die \ + "%s: Missing or null argument to \`-f' flag" "$progname" + RC_CONFS="$RC_CONFS${RC_CONFS:+ }$OPTARG";; a) SHOW_ALL=1;; A) SHOW_ALL=2;; d) DESCRIBE=1;; @@ -597,7 +607,12 @@ while getopts hf:aAdevinNR: flag; do i) IGNORE_UNKNOWNS=1;; n) SHOW_NAME=;; N) SHOW_VALUE=;; - R) ROOTDIR="$OPTARG";; + R) [ "$OPTARG" ] || die \ + "%s: Missing or null argument to \`-R' flag" "$progname" + ROOTDIR="$OPTARG";; + j) [ "$OPTARG" ] || die \ + "%s: Missing or null argument to \`-j' flag" "$progname" + JAIL="$OPTARG";; \?) usage;; esac done @@ -616,6 +631,13 @@ if [ ! "$SHOW_VALUE" ]; then fi # +# Process `-j jail' command-line option +# +if [ "$JAIL" ]; then + ROOTDIR="$( jls -j "$JAIL" path )" || die +fi + +# # Process `-R dir' command-line option # if [ "$ROOTDIR" ]; then -- Cheers, Devin Teske -> CONTACT INFORMATION <- Business Solutions Consultant II FIS - fisglobal.com 510-735-5650 Mobile 510-621-2038 Office 510-621-2020 Office Fax 909-477-4578 Home/Fax devin.teske@fisglobal.com -> LEGAL DISCLAIMER <- This message contains confidential and proprietary information of the sender, and is intended only for the person(s) to whom it is addressed. Any use, distribution, copying or disclosure by any other person is strictly prohibited. If you have received this message in error, please notify the e-mail sender immediately, and delete the original message without making a copy. -> END TRANSMISSION <-
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?1287510629.25599.2.camel>