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