eclass/acct-group: Sync with gentoo

It's from gentoo commit 84b3ffe79a9699b2246adfcfda74f39c1b577651.
This commit is contained in:
Krzesimir Nowak 2022-01-18 16:23:14 +01:00
parent 4897ff4093
commit 32053a1d5e

View File

@ -1,4 +1,4 @@
# Copyright 2019 Gentoo Authors # Copyright 2019-2021 Gentoo Authors
# Distributed under the terms of the GNU General Public License v2 # Distributed under the terms of the GNU General Public License v2
# @ECLASS: acct-group.eclass # @ECLASS: acct-group.eclass
@ -7,7 +7,7 @@
# @AUTHOR: # @AUTHOR:
# Michael Orlitzky <mjo@gentoo.org> # Michael Orlitzky <mjo@gentoo.org>
# Michał Górny <mgorny@gentoo.org> # Michał Górny <mgorny@gentoo.org>
# @SUPPORTED_EAPIS: 7 # @SUPPORTED_EAPIS: 7 8
# @BLURB: Eclass used to create and maintain a single group entry # @BLURB: Eclass used to create and maintain a single group entry
# @DESCRIPTION: # @DESCRIPTION:
# This eclass represents and creates a single group entry. The name # This eclass represents and creates a single group entry. The name
@ -20,22 +20,23 @@
# and add an ebuild with the following contents: # and add an ebuild with the following contents:
# #
# @CODE # @CODE
# EAPI=7 # EAPI=8
# inherit acct-group # inherit acct-group
# ACCT_GROUP_ID=200 # ACCT_GROUP_ID=200
# @CODE # @CODE
# #
# Then you add appropriate dependency to your package. The dependency # Then you add appropriate dependencies to your package. Note that
# type(s) should be: # the build system might need to resolve names, too. The dependency
# - DEPEND (+ RDEPEND) if the group is already needed at build time, # type(s) should be: BDEPEND if the group must be resolvable at build
# - RDEPEND if it is needed at install time (e.g. you 'fowners' files # time (e.g. 'fowners' uses it in src_install), IDEPEND if it must be
# in pkg_preinst) or run time. # resolvable at install time (e.g. 'fowners' uses it in pkg_preinst),
# and RDEPEND in every case.
if [[ -z ${_ACCT_GROUP_ECLASS} ]]; then if [[ -z ${_ACCT_GROUP_ECLASS} ]]; then
_ACCT_GROUP_ECLASS=1 _ACCT_GROUP_ECLASS=1
case ${EAPI:-0} in case ${EAPI:-0} in
7) ;; 7|8) ;;
*) die "EAPI=${EAPI:-0} not supported";; *) die "EAPI=${EAPI:-0} not supported";;
esac esac
@ -59,7 +60,8 @@ readonly ACCT_GROUP_NAME
# @REQUIRED # @REQUIRED
# @DESCRIPTION: # @DESCRIPTION:
# Preferred GID for the new group. This variable is obligatory, and its # Preferred GID for the new group. This variable is obligatory, and its
# value must be unique across all group packages. # value must be unique across all group packages. This can be overriden
# in make.conf through ACCT_GROUP_<UPPERCASE_USERNAME>_ID variable.
# #
# Overlays should set this to -1 to dynamically allocate GID. Using -1 # Overlays should set this to -1 to dynamically allocate GID. Using -1
# in ::gentoo is prohibited by policy. # in ::gentoo is prohibited by policy.
@ -75,12 +77,12 @@ readonly ACCT_GROUP_NAME
# << Boilerplate ebuild variables >> # << Boilerplate ebuild variables >>
: ${DESCRIPTION:="System group: ${ACCT_GROUP_NAME}"} : ${DESCRIPTION:="System group: ${ACCT_GROUP_NAME}"}
: ${SLOT:=0} : ${SLOT:=0}
: ${KEYWORDS:=alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 ~riscv s390 sh sparc x86 ~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris} : ${KEYWORDS:=alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 ~riscv s390 sparc x86 ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris}
S=${WORKDIR} S=${WORKDIR}
# << Phase functions >> # << Phase functions >>
EXPORT_FUNCTIONS pkg_pretend pkg_preinst EXPORT_FUNCTIONS pkg_pretend src_install pkg_preinst
# @FUNCTION: acct-group_pkg_pretend # @FUNCTION: acct-group_pkg_pretend
# @DESCRIPTION: # @DESCRIPTION:
@ -91,31 +93,63 @@ acct-group_pkg_pretend() {
# verify ACCT_GROUP_ID # verify ACCT_GROUP_ID
[[ -n ${ACCT_GROUP_ID} ]] || die "Ebuild error: ACCT_GROUP_ID must be set!" [[ -n ${ACCT_GROUP_ID} ]] || die "Ebuild error: ACCT_GROUP_ID must be set!"
[[ ${ACCT_GROUP_ID} -eq -1 ]] && return [[ ${ACCT_GROUP_ID} -ge -1 ]] || die "Ebuild error: ACCT_GROUP_ID=${ACCT_GROUP_ID} invalid!"
[[ ${ACCT_GROUP_ID} -ge 0 ]] || die "Ebuild errors: ACCT_GROUP_ID=${ACCT_GROUP_ID} invalid!" local group_id=${ACCT_GROUP_ID}
# check for the override
local override_name=${ACCT_GROUP_NAME^^}
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!"
fi
# check for ACCT_GROUP_ID collisions early # check for ACCT_GROUP_ID collisions early
if [[ -n ${ACCT_GROUP_ENFORCE_ID} ]]; then if [[ ${group_id} -ne -1 && -n ${ACCT_GROUP_ENFORCE_ID} ]]; then
local group_by_id=$(egetgroupname "${ACCT_GROUP_ID}") local group_by_id=$(egetgroupname "${group_id}")
local group_by_name=$(egetent group "${ACCT_GROUP_NAME}") local group_by_name=$(egetent group "${ACCT_GROUP_NAME}")
if [[ -n ${group_by_id} ]]; then if [[ -n ${group_by_id} ]]; then
if [[ ${group_by_id} != ${ACCT_GROUP_NAME} ]]; then if [[ ${group_by_id} != ${ACCT_GROUP_NAME} ]]; then
eerror "The required GID is already taken by another group." eerror "The required GID is already taken by another group."
eerror " GID: ${ACCT_GROUP_ID}" eerror " GID: ${group_id}"
eerror " needed for: ${ACCT_GROUP_NAME}" eerror " needed for: ${ACCT_GROUP_NAME}"
eerror " current group: ${group_by_id}" eerror " current group: ${group_by_id}"
die "GID ${ACCT_GROUP_ID} taken already" die "GID ${group_id} taken already"
fi fi
elif [[ -n ${group_by_name} ]]; then elif [[ -n ${group_by_name} ]]; then
eerror "The requested group exists already with wrong GID." eerror "The requested group exists already with wrong GID."
eerror " groupname: ${ACCT_GROUP_NAME}" eerror " groupname: ${ACCT_GROUP_NAME}"
eerror " requested GID: ${ACCT_GROUP_ID}" eerror " requested GID: ${group_id}"
eerror " current entry: ${group_by_name}" eerror " current entry: ${group_by_name}"
die "Group ${ACCT_GROUP_NAME} exists with wrong GID" die "Group ${ACCT_GROUP_NAME} exists with wrong GID"
fi fi
fi fi
} }
# @FUNCTION: acct-group_src_install
# @DESCRIPTION:
# Installs sysusers.d file for the group.
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
if [[ -n ${!override_var} ]]; then
ewarn "${override_var}=${!override_var} override in effect, support will not be provided."
_ACCT_GROUP_ID=${!override_var}
else
_ACCT_GROUP_ID=${ACCT_GROUP_ID}
fi
insinto /usr/lib/sysusers.d
newins - ${CATEGORY}-${ACCT_GROUP_NAME}.conf < <(
printf "g\t%q\t%q\n" \
"${ACCT_GROUP_NAME}" \
"${_ACCT_GROUP_ID/#-*/-}"
)
}
# @FUNCTION: acct-group_pkg_preinst # @FUNCTION: acct-group_pkg_preinst
# @DESCRIPTION: # @DESCRIPTION:
# Creates the group if it does not exist yet. # Creates the group if it does not exist yet.
@ -123,7 +157,7 @@ acct-group_pkg_preinst() {
debug-print-function ${FUNCNAME} "${@}" debug-print-function ${FUNCNAME} "${@}"
enewgroup ${ACCT_GROUP_ENFORCE_ID:+-F} "${ACCT_GROUP_NAME}" \ enewgroup ${ACCT_GROUP_ENFORCE_ID:+-F} "${ACCT_GROUP_NAME}" \
"${ACCT_GROUP_ID}" "${_ACCT_GROUP_ID}"
} }
fi fi