Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 28 Sep 2021 11:07:57 -0700
From:      Dan Mahoney <freebsd@gushi.org>
To:        Miroslav Lachman <000.fbsd@quip.cz>
Cc:        ports@freebsd.org, freebsd-rc@freebsd.org
Subject:   Re: Quick fun question: only set an rc.d variable sometimes?
Message-ID:  <2BAA032C-E80A-431A-99E1-6126956DDC16@gushi.org>
In-Reply-To: <7d0ec8d5-1be3-dbd0-5f00-0cf51e3fa18f@quip.cz>
References:  <5dabceea-7f3c-efbe-3778-67ca360547a@prime.gushi.org> <7d0ec8d5-1be3-dbd0-5f00-0cf51e3fa18f@quip.cz>

next in thread | previous in thread | raw e-mail | index | archive | help
Miroslav,

Thanks much for this!

Some of this would be useful additions/further-reading to the handbook =
page I originally quoted.  I'm happy to prepare a diff, if there's =
reasonable chance it would be accepted.

-Dan

> On Sep 28, 2021, at 4:59 AM, Miroslav Lachman <000.fbsd@quip.cz> =
wrote:
>=20
> On 28/09/2021 05:23, Dan Mahoney (Gushi) wrote:
>> Hey all,
>> I'm dealing with rc.d scripting and reading =
https://docs.freebsd.org/en/articles/rc-scripting/
>> Here's my question: Is there a sane way to have something like =
foo_pid *completely unset* in one case, but overridable by rc.conf =
after?
>> It took me a bit to wrap my head around the:
>> : ${dummy_enable:=3Dno}
>> : ${dummy_msg=3D"Nothing started."}
>> Examples.  (Why that first colon, what is this :=3D syntax), etc.
>=20
> The first colon is builtin function same as /bin/true
>=20
> A useful application for : is if you're only interested in using =
parameter expansions for their side-effects rather than actually passing =
their result to a command.
> You can use the parameter expansion as an argument to :
>=20
> : "${var:=3D$1}"
>=20
> There is as many variants to handle this as many rc scripts are =
installed on your system. Each have it slightly different (syntax) but =
with the same meaning:
>=20
> Apache
> [ -z "$apache24_enable" ]       && apache24_enable=3D"NO"
> [ -z "$apache24limits_enable" ] && apache24limits_enable=3D"NO"
> [ -z "$apache24limits_args" ]   && apache24limits_args=3D"-e -C =
daemon"
> [ -z "$apache24_http_accept_enable" ] && =
apache24_http_accept_enable=3D"NO"
> [ -z "$apache24_configcheck_disable" ] && =
apache24_configcheck_disable=3D"NO"
>=20
> Amavisd
> : ${amavisd_enable:=3DNO}
> pidfile=3D${amavisd_pidfile-"/var/amavis/amavisd.pid"}
>=20
> ISC DHCPD
> # default name to "dhcpd" if guessing failed
> # Trailing semicolon also for service(8)'s benefit:
> name=3D"${name:-dhcpd}" ;
> name=3D${name##*/isc-}
>=20
>=20
> Some more explanation:
>=20
> To get the assigned value, or default if it's missing:
>=20
> FOO=3D"${VARIABLE:-default}"
>=20
> Or to assign default to VARIABLE at the same time:
>=20
> FOO=3D"${VARIABLE:=3Ddefault}"
>=20
> Or check the link =
https://bash.cyberciti.biz/guide/Default_shell_variables_value
>=20
>> What I'm trying to say in rc.subr language is:
>> If the user has set something in rc.conf, use it.  Otherwise, leave =
it TOTALLY UNSET.  Not to the null string.  Undefined.
>=20
> Easily readable syntax can be like this:
>=20
> [ -n "$kdc_pid" ] && pidfile=3D"$kdc_pid"
>=20
> Variable pidfile will be set to a value of $kdc_pid only if $kdc_pid =
is set and is not empty.
>=20
> Miroslav Lachman




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?2BAA032C-E80A-431A-99E1-6126956DDC16>