1 |
commit: ebdd8464a4a6072da5f2fd6775ae062a080c3776 |
2 |
Author: Benda Xu <heroxbd <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Nov 27 01:08:42 2017 +0000 |
4 |
Commit: Benda XU <heroxbd <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Nov 27 01:08:42 2017 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/android.git/commit/?id=ebdd8464 |
7 |
|
8 |
db.eclass, user.eclass: upstreamed. |
9 |
|
10 |
eclass/db.eclass | 210 ------------------------ |
11 |
eclass/user.eclass | 474 ----------------------------------------------------- |
12 |
2 files changed, 684 deletions(-) |
13 |
|
14 |
diff --git a/eclass/db.eclass b/eclass/db.eclass |
15 |
deleted file mode 100644 |
16 |
index f7070d4..0000000 |
17 |
--- a/eclass/db.eclass |
18 |
+++ /dev/null |
19 |
@@ -1,210 +0,0 @@ |
20 |
-# Copyright 1999-2013 Gentoo Foundation |
21 |
-# Distributed under the terms of the GNU General Public License v2 |
22 |
-# $Header: /var/cvsroot/gentoo-x86/eclass/db.eclass,v 1.49 2013/07/21 09:23:45 pacho Exp $ |
23 |
-# This is a common location for functions used in the sys-libs/db ebuilds |
24 |
-# |
25 |
-# Bugs: maintainer-needed@g.o |
26 |
- |
27 |
-inherit eutils multilib |
28 |
- |
29 |
-IUSE="doc test examples" |
30 |
- |
31 |
-EXPORT_FUNCTIONS src_test |
32 |
- |
33 |
-DEPEND="test? ( >=dev-lang/tcl-8.4 )" |
34 |
- |
35 |
-RDEPEND="" |
36 |
- |
37 |
-db_fix_so() { |
38 |
- has "${EAPI:-0}" 0 1 2 && ! use prefix && EROOT="${ROOT}" |
39 |
- LIB="${EROOT}/usr/$(get_libdir)" |
40 |
- |
41 |
- cd "${LIB}" |
42 |
- |
43 |
- # first clean up old symlinks |
44 |
- find "${LIB}" -maxdepth 1 -type l -name 'libdb[1_-]*'"$(get_libname)" -delete |
45 |
- find "${LIB}" -maxdepth 1 -type l -name 'libdb[1_-]*'"$(get_libname "[23]")" -delete |
46 |
- find "${LIB}" -maxdepth 1 -type l -name "libdb$(get_libname)" -delete #519364 |
47 |
- find "${LIB}" -maxdepth 1 -type l -name "libdb$(get_libname "[23]")" -delete #519364 |
48 |
- find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*a' -delete |
49 |
- |
50 |
- # now rebuild all the correct ones |
51 |
- for ext in so a dylib sl; do |
52 |
- for name in libdb libdb_{cxx,tcl,java,sql,stl}; do |
53 |
- target=`find . -maxdepth 1 -type f -name "${name}-*.${ext}" |sort -n |tail -n 1` |
54 |
- [ -n "${target}" ] || continue; |
55 |
- case ${CHOST} in |
56 |
- *-aix*) |
57 |
- aixdll --merge-runtime \ |
58 |
- --keepdir=false \ |
59 |
- --target="${name}.${ext}" \ |
60 |
- --current="${target}" \ |
61 |
- `find . -maxdepth 1 -type f -name "${name}-*.${ext}"` |
62 |
- ;; |
63 |
- *) |
64 |
- ln -sf ${target//.\//} ${name}.${ext} |
65 |
- ;; |
66 |
- esac; |
67 |
- done; |
68 |
- done; |
69 |
- |
70 |
- # db[23] gets some extra-special stuff |
71 |
- if [ -f libdb1$(get_libname 2) ]; then |
72 |
- ln -sf libdb1$(get_libname 2) libdb$(get_libname 2) |
73 |
- ln -sf libdb1$(get_libname 2) libdb1$(get_libname) |
74 |
- ln -sf libdb1$(get_libname 2) libdb-1$(get_libame) |
75 |
- fi |
76 |
- # what do we do if we ever get 3.3 ? |
77 |
- for i in libdb libdb_{cxx,tcl,java,sql,stl}; do |
78 |
- if [ -f $i-3$(get_libname 2) ]; then |
79 |
- ln -sf $i-3$(get_libname 2) $i-3$(get_libname) |
80 |
- ln -sf $i-3$(get_libname 2) $i$(get_libname 3) |
81 |
- fi |
82 |
- done |
83 |
- |
84 |
- # do the same for headers now |
85 |
- # but since there are only two of them, just overwrite them |
86 |
- cd "${EROOT}"/usr/include |
87 |
- target=`find . -maxdepth 1 -type d -name 'db[0-9]*' | sort -n |cut -d/ -f2- | tail -n1` |
88 |
- if [ -n "${target}" ] && [ -e "${target}/db.h" ] && ( ! [[ -e db.h ]] || [[ -h db.h ]] ); then |
89 |
- einfo "Creating db.h symlinks to ${target}" |
90 |
- ln -sf "${target}"/db.h . |
91 |
- ln -sf "${target}"/db_185.h . |
92 |
- elif [ ! -e "${target}/db.h" ]; then |
93 |
- if [ -n "${target}" ]; then |
94 |
- ewarn "Could not find ${target}/db.h" |
95 |
- elif [ -h db.h ]; then |
96 |
- einfo "Apparently you just removed the last instance of $PN. Removing the symlinks" |
97 |
- rm -f db.h db_185.h |
98 |
- fi |
99 |
- fi |
100 |
-} |
101 |
- |
102 |
-db_src_install_doc() { |
103 |
- has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}" |
104 |
- # not everybody wants this wad of documentation as it is primarily API docs |
105 |
- if use doc; then |
106 |
- dodir /usr/share/doc/${PF}/html |
107 |
- mv "${ED}"/usr/docs/* "${ED}"/usr/share/doc/${PF}/html/ |
108 |
- rm -rf "${ED}"/usr/docs |
109 |
- else |
110 |
- rm -rf "${ED}"/usr/docs |
111 |
- fi |
112 |
- |
113 |
- db_src_install_examples |
114 |
-} |
115 |
- |
116 |
-db_src_install_examples() { |
117 |
- has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}" |
118 |
- if use examples ; then |
119 |
- local langs="c cxx stl" |
120 |
- [[ "${IUSE/java}" != "${IUSE}" ]] \ |
121 |
- && use java \ |
122 |
- && langs="${langs} java" |
123 |
- for i in $langs ; do |
124 |
- destdir="/usr/share/doc/${PF}/" |
125 |
- src="${S}/../examples_${i}/" |
126 |
- if [ -f "${src}" ]; then |
127 |
- dodir "${destdir}" |
128 |
- cp -ra "${src}" "${ED}${destdir}/" |
129 |
- fi |
130 |
- done |
131 |
- fi |
132 |
-} |
133 |
- |
134 |
-db_src_install_usrbinslot() { |
135 |
- has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}" |
136 |
- # slot all program names to avoid overwriting |
137 |
- for fname in "${ED}"/usr/bin/db* |
138 |
- do |
139 |
- dn="$(dirname "${fname}")" |
140 |
- bn="$(basename "${fname}")" |
141 |
- bn="${bn/db/db${SLOT}}" |
142 |
- mv "${fname}" "${dn}/${bn}" || \ |
143 |
- die "Failed to rename ${fname} to ${dn}/${bn}" |
144 |
- done |
145 |
-} |
146 |
- |
147 |
-db_src_install_headerslot() { |
148 |
- has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}" |
149 |
- # install all headers in a slotted location |
150 |
- dodir /usr/include/db${SLOT} |
151 |
- mv "${ED}"/usr/include/*.h "${ED}"/usr/include/db${SLOT}/ |
152 |
-} |
153 |
- |
154 |
-db_src_install_usrlibcleanup() { |
155 |
- has "${EAPI:-0}" 0 1 2 && ! use prefix && ED="${D}" |
156 |
- LIB="${ED}/usr/$(get_libdir)" |
157 |
- # Clean out the symlinks so that they will not be recorded in the |
158 |
- # contents (bug #60732) |
159 |
- |
160 |
- if [ "${ED}" = "" ]; then |
161 |
- die "Calling clean_links while \$ED not defined" |
162 |
- fi |
163 |
- |
164 |
- if [ -e "${LIB}"/libdb.a ] && [ ! -e "${LIB}"/libdb-${SLOT}.a ]; then |
165 |
- einfo "Moving libdb.a to a versioned name" |
166 |
- mv "${LIB}/libdb.a" "${LIB}/libdb-${SLOT}.a" |
167 |
- fi |
168 |
- |
169 |
- if [ -e "${LIB}"/libdb_cxx.a ] && [ ! -e "${LIB}"/libdb_cxx-${SLOT}.a ]; then |
170 |
- einfo "Moving libdb_cxx.a to a versioned name" |
171 |
- mv "${LIB}/libdb_cxx.a" "${LIB}/libdb_cxx-${SLOT}.a" |
172 |
- fi |
173 |
- |
174 |
- find "${LIB}" -maxdepth 1 -type l -name 'libdb[1_-]*'"$(get_libname)" -delete |
175 |
- find "${LIB}" -maxdepth 1 -type l -name 'libdb[1_-]*'"$(get_libname "[23]")" -delete |
176 |
- find "${LIB}" -maxdepth 1 -type l -name "libdb$(get_libname)" -delete #519364 |
177 |
- find "${LIB}" -maxdepth 1 -type l -name "libdb$(get_libname "[23]")" -delete #519364 |
178 |
- einfo "removing unversioned static archives" |
179 |
- find "${LIB}" -maxdepth 1 -type l -name 'libdb[1._-]*a' -delete |
180 |
- |
181 |
- rm -f \ |
182 |
- "${ED}"/usr/include/{db,db_185}.h \ |
183 |
- "${LIB}"/libdb{,_{cxx,sql,stl,java,tcl}}.a |
184 |
-} |
185 |
- |
186 |
-db_src_test() { |
187 |
- if [[ $UID -eq 0 ]]; then |
188 |
- M="You must run the testsuite as non-root, skipping" |
189 |
- ewarn "${M}" |
190 |
- elog "${M}" |
191 |
- return 0 |
192 |
- fi |
193 |
- |
194 |
- if use tcl; then |
195 |
- einfo "Running sys-libs/db testsuite" |
196 |
- ewarn "This can take 6+ hours on modern machines" |
197 |
- # Fix stuff that fails with relative paths, and upstream moving files |
198 |
- # around... |
199 |
- local test_parallel='' |
200 |
- for t in \ |
201 |
- "${S}"/test/parallel.tcl \ |
202 |
- "${S}"/../test/parallel.tcl \ |
203 |
- "${S}"/test/tcl/parallel.tcl \ |
204 |
- "${S}"/../test/tcl/parallel.tcl \ |
205 |
- ; do |
206 |
- [[ -f "${t}" ]] && test_parallel="${t}" && break |
207 |
- done |
208 |
- |
209 |
- sed -ri \ |
210 |
- -e '/regsub .test_path ./s,(regsub),#\1,g' \ |
211 |
- -e '/regsub .src_root ./s,(regsub),#\1,g' \ |
212 |
- -e '/regsub .tcl_utils ./s,(regsub),#\1,g' \ |
213 |
- "${test_parallel}" |
214 |
- cd "${S}" |
215 |
- for t in \ |
216 |
- ../test/test.tcl \ |
217 |
- ../test/tcl/test.tcl \ |
218 |
- ; do |
219 |
- [[ -f "${t}" ]] && testbase="${t}" && break |
220 |
- done |
221 |
- echo "source ${t}" > testrunner.tcl |
222 |
- echo "run_parallel $(makeopts_jobs) run_std" >> testrunner.tcl |
223 |
- |
224 |
- tclsh testrunner.tcl |
225 |
- egrep -qs '^FAIL' ALL.OUT* && die "Some tests failed, please see ${S}/ALL.OUT*" |
226 |
- else |
227 |
- eerror "You must have USE=tcl to run the sys-libs/db testsuite." |
228 |
- fi |
229 |
-} |
230 |
|
231 |
diff --git a/eclass/user.eclass b/eclass/user.eclass |
232 |
deleted file mode 100644 |
233 |
index 9fddbbb..0000000 |
234 |
--- a/eclass/user.eclass |
235 |
+++ /dev/null |
236 |
@@ -1,474 +0,0 @@ |
237 |
-# Copyright 1999-2014 Gentoo Foundation |
238 |
-# Distributed under the terms of the GNU General Public License v2 |
239 |
-# $Id$ |
240 |
- |
241 |
-# @ECLASS: user.eclass |
242 |
-# @MAINTAINER: |
243 |
-# base-system@g.o (Linux) |
244 |
-# Joe Jezak <josejx@×××××.com> (OS X) |
245 |
-# usata@g.o (OS X) |
246 |
-# Aaron Walker <ka0ttic@g.o> (FreeBSD) |
247 |
-# @BLURB: user management in ebuilds |
248 |
-# @DESCRIPTION: |
249 |
-# The user eclass contains a suite of functions that allow ebuilds |
250 |
-# to quickly make sure users in the installed system are sane. |
251 |
- |
252 |
-if [[ -z ${_USER_ECLASS} ]]; then |
253 |
-_USER_ECLASS=1 |
254 |
- |
255 |
-# @FUNCTION: _assert_pkg_ebuild_phase |
256 |
-# @INTERNAL |
257 |
-# @USAGE: <calling func name> |
258 |
-_assert_pkg_ebuild_phase() { |
259 |
- case ${EBUILD_PHASE} in |
260 |
- setup|preinst|postinst) ;; |
261 |
- *) |
262 |
- eerror "'$1()' called from '${EBUILD_PHASE}' phase which is not OK:" |
263 |
- eerror "You may only call from pkg_{setup,preinst,postinst} functions." |
264 |
- eerror "Package fails at QA and at life. Please file a bug." |
265 |
- die "Bad package! $1 is only for use in some pkg_* functions!" |
266 |
- esac |
267 |
-} |
268 |
- |
269 |
-# @FUNCTION: egetent |
270 |
-# @USAGE: <database> <key> |
271 |
-# @DESCRIPTION: |
272 |
-# Small wrapper for getent (Linux), nidump (< Mac OS X 10.5), |
273 |
-# dscl (Mac OS X 10.5), and pw (FreeBSD) used in enewuser()/enewgroup(). |
274 |
-# |
275 |
-# Supported databases: group passwd |
276 |
-egetent() { |
277 |
- local db=$1 key=$2 |
278 |
- |
279 |
- [[ $# -ge 3 ]] && die "usage: egetent <database> <key>" |
280 |
- |
281 |
- case ${db} in |
282 |
- passwd|group) ;; |
283 |
- *) die "sorry, database '${db}' not yet supported; file a bug" ;; |
284 |
- esac |
285 |
- |
286 |
- case ${CHOST} in |
287 |
- *-darwin[678]) |
288 |
- case ${key} in |
289 |
- *[!0-9]*) # Non numeric |
290 |
- nidump ${db} . | awk -F: "(\$1 ~ /^${key}\$/) {print;exit;}" |
291 |
- ;; |
292 |
- *) # Numeric |
293 |
- nidump ${db} . | awk -F: "(\$3 == ${key}) {print;exit;}" |
294 |
- ;; |
295 |
- esac |
296 |
- ;; |
297 |
- *-darwin*) |
298 |
- local mykey |
299 |
- case ${db} in |
300 |
- passwd) db="Users" mykey="UniqueID" ;; |
301 |
- group) db="Groups" mykey="PrimaryGroupID" ;; |
302 |
- esac |
303 |
- |
304 |
- case ${key} in |
305 |
- *[!0-9]*) # Non numeric |
306 |
- dscl . -read /${db}/${key} 2>/dev/null |grep RecordName |
307 |
- ;; |
308 |
- *) # Numeric |
309 |
- dscl . -search /${db} ${mykey} ${key} 2>/dev/null |
310 |
- ;; |
311 |
- esac |
312 |
- ;; |
313 |
- *-freebsd*|*-dragonfly*) |
314 |
- case ${db} in |
315 |
- passwd) db="user" ;; |
316 |
- *) ;; |
317 |
- esac |
318 |
- |
319 |
- # lookup by uid/gid |
320 |
- local opts |
321 |
- if [[ ${key} == [[:digit:]]* ]] ; then |
322 |
- [[ ${db} == "user" ]] && opts="-u" || opts="-g" |
323 |
- fi |
324 |
- |
325 |
- pw show ${db} ${opts} "${key}" -q |
326 |
- ;; |
327 |
- *-netbsd*|*-openbsd*) |
328 |
- grep "${key}:\*:" /etc/${db} |
329 |
- ;; |
330 |
- *) |
331 |
- # ignore output if nscd doesn't exist, or we're not running as root |
332 |
- nscd -i "${db}" 2>/dev/null |
333 |
- getent "${db}" "${key}" |
334 |
- ;; |
335 |
- esac |
336 |
-} |
337 |
- |
338 |
-# @FUNCTION: enewuser |
339 |
-# @USAGE: <user> [uid] [shell] [homedir] [groups] |
340 |
-# @DESCRIPTION: |
341 |
-# Same as enewgroup, you are not required to understand how to properly add |
342 |
-# a user to the system. The only required parameter is the username. |
343 |
-# Default uid is (pass -1 for this) next available, default shell is |
344 |
-# /bin/false, default homedir is /dev/null, and there are no default groups. |
345 |
-enewuser() { |
346 |
- if [[ ${EUID} != 0 ]] ; then |
347 |
- einfo "Donot have enough privilege to execute ${FUNCNAME[0]}" |
348 |
- return 0 |
349 |
- fi |
350 |
- _assert_pkg_ebuild_phase ${FUNCNAME} |
351 |
- |
352 |
- # get the username |
353 |
- local euser=$1; shift |
354 |
- if [[ -z ${euser} ]] ; then |
355 |
- eerror "No username specified !" |
356 |
- die "Cannot call enewuser without a username" |
357 |
- fi |
358 |
- |
359 |
- # lets see if the username already exists |
360 |
- if [[ -n $(egetent passwd "${euser}") ]] ; then |
361 |
- return 0 |
362 |
- fi |
363 |
- einfo "Adding user '${euser}' to your system ..." |
364 |
- |
365 |
- # options to pass to useradd |
366 |
- local opts=() |
367 |
- |
368 |
- # handle uid |
369 |
- local euid=$1; shift |
370 |
- if [[ -n ${euid} && ${euid} != -1 ]] ; then |
371 |
- if [[ ${euid} -gt 0 ]] ; then |
372 |
- if [[ -n $(egetent passwd ${euid}) ]] ; then |
373 |
- euid="next" |
374 |
- fi |
375 |
- else |
376 |
- eerror "Userid given but is not greater than 0 !" |
377 |
- die "${euid} is not a valid UID" |
378 |
- fi |
379 |
- else |
380 |
- euid="next" |
381 |
- fi |
382 |
- if [[ ${euid} == "next" ]] ; then |
383 |
- for ((euid = 101; euid <= 999; euid++)); do |
384 |
- [[ -z $(egetent passwd ${euid}) ]] && break |
385 |
- done |
386 |
- fi |
387 |
- opts+=( -u ${euid} ) |
388 |
- einfo " - Userid: ${euid}" |
389 |
- |
390 |
- # handle shell |
391 |
- local eshell=$1; shift |
392 |
- if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then |
393 |
- if [[ ! -e ${ROOT}${eshell} ]] ; then |
394 |
- eerror "A shell was specified but it does not exist !" |
395 |
- die "${eshell} does not exist in ${ROOT}" |
396 |
- fi |
397 |
- if [[ ${eshell} == */false || ${eshell} == */nologin ]] ; then |
398 |
- eerror "Do not specify ${eshell} yourself, use -1" |
399 |
- die "Pass '-1' as the shell parameter" |
400 |
- fi |
401 |
- else |
402 |
- for eshell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do |
403 |
- [[ -x ${ROOT}${eshell} ]] && break |
404 |
- done |
405 |
- |
406 |
- if [[ ${eshell} == "/dev/null" ]] ; then |
407 |
- eerror "Unable to identify the shell to use, proceeding with userland default." |
408 |
- case ${USERLAND} in |
409 |
- GNU) eshell="/bin/false" ;; |
410 |
- BSD) eshell="/sbin/nologin" ;; |
411 |
- Darwin) eshell="/usr/sbin/nologin" ;; |
412 |
- *) die "Unable to identify the default shell for userland ${USERLAND}" |
413 |
- esac |
414 |
- fi |
415 |
- fi |
416 |
- einfo " - Shell: ${eshell}" |
417 |
- opts+=( -s "${eshell}" ) |
418 |
- |
419 |
- # handle homedir |
420 |
- local ehome=$1; shift |
421 |
- if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then |
422 |
- ehome="/dev/null" |
423 |
- fi |
424 |
- einfo " - Home: ${ehome}" |
425 |
- opts+=( -d "${ehome}" ) |
426 |
- |
427 |
- # handle groups |
428 |
- local egroups=$1; shift |
429 |
- local g egroups_arr |
430 |
- IFS="," read -r -a egroups_arr <<<"${egroups}" |
431 |
- shift |
432 |
- if [[ ${#egroups_arr[@]} -gt 0 ]] ; then |
433 |
- local defgroup exgroups |
434 |
- for g in "${egroups_arr[@]}" ; do |
435 |
- if [[ -z $(egetent group "${g}") ]] ; then |
436 |
- eerror "You must add group ${g} to the system first" |
437 |
- die "${g} is not a valid GID" |
438 |
- fi |
439 |
- if [[ -z ${defgroup} ]] ; then |
440 |
- defgroup=${g} |
441 |
- else |
442 |
- exgroups+=",${g}" |
443 |
- fi |
444 |
- done |
445 |
- opts+=( -g "${defgroup}" ) |
446 |
- if [[ ! -z ${exgroups} ]] ; then |
447 |
- opts+=( -G "${exgroups:1}" ) |
448 |
- fi |
449 |
- fi |
450 |
- einfo " - Groups: ${egroups:-(none)}" |
451 |
- |
452 |
- # handle extra args |
453 |
- if [[ $# -gt 0 ]] ; then |
454 |
- die "extra arguments no longer supported; please file a bug" |
455 |
- else |
456 |
- local comment="added by portage for ${PN}" |
457 |
- opts+=( -c "${comment}" ) |
458 |
- einfo " - GECOS: ${comment}" |
459 |
- fi |
460 |
- |
461 |
- # add the user |
462 |
- case ${CHOST} in |
463 |
- *-darwin*) |
464 |
- ### Make the user |
465 |
- dscl . create "/users/${euser}" uid ${euid} |
466 |
- dscl . create "/users/${euser}" shell "${eshell}" |
467 |
- dscl . create "/users/${euser}" home "${ehome}" |
468 |
- dscl . create "/users/${euser}" realname "added by portage for ${PN}" |
469 |
- ### Add the user to the groups specified |
470 |
- for g in "${egroups_arr[@]}" ; do |
471 |
- dscl . merge "/groups/${g}" users "${euser}" |
472 |
- done |
473 |
- ;; |
474 |
- |
475 |
- *-freebsd*|*-dragonfly*) |
476 |
- pw useradd "${euser}" "${opts[@]}" || die |
477 |
- ;; |
478 |
- |
479 |
- *-netbsd*) |
480 |
- useradd "${opts[@]}" "${euser}" || die |
481 |
- ;; |
482 |
- |
483 |
- *-openbsd*) |
484 |
- # all ops the same, except the -g vs -g/-G ... |
485 |
- useradd -u ${euid} -s "${eshell}" \ |
486 |
- -d "${ehome}" -g "${egroups}" "${euser}" || die |
487 |
- ;; |
488 |
- |
489 |
- *) |
490 |
- useradd -r "${opts[@]}" "${euser}" || die |
491 |
- ;; |
492 |
- esac |
493 |
- |
494 |
- if [[ ! -e ${ROOT}/${ehome} ]] ; then |
495 |
- einfo " - Creating ${ehome} in ${ROOT}" |
496 |
- mkdir -p "${ROOT}/${ehome}" |
497 |
- chown "${euser}" "${ROOT}/${ehome}" |
498 |
- chmod 755 "${ROOT}/${ehome}" |
499 |
- fi |
500 |
-} |
501 |
- |
502 |
-# @FUNCTION: enewgroup |
503 |
-# @USAGE: <group> [gid] |
504 |
-# @DESCRIPTION: |
505 |
-# This function does not require you to understand how to properly add a |
506 |
-# group to the system. Just give it a group name to add and enewgroup will |
507 |
-# do the rest. You may specify the gid for the group or allow the group to |
508 |
-# allocate the next available one. |
509 |
-enewgroup() { |
510 |
- if [[ ${EUID} != 0 ]] ; then |
511 |
- einfo "Donot have enough privilege to execute ${FUNCNAME[0]}" |
512 |
- return 0 |
513 |
- fi |
514 |
- _assert_pkg_ebuild_phase ${FUNCNAME} |
515 |
- |
516 |
- # get the group |
517 |
- local egroup=$1; shift |
518 |
- if [[ -z ${egroup} ]] ; then |
519 |
- eerror "No group specified !" |
520 |
- die "Cannot call enewgroup without a group" |
521 |
- fi |
522 |
- |
523 |
- # see if group already exists |
524 |
- if [[ -n $(egetent group "${egroup}") ]] ; then |
525 |
- return 0 |
526 |
- fi |
527 |
- einfo "Adding group '${egroup}' to your system ..." |
528 |
- |
529 |
- # handle gid |
530 |
- local egid=$1; shift |
531 |
- if [[ ! -z ${egid} ]] ; then |
532 |
- if [[ ${egid} -gt 0 ]] ; then |
533 |
- if [[ -n $(egetent group ${egid}) ]] ; then |
534 |
- egid="next available; requested gid taken" |
535 |
- fi |
536 |
- else |
537 |
- eerror "Groupid given but is not greater than 0 !" |
538 |
- die "${egid} is not a valid GID" |
539 |
- fi |
540 |
- else |
541 |
- egid="next available" |
542 |
- fi |
543 |
- einfo " - Groupid: ${egid}" |
544 |
- |
545 |
- # handle extra |
546 |
- if [[ $# -gt 0 ]] ; then |
547 |
- die "extra arguments no longer supported; please file a bug" |
548 |
- fi |
549 |
- |
550 |
- # Some targets need to find the next available GID manually |
551 |
- _enewgroup_next_gid() { |
552 |
- if [[ ${egid} == *[!0-9]* ]] ; then |
553 |
- # Non numeric |
554 |
- for ((egid = 101; egid <= 999; egid++)) ; do |
555 |
- [[ -z $(egetent group ${egid}) ]] && break |
556 |
- done |
557 |
- fi |
558 |
- } |
559 |
- |
560 |
- # add the group |
561 |
- case ${CHOST} in |
562 |
- *-darwin*) |
563 |
- _enewgroup_next_gid |
564 |
- dscl . create "/groups/${egroup}" gid ${egid} |
565 |
- dscl . create "/groups/${egroup}" passwd '*' |
566 |
- ;; |
567 |
- |
568 |
- *-freebsd*|*-dragonfly*) |
569 |
- _enewgroup_next_gid |
570 |
- pw groupadd "${egroup}" -g ${egid} || die |
571 |
- ;; |
572 |
- |
573 |
- *-netbsd*) |
574 |
- _enewgroup_next_gid |
575 |
- groupadd -g ${egid} "${egroup}" || die |
576 |
- ;; |
577 |
- |
578 |
- *) |
579 |
- local opts |
580 |
- if [[ ${egid} == *[!0-9]* ]] ; then |
581 |
- # Non numeric; let groupadd figure out a GID for us |
582 |
- opts="" |
583 |
- else |
584 |
- opts="-g ${egid}" |
585 |
- fi |
586 |
- # We specify -r so that we get a GID in the system range from login.defs |
587 |
- groupadd -r ${opts} "${egroup}" || die |
588 |
- ;; |
589 |
- esac |
590 |
-} |
591 |
- |
592 |
-# @FUNCTION: egethome |
593 |
-# @USAGE: <user> |
594 |
-# @DESCRIPTION: |
595 |
-# Gets the home directory for the specified user. |
596 |
-egethome() { |
597 |
- local pos |
598 |
- |
599 |
- [[ $# -eq 1 ]] || die "usage: egethome <user>" |
600 |
- |
601 |
- case ${CHOST} in |
602 |
- *-darwin*|*-freebsd*|*-dragonfly*) |
603 |
- pos=9 |
604 |
- ;; |
605 |
- *) # Linux, NetBSD, OpenBSD, etc... |
606 |
- pos=6 |
607 |
- ;; |
608 |
- esac |
609 |
- |
610 |
- egetent passwd "$1" | cut -d: -f${pos} |
611 |
-} |
612 |
- |
613 |
-# @FUNCTION: egetshell |
614 |
-# @USAGE: <user> |
615 |
-# @DESCRIPTION: |
616 |
-# Gets the shell for the specified user. |
617 |
-egetshell() { |
618 |
- local pos |
619 |
- |
620 |
- [[ $# -eq 1 ]] || die "usage: egetshell <user>" |
621 |
- |
622 |
- case ${CHOST} in |
623 |
- *-darwin*|*-freebsd*|*-dragonfly*) |
624 |
- pos=10 |
625 |
- ;; |
626 |
- *) # Linux, NetBSD, OpenBSD, etc... |
627 |
- pos=7 |
628 |
- ;; |
629 |
- esac |
630 |
- |
631 |
- egetent passwd "$1" | cut -d: -f${pos} |
632 |
-} |
633 |
- |
634 |
-# @FUNCTION: esethome |
635 |
-# @USAGE: <user> <homedir> |
636 |
-# @DESCRIPTION: |
637 |
-# Update the home directory in a platform-agnostic way. |
638 |
-# Required parameters is the username and the new home directory. |
639 |
-# Specify -1 if you want to set home to the enewuser default |
640 |
-# of /dev/null. |
641 |
-# If the new home directory does not exist, it is created. |
642 |
-# Any previously existing home directory is NOT moved. |
643 |
-esethome() { |
644 |
- _assert_pkg_ebuild_phase ${FUNCNAME} |
645 |
- |
646 |
- # get the username |
647 |
- local euser=$1; shift |
648 |
- if [[ -z ${euser} ]] ; then |
649 |
- eerror "No username specified !" |
650 |
- die "Cannot call esethome without a username" |
651 |
- fi |
652 |
- |
653 |
- # lets see if the username already exists |
654 |
- if [[ -z $(egetent passwd "${euser}") ]] ; then |
655 |
- ewarn "User does not exist, cannot set home dir -- skipping." |
656 |
- return 1 |
657 |
- fi |
658 |
- |
659 |
- # handle homedir |
660 |
- local ehome=$1; shift |
661 |
- if [[ -z ${ehome} ]] ; then |
662 |
- eerror "No home directory specified !" |
663 |
- die "Cannot call esethome without a home directory or '-1'" |
664 |
- fi |
665 |
- |
666 |
- if [[ ${ehome} == "-1" ]] ; then |
667 |
- ehome="/dev/null" |
668 |
- fi |
669 |
- |
670 |
- # exit with no message if home dir is up to date |
671 |
- if [[ $(egethome "${euser}") == ${ehome} ]]; then |
672 |
- return 0 |
673 |
- fi |
674 |
- |
675 |
- einfo "Updating home for user '${euser}' ..." |
676 |
- einfo " - Home: ${ehome}" |
677 |
- |
678 |
- # ensure home directory exists, otherwise update will fail |
679 |
- if [[ ! -e ${ROOT}/${ehome} ]] ; then |
680 |
- einfo " - Creating ${ehome} in ${ROOT}" |
681 |
- mkdir -p "${ROOT}/${ehome}" |
682 |
- chown "${euser}" "${ROOT}/${ehome}" |
683 |
- chmod 755 "${ROOT}/${ehome}" |
684 |
- fi |
685 |
- |
686 |
- # update the home directory |
687 |
- case ${CHOST} in |
688 |
- *-darwin*) |
689 |
- dscl . change "/users/${euser}" home "${ehome}" |
690 |
- ;; |
691 |
- |
692 |
- *-freebsd*|*-dragonfly*) |
693 |
- pw usermod "${euser}" -d "${ehome}" && return 0 |
694 |
- [[ $? == 8 ]] && eerror "${euser} is in use, cannot update home" |
695 |
- eerror "There was an error when attempting to update the home directory for ${euser}" |
696 |
- eerror "Please update it manually on your system:" |
697 |
- eerror "\t pw usermod \"${euser}\" -d \"${ehome}\"" |
698 |
- ;; |
699 |
- |
700 |
- *) |
701 |
- usermod -d "${ehome}" "${euser}" && return 0 |
702 |
- [[ $? == 8 ]] && eerror "${euser} is in use, cannot update home" |
703 |
- eerror "There was an error when attempting to update the home directory for ${euser}" |
704 |
- eerror "Please update it manually on your system (as root):" |
705 |
- eerror "\t usermod -d \"${ehome}\" \"${euser}\"" |
706 |
- ;; |
707 |
- esac |
708 |
-} |
709 |
- |
710 |
-fi |