xref: /freebsd/usr.sbin/sysrc/sysrc.8 (revision 3dacd67e46e80e9c5d2604dbff76247ef6be1c2c)
1.\" Copyright (c) 2011-2012 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 Aug 24, 2012
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
103.Fl v
104and/or
105.Ev SYSRC_VERBOSE .
106.It Fl R Ar dir
107Operate within the root directory
108.Pq Sq Ar dir
109rather than
110.Pq Sq / .
111.It Fl v
112Verbose.
113Print the pathname of the specific
114.Xr rc.conf 5
115file where the directive was found.
116.It Fl x
117Remove variable(s) from specified file(s).
118.El
119.Pp
120This utility works similar to
121.Xr sysctl 8 .
122It shares the `-e' and `-n' options
123.Pq detailed above
124and also has the same
125.Ql name[=value]
126syntax for querying/setting configuration options.
127.Pp
128However, while
129.Xr sysctl 8
130serves to query/modify MIBs in the entrant kernel,
131.Nm
132instead works on values in the system
133.Xr rc.conf 5
134configuration files.
135.Pp
136The list of system configuration files is configured in the file
137.Ql /etc/defaults/rc.conf
138within the variable
139.Ql rc_conf_files ,
140which by-default contains a space-separated list of pathnames.
141On all FreeBSD
142systems, this defaults to the value "/etc/rc.conf /etc/rc.conf.local".
143Each
144pathname is sourced in-order upon startup.
145It is in the same fashion that
146.Nm
147sources the configuration files before returning the value of the given
148variable.
149.Pp
150When supplied a variable name,
151.Nm
152will return the value of the variable.
153If the variable does not appear in any
154of the configured
155.Ql rc_conf_files ,
156an error is printed and error status is returned.
157.Pp
158When changing values of a given variable, it does not matter if the variable
159appears in any of the
160.Ql rc_conf_files
161or not.
162If the variable does not appear in any of the files, it is appended to
163the end of the first pathname in the
164.Ql rc_conf_files
165variable.
166Otherwise,
167.Nm
168will replace only the last-occurrence in the last-file found to contain the
169variable.
170This gets the value to take effect next boot without heavily
171modifying these integral files (yet taking care not to allow the file to
172grow unwieldy should
173.Nm
174be called repeatedly).
175.Sh ENVIRONMENT
176The following environment variables are referenced by
177.Nm :
178.Bl -tag -width ".Ev SYSRC_VERBOSE"
179.It Ev RC_CONFS
180Override default
181.Ql rc_conf_files
182.Pq even if set to NULL .
183.It Ev RC_DEFAULTS
184Location of
185.Ql /etc/defaults/rc.conf
186file.
187.It Ev SYSRC_VERBOSE
188Default verbosity.
189Set to non-NULL to enable.
190.El
191.Sh DEPENDENCIES
192The following standard commands are required by
193.Nm :
194.Pp
195.Xr awk 1 ,
196.Xr cat 1 ,
197.Xr chmod 1 ,
198.Xr env 1 ,
199.Xr grep 1 ,
200.Xr jls 1 ,
201.Xr mktemp 1 ,
202.Xr mv 1 ,
203.Xr rm 1 ,
204.Xr sh 1 ,
205.Xr stat 1 ,
206.Xr tail 1 ,
207.Xr chown 8
208and
209.Xr jexec 8 .
210.Sh FILES
211.Bl -tag -width ".Pa /etc/defaults/rc.conf" -compact
212.It Pa /etc/defaults/rc.conf
213.It Pa /etc/rc.conf
214.It Pa /etc/rc.conf.local
215.El
216.Sh EXAMPLES
217Below are some simple examples of how
218.Nm
219can be used to query certain values from the
220.Xr rc.conf 5
221collection of system configuration files:
222.Pp
223.Nm
224sshd_enable
225.Dl returns the value of $sshd_enable, usually YES or NO .
226.Pp
227.Nm
228defaultrouter
229.Dl returns IP address of default router Pq if configured .
230.Pp
231Working on other files, such as
232.Xr crontab 5 :
233.Pp
234.Nm
235-f /etc/crontab MAILTO
236.Dl returns the value of the MAILTO setting Pq if configured .
237.Pp
238In addition to the above syntax,
239.Nm
240also supports inline
241.Xr sh 1
242PARAMETER expansion for changing the way values are reported, shown below:
243.Pp
244.Nm
245\&'hostname%%.*'
246.Dl returns $hostname up to (but not including) first `.' .
247.Pp
248.Nm
249\&'network_interfaces%%[$IFS]*'
250.Dl returns first word of $network_interfaces .
251.Pp
252.Nm
253\&'ntpdate_flags##*[$IFS]'
254.Dl returns last word of $ntpdate_flags (time server address) .
255.Pp
256.Nm
257usbd_flags-"default"
258.Dl returns $usbd_flags or "default" if unset or NULL .
259.Pp
260.Nm
261cloned_interfaces+"alternate"
262.Dl returns "alternate" if $cloned_interfaces is set .
263.Pp
264.Nm
265\&'#kern_securelevel'
266.Dl returns length in characters of $kern_securelevel .
267.Pp
268.Nm
269\&'hostname?'
270.Dl returns NULL and error status 2 if $hostname is unset Pq or if set, returns the value of $hostname with no error status .
271.Pp
272.Nm
273\&'hostname:?'
274.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 .
275.Sh LIMITATIONS
276The
277.Nm
278utility presently does not support the
279.Ql rc.conf.d
280collection of system configuration files
281.Pq which requires a service name to be known during execution .
282.Pp
283This will be corrected by a future enhancement.
284.Sh SEE ALSO
285.Xr jls 1 ,
286.Xr rc.conf 5 ,
287.Xr jail 8 ,
288.Xr jexec 8 ,
289.Xr rc 8 ,
290.Xr sysctl 8
291.Sh HISTORY
292A
293.Nm
294utility first appeared in
295.Fx 10.0 .
296.Sh AUTHORS
297.An Devin Teske Aq dteske@FreeBSD.org
298.Sh THANKS TO
299Brandon Gooch, Garrett Cooper, Julian Elischer, Pawel Jakub Dawidek,
300Cyrille Lefevre, Ross West, Stefan Esser, Marco Steinbach, and Jilles Tjoelker
301for suggestions and help.
302