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 <m...@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


Reply via email to