From: Michael Orlitzky <mjo@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Subject: [gentoo-dev] [PATCH 4/4] acct-group.eclass: use an eclass variable for the override variable name
Date: Thu, 9 May 2024 07:57:45 -0400 [thread overview]
Message-ID: <20240509115745.5182-5-mjo@gentoo.org> (raw)
In-Reply-To: <20240509115745.5182-1-mjo@gentoo.org>
If (after upcasing and replacing hyphens by underscores) ACCT_GROUP_NAME
is set to something that isn't valid in a bash variable name, the eclass
will crash: it uses ACCT_GROUP_NAME to construct the make.conf override
variables in pkg_pretend() and src_install().
This commit relocates the computation of the "override name" subsequent
to the definition of ACCT_GROUP_NAME="${PN}". In Gentoo, policy prohibits
redefinition of that variable; so nothing is changed. But in an overlay,
this allows the ebuild to define ACCT_GROUP_NAME to something that would
not be valid in a bash variable at the expense of violating expectations
about the override variable names.
Signed-off-by: Michael Orlitzky <mjo@gentoo.org>
---
eclass/acct-group.eclass | 23 +++++++++++++++++++----
1 file changed, 19 insertions(+), 4 deletions(-)
diff --git a/eclass/acct-group.eclass b/eclass/acct-group.eclass
index 305440116ecd..69b262fb49cf 100644
--- a/eclass/acct-group.eclass
+++ b/eclass/acct-group.eclass
@@ -57,6 +57,23 @@ inherit user-info
# otherwise-valid group names.
ACCT_GROUP_NAME=${PN}
+# @ECLASS_VARIABLE: _OVERRIDE_NAME
+# @INTERNAL
+# @DESCRIPTION:
+# A version of the group name suitable for use in a bash variable. This
+# is used to construct the names of the make.conf override variables and
+# it will always be uppercase $PN with the hyphens replaced by
+# underscores. It is defined once, here, so that in an overlay the
+# ebuild may set ACCT_GROUP_NAME to something other than $PN without
+# affecting the name of the override variable. This is necessary if the
+# group name in question would lead to an invalid bash variable
+# name. Doing so does violate expectations with respect to the override
+# naming convention, but (a) your warranty is already void if you are
+# changing ACCT_GROUP_NAME or using make.conf overrides, and (b) you
+# shouldn't need make.conf overrides in an overlay.
+_OVERRIDE_NAME=${ACCT_GROUP_NAME^^}
+_OVERRIDE_NAME=${_OVERRIDE_NAME//-/_}
+
# @ECLASS_VARIABLE: ACCT_GROUP_ID
# @REQUIRED
# @DESCRIPTION:
@@ -97,8 +114,7 @@ acct-group_pkg_pretend() {
local group_id=${ACCT_GROUP_ID}
# check for the override
- local override_name=${ACCT_GROUP_NAME^^}
- local override_var=ACCT_GROUP_${override_name//-/_}_ID
+ local override_var=ACCT_GROUP_${_OVERRIDE_NAME}_ID
if [[ -n ${!override_var} ]]; then
group_id=${!override_var}
[[ ${group_id} -ge -1 ]] || die "${override_var}=${group_id} invalid!"
@@ -133,8 +149,7 @@ acct-group_src_install() {
debug-print-function ${FUNCNAME} "${@}"
# check for the override
- local override_name=${ACCT_GROUP_NAME^^}
- local override_var=ACCT_GROUP_${override_name//-/_}_ID
+ local override_var=ACCT_GROUP_${_OVERRIDE_NAME}_ID
if [[ -n ${!override_var} ]]; then
ewarn "${override_var}=${!override_var} override in effect, support will not be provided."
_ACCT_GROUP_ID=${!override_var}
--
2.43.2
prev parent reply other threads:[~2024-05-09 11:59 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-09 11:57 [gentoo-dev] [PATCH 0/4] acct-{user,group}.eclass: make user/group names writable Michael Orlitzky
2024-05-09 11:57 ` [gentoo-dev] [PATCH 1/4] acct-user.eclass: make ACCT_USER_NAME writable Michael Orlitzky
2024-05-09 12:00 ` Michał Górny
2024-05-10 5:58 ` Ulrich Mueller
2024-05-09 11:57 ` [gentoo-dev] [PATCH 2/4] acct-group.eclass: make ACCT_GROUP_NAME writable Michael Orlitzky
2024-05-09 11:57 ` [gentoo-dev] [PATCH 3/4] acct-user.eclass: use an eclass variable for the override variable name Michael Orlitzky
2024-05-09 12:03 ` Michał Górny
2024-05-09 12:12 ` Michael Orlitzky
2024-05-09 12:41 ` Michał Górny
2024-05-09 11:57 ` Michael Orlitzky [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240509115745.5182-5-mjo@gentoo.org \
--to=mjo@gentoo.org \
--cc=gentoo-dev@lists.gentoo.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox