dev-cpp/pangomm: stable 2.42.1 for hppa, bug #717144
[gentoo.git] / eclass / acct-group.eclass
1 # Copyright 2019 Gentoo Authors
2 # Distributed under the terms of the GNU General Public License v2
3
4 # @ECLASS: acct-group.eclass
5 # @MAINTAINER:
6 # Michał Górny <mgorny@gentoo.org>
7 # @AUTHOR:
8 # Michael Orlitzky <mjo@gentoo.org>
9 # Michał Górny <mgorny@gentoo.org>
10 # @SUPPORTED_EAPIS: 7
11 # @BLURB: Eclass used to create and maintain a single group entry
12 # @DESCRIPTION:
13 # This eclass represents and creates a single group entry.  The name
14 # of the group is derived from ${PN}, while (preferred) GID needs to
15 # be specified via ACCT_GROUP_ID.  Packages (and users) needing the group
16 # in question should depend on the package providing it.
17 #
18 # Example:
19 # If your package needs group 'foo', you create 'acct-group/foo' package
20 # and add an ebuild with the following contents:
21 #
22 # @CODE
23 # EAPI=7
24 # inherit acct-group
25 # ACCT_GROUP_ID=200
26 # @CODE
27 #
28 # Then you add appropriate dependency to your package.  The dependency
29 # type(s) should be:
30 # - DEPEND (+ RDEPEND) if the group is already needed at build time,
31 # - RDEPEND if it is needed at install time (e.g. you 'fowners' files
32 #   in pkg_preinst) or run time.
33
34 if [[ -z ${_ACCT_GROUP_ECLASS} ]]; then
35 _ACCT_GROUP_ECLASS=1
36
37 case ${EAPI:-0} in
38         7) ;;
39         *) die "EAPI=${EAPI:-0} not supported";;
40 esac
41
42 inherit user
43
44 [[ ${CATEGORY} == acct-group ]] ||
45         die "Ebuild error: this eclass can be used only in acct-group category!"
46
47
48 # << Eclass variables >>
49
50 # @ECLASS-VARIABLE: ACCT_GROUP_NAME
51 # @INTERNAL
52 # @DESCRIPTION:
53 # The name of the group.  This is forced to ${PN} and the policy
54 # prohibits it from being changed.
55 ACCT_GROUP_NAME=${PN}
56 readonly ACCT_GROUP_NAME
57
58 # @ECLASS-VARIABLE: ACCT_GROUP_ID
59 # @REQUIRED
60 # @DESCRIPTION:
61 # Preferred GID for the new group.  This variable is obligatory, and its
62 # value must be unique across all group packages.
63 #
64 # Overlays should set this to -1 to dynamically allocate GID.  Using -1
65 # in ::gentoo is prohibited by policy.
66
67 # @ECLASS-VARIABLE: ACCT_GROUP_ENFORCE_ID
68 # @DESCRIPTION:
69 # If set to a non-null value, the eclass will require the group to have
70 # specified GID.  If the group already exists with another GID, or
71 # the GID is taken by another group, the install will fail.
72 : ${ACCT_GROUP_ENFORCE_ID:=}
73
74
75 # << Boilerplate ebuild variables >>
76 : ${DESCRIPTION:="System group: ${ACCT_GROUP_NAME}"}
77 : ${SLOT:=0}
78 : ${KEYWORDS:=alpha amd64 arm arm64 hppa ia64 m68k ~mips ppc ppc64 ~riscv s390 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}
79 S=${WORKDIR}
80
81
82 # << Phase functions >>
83 EXPORT_FUNCTIONS pkg_pretend pkg_preinst
84
85 # @FUNCTION: acct-group_pkg_pretend
86 # @DESCRIPTION:
87 # Performs sanity checks for correct eclass usage, and early-checks
88 # whether requested GID can be enforced.
89 acct-group_pkg_pretend() {
90         debug-print-function ${FUNCNAME} "${@}"
91
92         # verify ACCT_GROUP_ID
93         [[ -n ${ACCT_GROUP_ID} ]] || die "Ebuild error: ACCT_GROUP_ID must be set!"
94         [[ ${ACCT_GROUP_ID} -eq -1 ]] && return
95         [[ ${ACCT_GROUP_ID} -ge 0 ]] || die "Ebuild errors: ACCT_GROUP_ID=${ACCT_GROUP_ID} invalid!"
96
97         # check for ACCT_GROUP_ID collisions early
98         if [[ -n ${ACCT_GROUP_ENFORCE_ID} ]]; then
99                 local group_by_id=$(egetgroupname "${ACCT_GROUP_ID}")
100                 local group_by_name=$(egetent group "${ACCT_GROUP_NAME}")
101                 if [[ -n ${group_by_id} ]]; then
102                         if [[ ${group_by_id} != ${ACCT_GROUP_NAME} ]]; then
103                                 eerror "The required GID is already taken by another group."
104                                 eerror "  GID: ${ACCT_GROUP_ID}"
105                                 eerror "  needed for: ${ACCT_GROUP_NAME}"
106                                 eerror "  current group: ${group_by_id}"
107                                 die "GID ${ACCT_GROUP_ID} taken already"
108                         fi
109                 elif [[ -n ${group_by_name} ]]; then
110                         eerror "The requested group exists already with wrong GID."
111                         eerror "  groupname: ${ACCT_GROUP_NAME}"
112                         eerror "  requested GID: ${ACCT_GROUP_ID}"
113                         eerror "  current entry: ${group_by_name}"
114                         die "Group ${ACCT_GROUP_NAME} exists with wrong GID"
115                 fi
116         fi
117 }
118
119 # @FUNCTION: acct-group_pkg_preinst
120 # @DESCRIPTION:
121 # Creates the group if it does not exist yet.
122 acct-group_pkg_preinst() {
123         debug-print-function ${FUNCNAME} "${@}"
124
125         enewgroup ${ACCT_GROUP_ENFORCE_ID:+-F} "${ACCT_GROUP_NAME}" \
126                 "${ACCT_GROUP_ID}"
127 }
128
129 fi