From nobody Tue Sep 28 18:07:57 2021 X-Original-To: ports@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 91BB917ED67F; Tue, 28 Sep 2021 18:08:09 +0000 (UTC) (envelope-from freebsd@gushi.org) Received: from prime.gushi.org (prime.gushi.org [IPv6:2620:137:6000:10::142]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "prime.gushi.org", Issuer "RapidSSL TLS DV RSA Mixed SHA256 2020 CA-1" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4HJnYP350Rz4ZVH; Tue, 28 Sep 2021 18:08:09 +0000 (UTC) (envelope-from freebsd@gushi.org) Received: from smtpclient.apple ([IPv6:2601:602:0:8e8:85a0:8fc3:ba77:904a]) (authenticated bits=0) by prime.gushi.org (8.16.1/8.16.1) with ESMTPSA id 18SI82sI033138 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NO); Tue, 28 Sep 2021 11:08:05 -0700 (PDT) (envelope-from freebsd@gushi.org) DKIM-Filter: OpenDKIM Filter v2.10.3 prime.gushi.org 18SI82sI033138 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gushi.org; s=prime2014; t=1632852486; bh=mIhRBLKn8jlMFd/n9HllWmzTGTyUYLpaXAA+r8W7q2U=; h=Subject:From:In-Reply-To:Date:Cc:References:To; z=Subject:=20Re:=20Quick=20fun=20question:=20only=20set=20an=20rc.d =20variable=20sometimes?|From:=20Dan=20Mahoney=20|In-Reply-To:=20<7d0ec8d5-1be3-dbd0-5f00-0cf51e3fa18f@quip.cz>|D ate:=20Tue,=2028=20Sep=202021=2011:07:57=20-0700|Cc:=20ports@freeb sd.org,=0D=0A=20freebsd-rc@freebsd.org|References:=20<5dabceea-7f3 c-efbe-3778-67ca360547a@prime.gushi.org>=0D=0A=20<7d0ec8d5-1be3-db d0-5f00-0cf51e3fa18f@quip.cz>|To:=20Miroslav=20Lachman=20<000.fbsd @quip.cz>; b=LqyBcDIF3gSZVyiCigqO5mh3gtqraZvYmNOkSlcrymi6zSXDDme81GM/KQugdcqcE 1HxIBYjuiEocrLPv3/U497gKtlhPHrL1ZKnRIIoiUpZg6hnDLgnumcL6LQyzL/1oHz yRRKKMm5QbRzs4c+5N/70UshlfLdL0TOY22JXERr2Fh+XCzOIbMCtlApg8dwErshii aplG0qwLHfdHBplecQG9QqXNjSFQcTla/024b8gRuhunaXx421iyUDEqc6db7P1tct aIwnVIAbnGIvAOx2RFC2KWFz5IC16tZPvtAVKoaSorNAVp7/bJdqeV34yvjHgabibO dt3tgkMW5A0rQ== X-Authentication-Warning: prime.gushi.org: Host [IPv6:2601:602:0:8e8:85a0:8fc3:ba77:904a] claimed to be smtpclient.apple Content-Type: text/plain; charset=us-ascii List-Id: Porting software to FreeBSD List-Archive: https://lists.freebsd.org/archives/freebsd-ports List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-ports@freebsd.org X-BeenThere: freebsd-ports@freebsd.org Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.120.0.1.13\)) Subject: Re: Quick fun question: only set an rc.d variable sometimes? From: Dan Mahoney In-Reply-To: <7d0ec8d5-1be3-dbd0-5f00-0cf51e3fa18f@quip.cz> Date: Tue, 28 Sep 2021 11:07:57 -0700 Cc: ports@freebsd.org, freebsd-rc@freebsd.org Content-Transfer-Encoding: quoted-printable Message-Id: <2BAA032C-E80A-431A-99E1-6126956DDC16@gushi.org> References: <5dabceea-7f3c-efbe-3778-67ca360547a@prime.gushi.org> <7d0ec8d5-1be3-dbd0-5f00-0cf51e3fa18f@quip.cz> To: Miroslav Lachman <000.fbsd@quip.cz> X-Mailer: Apple Mail (2.3654.120.0.1.13) X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.6.2 (prime.gushi.org [IPv6:2620:137:6000:10:0:0:0:142]); Tue, 28 Sep 2021 18:08:06 +0000 (UTC) X-Rspamd-Queue-Id: 4HJnYP350Rz4ZVH X-Spamd-Bar: ---- Authentication-Results: mx1.freebsd.org; none X-Spamd-Result: default: False [-4.00 / 15.00]; REPLY(-4.00)[] X-ThisMailContainsUnwantedMimeParts: N 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