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