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