From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id F4091158004 for ; Thu, 9 May 2024 11:59:06 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id DC665E2AFF; Thu, 9 May 2024 11:57:53 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 69604E2AF0 for ; Thu, 9 May 2024 11:57:53 +0000 (UTC) From: Michael Orlitzky 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 Message-ID: <20240509115745.5182-5-mjo@gentoo.org> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240509115745.5182-1-mjo@gentoo.org> References: <20240509115745.5182-1-mjo@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Archives-Salt: 84545e9f-4560-43c0-b14f-ea7beeb7ed9a X-Archives-Hash: 7116570a534248d08742004709557a3a 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 --- 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