| 1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
1 | # Copyright 1999-2003 Gentoo Technologies, Inc. |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.19 2003/02/16 20:12:26 azarah Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.24 2003/03/03 21:27:15 vapier Exp $ |
| 4 | # |
4 | # |
| 5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
5 | # Author: Martin Schlemmer <azarah@gentoo.org> |
| 6 | # |
6 | # |
| 7 | # This eclass is for general purpose functions that most ebuilds |
7 | # This eclass is for general purpose functions that most ebuilds |
| 8 | # have to implement themselves. |
8 | # have to implement themselves. |
| … | |
… | |
| 341 | ADMINPARAM="${ADMINPARAM/-j}" |
341 | ADMINPARAM="${ADMINPARAM/-j}" |
| 342 | fi |
342 | fi |
| 343 | |
343 | |
| 344 | export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" |
344 | export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" |
| 345 | |
345 | |
| 346 | if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" ] |
346 | if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ |
|
|
347 | "${ARCH}" = "arm" -o "${ARCH}" = "mips" ] |
| 347 | then |
348 | then |
| 348 | # x86 and hppa always has "processor" |
349 | # these archs will always have "[Pp]rocessor" |
| 349 | jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))" |
350 | jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" |
| 350 | |
351 | |
| 351 | elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] |
352 | elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ] |
| 352 | then |
353 | then |
| 353 | # sparc always has "ncpus active" |
354 | # sparc always has "ncpus active" |
| 354 | jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
355 | jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))" |
| … | |
… | |
| 370 | then |
371 | then |
| 371 | jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))" |
372 | jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))" |
| 372 | else |
373 | else |
| 373 | jobs=2 |
374 | jobs=2 |
| 374 | fi |
375 | fi |
| 375 | elif [ "${ARCH}" = "mips" ] |
|
|
| 376 | then |
|
|
| 377 | # mips always has "processor" |
|
|
| 378 | jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))" |
|
|
| 379 | |
|
|
| 380 | else |
376 | else |
| 381 | jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))" |
377 | jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))" |
| 382 | die "Unknown ARCH -- ${ARCH}!" |
378 | die "Unknown ARCH -- ${ARCH}!" |
| 383 | fi |
379 | fi |
| 384 | |
380 | |
| … | |
… | |
| 399 | export MAKEOPTS="${MAKEOPTS} -j${jobs}" |
395 | export MAKEOPTS="${MAKEOPTS} -j${jobs}" |
| 400 | fi |
396 | fi |
| 401 | fi |
397 | fi |
| 402 | } |
398 | } |
| 403 | |
399 | |
|
|
400 | # Simplify/standardize adding users to the system |
|
|
401 | # vapier@gentoo.org |
|
|
402 | # |
|
|
403 | # enewuser(username, uid, shell, homedir, groups, extra options) |
|
|
404 | # |
|
|
405 | # Default values if you do not specify any: |
|
|
406 | # username: REQUIRED ! |
|
|
407 | # uid: next available (see useradd(8)) |
|
|
408 | # shell: /bin/false |
|
|
409 | # homedir: /dev/null |
|
|
410 | # groups: none |
|
|
411 | # extra: comment of 'added by portage for ${PN}' |
|
|
412 | enewuser() { |
|
|
413 | # get the username |
|
|
414 | local euser="$1"; shift |
|
|
415 | if [ -z "${euser}" ] ; then |
|
|
416 | eerror "No username specified !" |
|
|
417 | die "Cannot call enewuser without a username" |
|
|
418 | fi |
|
|
419 | einfo "Adding user '${euser}' to your system ..." |
|
|
420 | |
|
|
421 | # setup a file for testing usernames/groups |
|
|
422 | local tmpfile="`mktemp -p ${T}`" |
|
|
423 | touch ${tmpfile} |
|
|
424 | chown ${euser} ${tmpfile} >& /dev/null |
|
|
425 | local realuser="`ls -l ${tmpfile} | awk '{print $3}'`" |
|
|
426 | |
|
|
427 | # see if user already exists |
|
|
428 | if [ "${euser}" == "${realuser}" ] ; then |
|
|
429 | einfo "${euser} already exists on your system :)" |
|
|
430 | return 0 |
|
|
431 | fi |
|
|
432 | |
|
|
433 | # options to pass to useradd |
|
|
434 | local opts="" |
|
|
435 | |
|
|
436 | # handle uid |
|
|
437 | local euid="$1"; shift |
|
|
438 | if [ ! -z "${euid}" ] ; then |
|
|
439 | if [ ${euid} -gt 0 ] ; then |
|
|
440 | opts="${opts} -u ${euid}" |
|
|
441 | else |
|
|
442 | eerror "Userid given but is not greater than 0 !" |
|
|
443 | die "${euid} is not a valid UID" |
|
|
444 | fi |
|
|
445 | else |
|
|
446 | euid="next available" |
|
|
447 | fi |
|
|
448 | einfo " - Userid: ${euid}" |
|
|
449 | |
|
|
450 | # handle shell |
|
|
451 | local eshell="$1"; shift |
|
|
452 | if [ ! -z "${eshell}" ] ; then |
|
|
453 | if [ ! -e ${eshell} ] ; then |
|
|
454 | eerror "A shell was specified but it does not exist !" |
|
|
455 | die "${eshell} does not exist" |
|
|
456 | fi |
|
|
457 | else |
|
|
458 | eshell=/bin/false |
|
|
459 | fi |
|
|
460 | einfo " - Shell: ${eshell}" |
|
|
461 | opts="${opts} -s ${eshell}" |
|
|
462 | |
|
|
463 | # handle homedir |
|
|
464 | local ehome="$1"; shift |
|
|
465 | if [ -z "${ehome}" ] ; then |
|
|
466 | ehome=/dev/null |
|
|
467 | fi |
|
|
468 | einfo " - Home: ${ehome}" |
|
|
469 | opts="${opts} -d ${ehome}" |
|
|
470 | |
|
|
471 | # handle groups |
|
|
472 | local egroups="$1"; shift |
|
|
473 | if [ ! -z "${egroups}" ] ; then |
|
|
474 | local realgroup |
|
|
475 | local oldifs="${IFS}" |
|
|
476 | export IFS="," |
|
|
477 | for g in ${egroups} ; do |
|
|
478 | chgrp ${g} ${tmpfile} >& /dev/null |
|
|
479 | realgroup="`ls -l ${tmpfile} | awk '{print $4}'`" |
|
|
480 | if [ "${g}" != "${realgroup}" ] ; then |
|
|
481 | eerror "You must add ${g} to the system first" |
|
|
482 | die "${g} is not a valid GID" |
|
|
483 | fi |
|
|
484 | done |
|
|
485 | export IFS="${oldifs}" |
|
|
486 | opts="${opts} -g ${egroups}" |
|
|
487 | else |
|
|
488 | egroups="(none)" |
|
|
489 | fi |
|
|
490 | einfo " - Groups: ${egroups}" |
|
|
491 | |
|
|
492 | # handle extra and add the user |
|
|
493 | local eextra="$@" |
|
|
494 | local oldsandbox="${oldsandbox}" |
|
|
495 | export SANDBOX_ON="0" |
|
|
496 | if [ -z "${eextra}" ] ; then |
|
|
497 | useradd ${opts} ${euser} \ |
|
|
498 | -c "added by portage for ${PN}" \ |
|
|
499 | || die "enewuser failed" |
|
|
500 | else |
|
|
501 | einfo " - Extra: ${eextra}" |
|
|
502 | useradd ${opts} ${euser} ${eextra} \ |
|
|
503 | || die "enewuser failed" |
|
|
504 | fi |
|
|
505 | export SANDBOX_ON="${oldsandbox}" |
|
|
506 | |
|
|
507 | if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then |
|
|
508 | einfo " - Creating ${ehome} in ${D}" |
|
|
509 | dodir ${ehome} |
|
|
510 | fperms ${euser} ${ehome} |
|
|
511 | fi |
|
|
512 | } |
|
|
513 | |
|
|
514 | # Simplify/standardize adding groups to the system |
|
|
515 | # vapier@gentoo.org |
|
|
516 | # |
|
|
517 | # enewgroup(group, gid) |
|
|
518 | # |
|
|
519 | # Default values if you do not specify any: |
|
|
520 | # groupname: REQUIRED ! |
|
|
521 | # gid: next available (see groupadd(8)) |
|
|
522 | # extra: none |
|
|
523 | enewgroup() { |
|
|
524 | # get the group |
|
|
525 | local egroup="$1"; shift |
|
|
526 | if [ -z "${egroup}" ] ; then |
|
|
527 | eerror "No group specified !" |
|
|
528 | die "Cannot call enewgroup without a group" |
|
|
529 | fi |
|
|
530 | einfo "Adding group '${egroup}' to your system ..." |
|
|
531 | |
|
|
532 | # setup a file for testing groupname |
|
|
533 | local tmpfile="`mktemp -p ${T}`" |
|
|
534 | touch ${tmpfile} |
|
|
535 | chgrp ${egroup} ${tmpfile} >& /dev/null |
|
|
536 | local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`" |
|
|
537 | |
|
|
538 | # see if group already exists |
|
|
539 | if [ "${egroup}" == "${realgroup}" ] ; then |
|
|
540 | einfo "${egroup} already exists on your system :)" |
|
|
541 | return 0 |
|
|
542 | fi |
|
|
543 | |
|
|
544 | # options to pass to useradd |
|
|
545 | local opts="" |
|
|
546 | |
|
|
547 | # handle gid |
|
|
548 | local egid="$1"; shift |
|
|
549 | if [ ! -z "${egid}" ] ; then |
|
|
550 | if [ ${egid} -gt 0 ] ; then |
|
|
551 | opts="${opts} -g ${egid}" |
|
|
552 | else |
|
|
553 | eerror "Groupid given but is not greater than 0 !" |
|
|
554 | die "${egid} is not a valid GID" |
|
|
555 | fi |
|
|
556 | else |
|
|
557 | egid="next available" |
|
|
558 | fi |
|
|
559 | einfo " - Groupid: ${egid}" |
|
|
560 | |
|
|
561 | # handle extra |
|
|
562 | local eextra="$@" |
|
|
563 | opts="${opts} ${eextra}" |
|
|
564 | |
|
|
565 | # add the group |
|
|
566 | local oldsandbox="${oldsandbox}" |
|
|
567 | export SANDBOX_ON="0" |
|
|
568 | groupadd ${opts} ${egroup} || die "enewgroup failed" |
|
|
569 | export SANDBOX_ON="${oldsandbox}" |
|
|
570 | } |
|
|
571 | |
|
|
572 | # Simple script to replace 'dos2unix' binaries |
|
|
573 | # vapier@gentoo.org |
|
|
574 | # |
|
|
575 | # edos2unix(file, <more files>...) |
|
|
576 | edos2unix() { |
|
|
577 | for f in $@ ; do |
|
|
578 | cp ${f} ${T}/ |
|
|
579 | sed 's/\r$//' ${T}/${f}.old > ${f} |
|
|
580 | done |
|
|
581 | } |