eclass/user: Sync with gentoo

It's from gentoo commit cbe262b6c9a662b80b259562aa5949623ab9247a.
This commit is contained in:
Krzesimir Nowak 2022-03-09 20:17:04 +01:00
parent 2393c4a1d9
commit 2489a9690d

View File

@ -1,15 +1,31 @@
# Copyright 1999-2020 Gentoo Authors # Copyright 1999-2022 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: user.eclass # @ECLASS: user.eclass
# @MAINTAINER: # @MAINTAINER:
# base-system@gentoo.org (Linux) # base-system@gentoo.org (Linux)
# Michał Górny <mgorny@gentoo.org> (NetBSD) # Michał Górny <mgorny@gentoo.org> (NetBSD)
# @SUPPORTED_EAPIS: 6 7 8
# @BLURB: user management in ebuilds # @BLURB: user management in ebuilds
# @DEPRECATED: acct-user/acct-group packages
# @DESCRIPTION: # @DESCRIPTION:
# The user eclass contains a suite of functions that allow ebuilds # The user eclass contains a suite of functions that allow ebuilds
# to quickly make sure users in the installed system are sane. # to quickly make sure users in the installed system are sane.
case ${EAPI} in
6|7) ;;
8)
if [[ ${CATEGORY} != acct-* ]]; then
eerror "In EAPI ${EAPI}, packages must not inherit user.eclass"
eerror "unless they are in the acct-user or acct-group category."
eerror "Migrate your package to GLEP 81 user/group management,"
eerror "or inherit user-info if you need only the query functions."
die "Invalid \"inherit user\" in EAPI ${EAPI}"
fi
;;
*) die "${ECLASS}: EAPI ${EAPI:-0} not supported" ;;
esac
if [[ -z ${_USER_ECLASS} ]]; then if [[ -z ${_USER_ECLASS} ]]; then
_USER_ECLASS=1 _USER_ECLASS=1
@ -18,14 +34,16 @@ inherit user-info
# @FUNCTION: _assert_pkg_ebuild_phase # @FUNCTION: _assert_pkg_ebuild_phase
# @INTERNAL # @INTERNAL
# @USAGE: <calling func name> # @USAGE: <calling func name>
# @DESCRIPTION:
# Raises an alert if the phase is not suitable for user.eclass usage.
_assert_pkg_ebuild_phase() { _assert_pkg_ebuild_phase() {
case ${EBUILD_PHASE} in case ${EBUILD_PHASE} in
setup|preinst|postinst|prerm|postrm) ;; setup|preinst|postinst|prerm|postrm) ;;
*) *)
eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:" eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:"
eerror "You may only call from pkg_{setup,{pre,post}{inst,rm}} functions." eerror "You may only call from pkg_{setup,{pre,post}{inst,rm}} functions."
eerror "Package fails at QA and at life. Please file a bug." eerror "Package has serious QA issues. Please file a bug."
die "Bad package! $1 is only for use in some pkg_* functions!" die "Bad package! ${1} is only for use in some pkg_* functions!"
esac esac
} }
@ -74,8 +92,8 @@ enewuser() {
_assert_pkg_ebuild_phase ${FUNCNAME} _assert_pkg_ebuild_phase ${FUNCNAME}
local create_home=1 force_uid= local create_home=1 force_uid=
while [[ $1 == -* ]]; do while [[ ${1} == -* ]]; do
case $1 in case ${1} in
-F) force_uid=1;; -F) force_uid=1;;
-M) create_home=;; -M) create_home=;;
*) die "${FUNCNAME}: invalid option ${1}";; *) die "${FUNCNAME}: invalid option ${1}";;
@ -84,9 +102,9 @@ enewuser() {
done done
# get the username # get the username
local euser=$1; shift local euser=${1}; shift
if [[ -z ${euser} ]] ; then if [[ -z ${euser} ]] ; then
eerror "No username specified !" eerror "No username specified!"
die "Cannot call enewuser without a username" die "Cannot call enewuser without a username"
fi fi
@ -100,7 +118,7 @@ enewuser() {
local opts=() local opts=()
# handle uid # handle uid
local euid=$1; shift local euid=${1}; shift
if [[ -n ${euid} && ${euid} != -1 ]] ; then if [[ -n ${euid} && ${euid} != -1 ]] ; then
if [[ ${euid} -gt 0 ]] ; then if [[ ${euid} -gt 0 ]] ; then
if [[ -n $(egetent passwd ${euid}) ]] ; then if [[ -n $(egetent passwd ${euid}) ]] ; then
@ -108,7 +126,7 @@ enewuser() {
euid="next" euid="next"
fi fi
else else
eerror "Userid given but is not greater than 0 !" eerror "Userid given but is not greater than 0!"
die "${euid} is not a valid UID" die "${euid} is not a valid UID"
fi fi
else else
@ -125,10 +143,10 @@ enewuser() {
elog " - Userid: ${euid}" elog " - Userid: ${euid}"
# handle shell # handle shell
local eshell=$1; shift local eshell=${1}; shift
if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then
if [[ ! -e ${ROOT}${eshell} ]] ; then if [[ ! -e ${ROOT}${eshell} ]] ; then
eerror "A shell was specified but it does not exist !" eerror "A shell was specified but it does not exist!"
die "${eshell} does not exist in ${ROOT}" die "${eshell} does not exist in ${ROOT}"
fi fi
if [[ ${eshell} == */false || ${eshell} == */nologin ]] ; then if [[ ${eshell} == */false || ${eshell} == */nologin ]] ; then
@ -142,7 +160,7 @@ enewuser() {
opts+=( -s "${eshell}" ) opts+=( -s "${eshell}" )
# handle homedir # handle homedir
local ehome=$1; shift local ehome=${1}; shift
if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then
ehome="/dev/null" ehome="/dev/null"
fi fi
@ -150,7 +168,7 @@ enewuser() {
opts+=( -d "${ehome}" ) opts+=( -d "${ehome}" )
# handle groups # handle groups
local egroups=$1; shift local egroups=${1}; shift
local g egroups_arr local g egroups_arr
IFS="," read -r -a egroups_arr <<<"${egroups}" IFS="," read -r -a egroups_arr <<<"${egroups}"
if [[ ${#egroups_arr[@]} -gt 0 ]] ; then if [[ ${#egroups_arr[@]} -gt 0 ]] ; then
@ -229,8 +247,8 @@ enewgroup() {
_assert_pkg_ebuild_phase ${FUNCNAME} _assert_pkg_ebuild_phase ${FUNCNAME}
local force_gid= local force_gid=
while [[ $1 == -* ]]; do while [[ ${1} == -* ]]; do
case $1 in case ${1} in
-F) force_gid=1;; -F) force_gid=1;;
*) die "${FUNCNAME}: invalid option ${1}";; *) die "${FUNCNAME}: invalid option ${1}";;
esac esac
@ -238,9 +256,9 @@ enewgroup() {
done done
# get the group # get the group
local egroup=$1; shift local egroup=${1}; shift
if [[ -z ${egroup} ]] ; then if [[ -z ${egroup} ]] ; then
eerror "No group specified !" eerror "No group specified!"
die "Cannot call enewgroup without a group" die "Cannot call enewgroup without a group"
fi fi
@ -251,7 +269,7 @@ enewgroup() {
elog "Adding group '${egroup}' to your system ..." elog "Adding group '${egroup}' to your system ..."
# handle gid # handle gid
local egid=$1; shift local egid=${1}; shift
if [[ -n ${egid} && ${egid} != -1 ]] ; then if [[ -n ${egid} && ${egid} != -1 ]] ; then
if [[ ${egid} -gt 0 ]] ; then if [[ ${egid} -gt 0 ]] ; then
if [[ -n $(egetent group ${egid}) ]] ; then if [[ -n $(egetent group ${egid}) ]] ; then
@ -259,7 +277,7 @@ enewgroup() {
egid="next available; requested gid taken" egid="next available; requested gid taken"
fi fi
else else
eerror "Groupid given but is not greater than 0 !" eerror "Groupid given but is not greater than 0!"
die "${egid} is not a valid GID" die "${egid} is not a valid GID"
fi fi
else else
@ -323,9 +341,9 @@ esethome() {
_assert_pkg_ebuild_phase ${FUNCNAME} _assert_pkg_ebuild_phase ${FUNCNAME}
# get the username # get the username
local euser=$1; shift local euser=${1}; shift
if [[ -z ${euser} ]] ; then if [[ -z ${euser} ]] ; then
eerror "No username specified !" eerror "No username specified!"
die "Cannot call esethome without a username" die "Cannot call esethome without a username"
fi fi
@ -336,9 +354,9 @@ esethome() {
fi fi
# handle homedir # handle homedir
local ehome=$1; shift local ehome=${1}; shift
if [[ -z ${ehome} ]] ; then if [[ -z ${ehome} ]] ; then
eerror "No home directory specified !" eerror "No home directory specified!"
die "Cannot call esethome without a home directory or '-1'" die "Cannot call esethome without a home directory or '-1'"
fi fi
@ -392,9 +410,9 @@ esetshell() {
_assert_pkg_ebuild_phase ${FUNCNAME} _assert_pkg_ebuild_phase ${FUNCNAME}
# get the username # get the username
local euser=$1; shift local euser=${1}; shift
if [[ -z ${euser} ]] ; then if [[ -z ${euser} ]] ; then
eerror "No username specified !" eerror "No username specified!"
die "Cannot call esetshell without a username" die "Cannot call esetshell without a username"
fi fi
@ -405,9 +423,9 @@ esetshell() {
fi fi
# handle shell # handle shell
local eshell=$1; shift local eshell=${1}; shift
if [[ -z ${eshell} ]] ; then if [[ -z ${eshell} ]] ; then
eerror "No shell specified !" eerror "No shell specified!"
die "Cannot call esetshell without a shell or '-1'" die "Cannot call esetshell without a shell or '-1'"
fi fi
@ -452,9 +470,9 @@ esetcomment() {
_assert_pkg_ebuild_phase ${FUNCNAME} _assert_pkg_ebuild_phase ${FUNCNAME}
# get the username # get the username
local euser=$1; shift local euser=${1}; shift
if [[ -z ${euser} ]] ; then if [[ -z ${euser} ]] ; then
eerror "No username specified !" eerror "No username specified!"
die "Cannot call esetcomment without a username" die "Cannot call esetcomment without a username"
fi fi
@ -465,9 +483,9 @@ esetcomment() {
fi fi
# handle comment # handle comment
local ecomment=$1; shift local ecomment=${1}; shift
if [[ -z ${ecomment} ]] ; then if [[ -z ${ecomment} ]] ; then
eerror "No comment specified !" eerror "No comment specified!"
die "Cannot call esetcomment without a comment" die "Cannot call esetcomment without a comment"
fi fi
@ -511,7 +529,7 @@ esetgroups() {
[[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <user> <groups>" [[ ${#} -eq 2 ]] || die "Usage: ${FUNCNAME} <user> <groups>"
# get the username # get the username
local euser=$1; shift local euser=${1}; shift
# lets see if the username already exists # lets see if the username already exists
if [[ -z $(egetent passwd "${euser}") ]] ; then if [[ -z $(egetent passwd "${euser}") ]] ; then
@ -520,7 +538,7 @@ esetgroups() {
fi fi
# handle group # handle group
local egroups=$1; shift local egroups=${1}; shift
local g egroups_arr=() local g egroups_arr=()
IFS="," read -r -a egroups_arr <<<"${egroups}" IFS="," read -r -a egroups_arr <<<"${egroups}"