1.\" Copyright (c) 2011-2013 Devin Teske 2.\" All rights reserved. 3.\" 4.\" Redistribution and use in source and binary forms, with or without 5.\" modification, are permitted provided that the following conditions 6.\" are met: 7.\" 1. Redistributions of source code must retain the above copyright 8.\" notice, this list of conditions and the following disclaimer. 9.\" 2. Redistributions in binary form must reproduce the above copyright 10.\" notice, this list of conditions and the following disclaimer in the 11.\" documentation and/or other materials provided with the distribution. 12.\" 13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23.\" SUCH DAMAGE. 24.\" 25.\" $FreeBSD$ 26.\" 27.Dd Nov 7, 2013 28.Dt SYSRC 8 29.Os 30.Sh NAME 31.Nm sysrc 32.Nd safely edit system rc files 33.Sh SYNOPSIS 34.Nm 35.Op Fl dDeFhinNqvx 36.Op Fl f Ar file 37.Op Fl j Ar jail | Fl R Ar dir 38.Ar name Ns Op = Ns Ar value 39.Ar ... 40.Nm 41.Op Fl dDeFhinNqvx 42.Op Fl f Ar file 43.Op Fl j Ar jail | Fl R Ar dir 44.Fl a | A 45.Sh DESCRIPTION 46The 47.Nm 48utility retrieves 49.Xr rc.conf 5 50variables from the collection of system rc files and allows processes with 51appropriate privilege to change values in a safe and effective manner. 52.Pp 53The following options are available: 54.Bl -tag -width indent+ 55.It Fl a 56Dump a list of all non-default configuration variables. 57.It Fl A 58Dump a list of all configuration variables 59.Pq incl. defaults . 60.It Fl d 61Print a description of the given variable. 62.It Fl D 63Show default value(s) only (this is the same as setting RC_CONFS to NULL or 64passing `-f' with a NULL file-argument). 65.It Fl e 66Print query results as 67.Ql var=value 68.Pq useful for producing output to be fed back in . 69Ignored if 70.Fl n 71is specified. 72.It Fl f Ar file 73Operate on the specified file(s) instead of the files obtained by reading the 74.Sq rc_conf_files 75entry in the 76.Ev RC_DEFAULTS 77file. 78This option can be specified multiple times for additional files. 79.It Fl F 80Show only the last 81.Xr rc.conf 5 82file each directive is in. 83.It Fl h 84Print a short usage message to stderr and exit. 85.It Fl -help 86Print a full usage statement to stderr and exit. 87.It Fl i 88Ignore unknown variables. 89.It Fl j Ar jail 90The 91.Ar jid 92or name of the 93.Ar jail 94to operate within 95.Pq overrides So Fl R Ar dir Sc ; requires Xr jexec 8 . 96.It Fl n 97Show only variable values, not their names. 98.It Fl N 99Show only variable names, not their values. 100.It Fl q 101Quiet. 102Ignore previous occurrences of 103.Fl v 104flag. 105.It Fl R Ar dir 106Operate within the root directory 107.Pq Sq Ar dir 108rather than 109.Pq Sq / . 110.It Fl v 111Verbose. 112Print the pathname of the specific 113.Xr rc.conf 5 114file where the directive was found. 115.It Fl -version 116Print version information to stdout and exit. 117.It Fl x 118Remove variable(s) from specified file(s). 119.El 120.Pp 121This utility works similar to 122.Xr sysctl 8 . 123It shares the `-e' and `-n' options 124.Pq detailed above 125and also has the same 126.Ql name[=value] 127syntax for querying/setting configuration options. 128.Pp 129However, while 130.Xr sysctl 8 131serves to query/modify MIBs in the entrant kernel, 132.Nm 133instead works on values in the system 134.Xr rc.conf 5 135configuration files. 136.Pp 137The list of system configuration files is configured in the file 138.Ql /etc/defaults/rc.conf 139within the variable 140.Ql rc_conf_files , 141which by-default contains a space-separated list of pathnames. 142On all FreeBSD 143systems, this defaults to the value "/etc/rc.conf /etc/rc.conf.local". 144Each 145pathname is sourced in-order upon startup. 146It is in the same fashion that 147.Nm 148sources the configuration files before returning the value of the given 149variable. 150.Pp 151When supplied a variable name, 152.Nm 153will return the value of the variable. 154If the variable does not appear in any 155of the configured 156.Ql rc_conf_files , 157an error is printed and error status is returned. 158.Pp 159When changing values of a given variable, it does not matter if the variable 160appears in any of the 161.Ql rc_conf_files 162or not. 163If the variable does not appear in any of the files, it is appended to 164the end of the first pathname in the 165.Ql rc_conf_files 166variable. 167Otherwise, 168.Nm 169will replace only the last-occurrence in the last-file found to contain the 170variable. 171This gets the value to take effect next boot without heavily 172modifying these integral files (yet taking care not to allow the file to 173grow unwieldy should 174.Nm 175be called repeatedly). 176.Sh ENVIRONMENT 177The following environment variables are referenced by 178.Nm : 179.Bl -tag -width ".Ev RC_DEFAULTS" 180.It Ev RC_CONFS 181Override default 182.Ql rc_conf_files 183.Pq even if set to NULL . 184.It Ev RC_DEFAULTS 185Location of 186.Ql /etc/defaults/rc.conf 187file. 188.El 189.Sh DEPENDENCIES 190The following standard commands are required by 191.Nm : 192.Pp 193.Xr awk 1 , 194.Xr cat 1 , 195.Xr chmod 1 , 196.Xr env 1 , 197.Xr grep 1 , 198.Xr jls 1 , 199.Xr mktemp 1 , 200.Xr mv 1 , 201.Xr rm 1 , 202.Xr sh 1 , 203.Xr stat 1 , 204.Xr tail 1 , 205.Xr chown 8 206and 207.Xr jexec 8 . 208.Sh FILES 209.Bl -tag -width ".Pa /etc/defaults/rc.conf" -compact 210.It Pa /etc/defaults/rc.conf 211.It Pa /etc/rc.conf 212.It Pa /etc/rc.conf.local 213.El 214.Sh EXAMPLES 215Below are some simple examples of how 216.Nm 217can be used to query certain values from the 218.Xr rc.conf 5 219collection of system configuration files: 220.Pp 221.Nm 222sshd_enable 223.Dl returns the value of $sshd_enable, usually YES or NO . 224.Pp 225.Nm 226defaultrouter 227.Dl returns IP address of default router Pq if configured . 228.Pp 229Working on other files, such as 230.Xr crontab 5 : 231.Pp 232.Nm 233-f /etc/crontab MAILTO 234.Dl returns the value of the MAILTO setting Pq if configured . 235.Pp 236In addition to the above syntax, 237.Nm 238also supports inline 239.Xr sh 1 240PARAMETER expansion for changing the way values are reported, shown below: 241.Pp 242.Nm 243\&'hostname%%.*' 244.Dl returns $hostname up to (but not including) first `.' . 245.Pp 246.Nm 247\&'network_interfaces%%[$IFS]*' 248.Dl returns first word of $network_interfaces . 249.Pp 250.Nm 251\&'ntpdate_flags##*[$IFS]' 252.Dl returns last word of $ntpdate_flags (time server address) . 253.Pp 254.Nm 255usbd_flags-"default" 256.Dl returns $usbd_flags or "default" if unset or NULL . 257.Pp 258.Nm 259cloned_interfaces+"alternate" 260.Dl returns "alternate" if $cloned_interfaces is set . 261.Pp 262.Nm 263\&'#kern_securelevel' 264.Dl returns length in characters of $kern_securelevel . 265.Pp 266.Nm 267\&'hostname?' 268.Dl returns NULL and error status 2 if $hostname is unset Pq or if set, returns the value of $hostname with no error status . 269.Pp 270.Nm 271\&'hostname:?' 272.Dl returns NULL and error status 2 if $hostname is unset or NULL Pq or if set and non-NULL, returns value without error status . 273.Sh LIMITATIONS 274The 275.Nm 276utility presently does not support the 277.Ql rc.conf.d 278collection of system configuration files 279.Pq which requires a service name to be known during execution . 280.Pp 281This will be corrected by a future enhancement. 282.Sh SEE ALSO 283.Xr jls 1 , 284.Xr rc.conf 5 , 285.Xr jail 8 , 286.Xr jexec 8 , 287.Xr rc 8 , 288.Xr sysctl 8 289.Sh HISTORY 290A 291.Nm 292utility first appeared in 293.Fx 9.2 . 294.Sh AUTHORS 295.An Devin Teske Aq dteske@FreeBSD.org 296.Sh THANKS TO 297Brandon Gooch, Garrett Cooper, Julian Elischer, Pawel Jakub Dawidek, 298Cyrille Lefevre, Ross West, Stefan Esser, Marco Steinbach, and Jilles Tjoelker 299for suggestions and help. 300