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