mirror of
https://github.com/flatcar/scripts.git
synced 2025-08-17 01:46:58 +02:00
eclass/user: Sync with gentoo
It's from gentoo commit cbe262b6c9a662b80b259562aa5949623ab9247a.
This commit is contained in:
parent
2393c4a1d9
commit
2489a9690d
@ -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,7 +102,7 @@ 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"
|
||||||
@ -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
|
||||||
@ -125,7 +143,7 @@ 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!"
|
||||||
@ -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,7 +256,7 @@ 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"
|
||||||
@ -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
|
||||||
@ -323,7 +341,7 @@ 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"
|
||||||
@ -336,7 +354,7 @@ 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'"
|
||||||
@ -392,7 +410,7 @@ 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"
|
||||||
@ -405,7 +423,7 @@ 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'"
|
||||||
@ -452,7 +470,7 @@ 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"
|
||||||
@ -465,7 +483,7 @@ 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"
|
||||||
@ -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}"
|
||||||
|
Loading…
Reference in New Issue
Block a user