/[gentoo-x86]/eclass/eutils.eclass
Gentoo

Diff of /eclass/eutils.eclass

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 1.173 Revision 1.182
1# Copyright 1999-2005 Gentoo Foundation 1# Copyright 1999-2005 Gentoo Foundation
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.173 2005/05/24 03:17:19 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.182 2005/06/11 00:02:26 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.
11 11
12inherit multilib 12inherit multilib
13ECLASS=eutils 13ECLASS=eutils
14INHERITED="$INHERITED $ECLASS" 14INHERITED="$INHERITED $ECLASS"
15 15
16DEPEND="!bootstrap? ( sys-devel/patch )" 16DEPEND="!bootstrap? ( sys-devel/patch userland_GNU? ( sys-apps/shadow ) )"
17# sys-apps/shadow is needed for useradd, etc, bug #94745.
17 18
18DESCRIPTION="Based on the ${ECLASS} eclass" 19DESCRIPTION="Based on the ${ECLASS} eclass"
19 20
20# Wait for the supplied number of seconds. If no argument is supplied, defaults 21# Wait for the supplied number of seconds. If no argument is supplied, defaults
21# to five seconds. If the EPAUSE_IGNORE env var is set, don't wait. If we're not 22# to five seconds. If the EPAUSE_IGNORE env var is set, don't wait. If we're not
249 # New ARCH dependant patch naming scheme ... 250 # New ARCH dependant patch naming scheme ...
250 # 251 #
251 # ???_arch_foo.patch 252 # ???_arch_foo.patch
252 # 253 #
253 if [ -f ${x} ] && \ 254 if [ -f ${x} ] && \
254 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "`eval echo \$\{x/_${ARCH}_\}`" != "${x}" ] || \ 255 ([ "${SINGLE_PATCH}" = "yes" -o "${x/_all_}" != "${x}" -o "${x/_${ARCH}_}" != "${x}" ] || \
255 [ "${EPATCH_FORCE}" = "yes" ]) 256 [ "${EPATCH_FORCE}" = "yes" ])
256 then 257 then
257 local count=0 258 local count=0
258 local popts="${EPATCH_OPTS}" 259 local popts="${EPATCH_OPTS}"
259 local patchname=${x##*/} 260 local patchname=${x##*/}
369 then 370 then
370 einfo "Done with patching" 371 einfo "Done with patching"
371 fi 372 fi
372} 373}
373 374
374# This function check how many cpu's are present, and then set
375# -j in MAKEOPTS accordingly.
376#
377# Thanks to nall <nall@gentoo.org> for this.
378#
379get_number_of_jobs() {
380 local jobs=0
381
382 if [ ! -r /proc/cpuinfo ]
383 then
384 return 1
385 fi
386
387 # This bit is from H?kan Wessberg <nacka-gentoo@refug.org>, bug #13565.
388 if [ "`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | wc -l`" -gt 0 ]
389 then
390 ADMINOPTS="`egrep "^[[:space:]]*MAKEOPTS=" /etc/make.conf | cut -d= -f2 | sed 's/\"//g'`"
391 ADMINPARAM="`echo ${ADMINOPTS} | gawk '{match($0, /-j *[0-9]*/, opt); print opt[0]}'`"
392 ADMINPARAM="${ADMINPARAM/-j}"
393 fi
394
395 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
396
397 if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
398 "${ARCH}" = "arm" -o "${ARCH}" = "mips" -o "${ARCH}" = "ia64" ]
399 then
400 # these archs will always have "[Pp]rocessor"
401 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
402
403 elif [ "${ARCH}" = "sparc" -o "${ARCH}" = "sparc64" ]
404 then
405 # sparc always has "ncpus active"
406 jobs="$((`grep "^ncpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
407
408 elif [ "${ARCH}" = "alpha" ]
409 then
410 # alpha has "cpus active", but only when compiled with SMP
411 if [ "`grep -c "^cpus active" /proc/cpuinfo`" -eq 1 ]
412 then
413 jobs="$((`grep "^cpus active" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
414 else
415 jobs=2
416 fi
417
418 elif [ "${ARCH}" = "ppc" -o "${ARCH}" = "ppc64" ]
419 then
420 # ppc has "processor", but only when compiled with SMP
421 if [ "`grep -c "^processor" /proc/cpuinfo`" -eq 1 ]
422 then
423 jobs="$((`grep -c ^processor /proc/cpuinfo` * 2))"
424 else
425 jobs=2
426 fi
427 elif [ "${ARCH}" = "s390" ]
428 then
429 # s390 has "# processors : "
430 jobs="$((`grep "^\# processors" /proc/cpuinfo | sed -e "s/^.*: //"` * 2))"
431 else
432 jobs="$((`grep -c ^cpu /proc/cpuinfo` * 2))"
433 die "Unknown ARCH -- ${ARCH}!"
434 fi
435
436 # Make sure the number is valid ...
437 if [ "${jobs}" -lt 1 ]
438 then
439 jobs=1
440 fi
441
442 if [ -n "${ADMINPARAM}" ]
443 then
444 if [ "${jobs}" -gt "${ADMINPARAM}" ]
445 then
446 einfo "Setting make jobs to \"-j${ADMINPARAM}\" to ensure successful merge ..."
447 export MAKEOPTS="${MAKEOPTS} -j${ADMINPARAM}"
448 else
449 einfo "Setting make jobs to \"-j${jobs}\" to ensure successful merge ..."
450 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
451 fi
452 fi
453}
454
455# Cheap replacement for when debianutils (and thus mktemp) 375# Cheap replacement for when debianutils (and thus mktemp)
456# does not exist on the users system 376# does not exist on the users system
457# vapier@gentoo.org 377# vapier@gentoo.org
458# 378#
459# Takes just 1 optional parameter (the directory to create tmpfile in) 379# Takes just 1 optional parameter (the directory to create tmpfile in)
490# Joe Jezak <josejx@gmail.com> and usata@gentoo.org 410# Joe Jezak <josejx@gmail.com> and usata@gentoo.org
491# FBSD stuff: Aaron Walker <ka0ttic@gentoo.org> 411# FBSD stuff: Aaron Walker <ka0ttic@gentoo.org>
492# 412#
493# egetent(database, key) 413# egetent(database, key)
494egetent() { 414egetent() {
495 if useq ppc-macos ; then 415 if [[ "${USERLAND}" == "Darwin" ]] ; then
496 case "$2" in 416 case "$2" in
497 *[!0-9]*) # Non numeric 417 *[!0-9]*) # Non numeric
498 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }" 418 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
499 ;; 419 ;;
500 *) # Numeric 420 *) # Numeric
501 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" 421 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
502 ;; 422 ;;
503 esac 423 esac
504 elif useq x86-fbsd ; then 424 elif [[ "${USERLAND}" == "BSD" ]] ; then
505 local action 425 local action
506 if [ "$1" == "passwd" ] 426 if [ "$1" == "passwd" ]
507 then 427 then
508 action="user" 428 action="user"
509 else 429 else
529# homedir: /dev/null 449# homedir: /dev/null
530# groups: none 450# groups: none
531# extra: comment of 'added by portage for ${PN}' 451# extra: comment of 'added by portage for ${PN}'
532enewuser() { 452enewuser() {
533 # get the username 453 # get the username
534 local euser="$1"; shift 454 local euser=$1; shift
535 if [ -z "${euser}" ] 455 if [[ -z ${euser} ]] ; then
536 then
537 eerror "No username specified !" 456 eerror "No username specified !"
538 die "Cannot call enewuser without a username" 457 die "Cannot call enewuser without a username"
539 fi 458 fi
540 459
541 # lets see if the username already exists 460 # lets see if the username already exists
542 if [ "${euser}" == "`egetent passwd \"${euser}\" | cut -d: -f1`" ] 461 if [[ ${euser} == $(egetent passwd "${euser}" | cut -d: -f1) ]] ; then
543 then
544 return 0 462 return 0
545 fi 463 fi
546 einfo "Adding user '${euser}' to your system ..." 464 einfo "Adding user '${euser}' to your system ..."
547 465
548 # options to pass to useradd 466 # options to pass to useradd
549 local opts= 467 local opts=
550 468
551 # handle uid 469 # handle uid
552 local euid="$1"; shift 470 local euid=$1; shift
553 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] 471 if [[ ! -z ${euid} ]] && [[ ${euid} != "-1" ]] ; then
554 then
555 if [ "${euid}" -gt 0 ] 472 if [[ ${euid} -gt 0 ]] ; then
556 then
557 if [ ! -z "`egetent passwd ${euid}`" ] 473 if [[ ! -z $(egetent passwd ${euid}) ]] ; then
558 then
559 euid="next" 474 euid="next"
560 fi 475 fi
561 else 476 else
562 eerror "Userid given but is not greater than 0 !" 477 eerror "Userid given but is not greater than 0 !"
563 die "${euid} is not a valid UID" 478 die "${euid} is not a valid UID"
564 fi 479 fi
565 else 480 else
566 euid="next" 481 euid="next"
567 fi 482 fi
568 if [ "${euid}" == "next" ] 483 if [[ ${euid} == "next" ]] ; then
569 then
570 local pwrange 484 local pwrange
571 if [ "${USERLAND}" == "BSD" ] ; then 485 if [[ ${USERLAND} == "BSD" ]] ; then
572 pwrange="`jot 898 101`" 486 pwrange=$(jot 898 101)
573 else 487 else
574 pwrange="`seq 101 999`" 488 pwrange=$(seq 101 999)
575 fi 489 fi
576 for euid in ${pwrange} ; do 490 for euid in ${pwrange} ; do
577 [ -z "`egetent passwd ${euid}`" ] && break 491 [[ -z $(egetent passwd ${euid}) ]] && break
578 done 492 done
579 fi 493 fi
580 opts="${opts} -u ${euid}" 494 opts="${opts} -u ${euid}"
581 einfo " - Userid: ${euid}" 495 einfo " - Userid: ${euid}"
582 496
583 # handle shell 497 # handle shell
584 local eshell="$1"; shift 498 local eshell=$1; shift
585 if [ ! -z "${eshell}" ] && [ "${eshell}" != "-1" ] 499 if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then
586 then
587 if [ ! -e "${eshell}" ] 500 if [[ ! -e ${eshell} ]] ; then
588 then
589 eerror "A shell was specified but it does not exist !" 501 eerror "A shell was specified but it does not exist !"
590 die "${eshell} does not exist" 502 die "${eshell} does not exist"
591 fi 503 fi
592 else 504 else
593 if [ "${USERLAND}" == "BSD" ] 505 case ${USERLAND} in
594 then
595 eshell="/usr/bin/false" 506 Darwin) eshell="/usr/bin/false";;
596 else 507 BSD) eshell="/usr/sbin/nologin";;
597 eshell="/bin/false" 508 *) eshell="/bin/false";;
598 fi 509 esac
599 fi 510 fi
600 einfo " - Shell: ${eshell}" 511 einfo " - Shell: ${eshell}"
601 opts="${opts} -s ${eshell}" 512 opts="${opts} -s ${eshell}"
602 513
603 # handle homedir 514 # handle homedir
604 local ehome="$1"; shift 515 local ehome=$1; shift
605 if [ -z "${ehome}" ] && [ "${eshell}" != "-1" ] 516 if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then
606 then
607 ehome="/dev/null" 517 ehome="/dev/null"
608 fi 518 fi
609 einfo " - Home: ${ehome}" 519 einfo " - Home: ${ehome}"
610 opts="${opts} -d ${ehome}" 520 opts="${opts} -d ${ehome}"
611 521
612 # handle groups 522 # handle groups
613 local egroups="$1"; shift 523 local egroups=$1; shift
614 if [ ! -z "${egroups}" ] 524 if [[ ! -z ${egroups} ]] ; then
615 then
616 local oldifs="${IFS}" 525 local oldifs=${IFS}
617 local defgroup="" exgroups="" 526 local defgroup="" exgroups=""
618 527
619 export IFS="," 528 export IFS=","
620 for g in ${egroups} 529 for g in ${egroups} ; do
621 do
622 export IFS="${oldifs}" 530 export IFS=${oldifs}
623 if [ -z "`egetent group \"${g}\"`" ] 531 if [[ -z $(egetent group "${g}") ]] ; then
624 then
625 eerror "You must add group ${g} to the system first" 532 eerror "You must add group ${g} to the system first"
626 die "${g} is not a valid GID" 533 die "${g} is not a valid GID"
627 fi 534 fi
628 if [ -z "${defgroup}" ] 535 if [[ -z ${defgroup} ]] ; then
629 then
630 defgroup="${g}" 536 defgroup=${g}
631 else 537 else
632 exgroups="${exgroups},${g}" 538 exgroups="${exgroups},${g}"
633 fi 539 fi
634 export IFS="," 540 export IFS=","
635 done 541 done
636 export IFS="${oldifs}" 542 export IFS=${oldifs}
637 543
638 opts="${opts} -g ${defgroup}" 544 opts="${opts} -g ${defgroup}"
639 if [ ! -z "${exgroups}" ] 545 if [[ ! -z ${exgroups} ]] ; then
640 then
641 opts="${opts} -G ${exgroups:1}" 546 opts="${opts} -G ${exgroups:1}"
642 fi 547 fi
643 else 548 else
644 egroups="(none)" 549 egroups="(none)"
645 fi 550 fi
646 einfo " - Groups: ${egroups}" 551 einfo " - Groups: ${egroups}"
647 552
648 # handle extra and add the user 553 # handle extra and add the user
649 local eextra="$@"
650 local oldsandbox="${SANDBOX_ON}" 554 local oldsandbox=${SANDBOX_ON}
651 export SANDBOX_ON="0" 555 export SANDBOX_ON="0"
652 if useq ppc-macos 556 case ${USERLAND} in
653 then 557 Darwin)
654 ### Make the user 558 ### Make the user
655 if [ -z "${eextra}" ] 559 if [[ -z $@ ]] ; then
656 then
657 dscl . create /users/${euser} uid ${euid} 560 dscl . create /users/${euser} uid ${euid}
658 dscl . create /users/${euser} shell ${eshell} 561 dscl . create /users/${euser} shell ${eshell}
659 dscl . create /users/${euser} home ${ehome} 562 dscl . create /users/${euser} home ${ehome}
660 dscl . create /users/${euser} realname "added by portage for ${PN}" 563 dscl . create /users/${euser} realname "added by portage for ${PN}"
661 ### Add the user to the groups specified 564 ### Add the user to the groups specified
662 local oldifs="${IFS}" 565 local oldifs=${IFS}
663 export IFS="," 566 export IFS=","
664 for g in ${egroups} 567 for g in ${egroups} ; do
665 do
666 dscl . merge /groups/${g} users ${euser} 568 dscl . merge /groups/${g} users ${euser}
667 done 569 done
668 export IFS="${oldifs}" 570 export IFS=${oldifs}
669 else 571 else
670 einfo "Extra options are not supported on macos yet" 572 einfo "Extra options are not supported on Darwin yet"
671 einfo "Please report the ebuild along with the info below" 573 einfo "Please report the ebuild along with the info below"
672 einfo "eextra: ${eextra}" 574 einfo "eextra: $@"
673 die "Required function missing" 575 die "Required function missing"
674 fi 576 fi
675 elif use x86-fbsd ; then 577 ;;
676 if [ -z "${eextra}" ] 578 BSD)
677 then 579 if [[ -z $@ ]] ; then
678 pw useradd ${euser} ${opts} \ 580 pw useradd ${euser} ${opts} \
679 -c "added by portage for ${PN}" \ 581 -c "added by portage for ${PN}" \
680 die "enewuser failed" 582 die "enewuser failed"
681 else 583 else
682 einfo " - Extra: ${eextra}" 584 einfo " - Extra: $@"
683 pw useradd ${euser} ${opts} \ 585 pw useradd ${euser} ${opts} \
684 -c ${eextra} || die "enewuser failed" 586 "$@" || die "enewuser failed"
685 fi 587 fi
686 else 588 ;;
687 if [ -z "${eextra}" ] 589 *)
688 then 590 if [[ -z $@ ]] ; then
689 useradd ${opts} ${euser} \ 591 useradd ${opts} ${euser} \
690 -c "added by portage for ${PN}" \ 592 -c "added by portage for ${PN}" \
691 || die "enewuser failed" 593 || die "enewuser failed"
692 else 594 else
693 einfo " - Extra: ${eextra}" 595 einfo " - Extra: $@"
694 useradd ${opts} ${euser} ${eextra} \ 596 useradd ${opts} ${euser} "$@" \
695 || die "enewuser failed" 597 || die "enewuser failed"
696 fi 598 fi
697 fi 599 ;;
600 esac
698 export SANDBOX_ON="${oldsandbox}" 601 export SANDBOX_ON=${oldsandbox}
699 602
700 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ] 603 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ]
701 then 604 then
702 einfo " - Creating ${ehome} in ${D}" 605 einfo " - Creating ${ehome} in ${D}"
703 dodir ${ehome} 606 dodir ${ehome}
740 then 643 then
741 if [ "${egid}" -gt 0 ] 644 if [ "${egid}" -gt 0 ]
742 then 645 then
743 if [ -z "`egetent group ${egid}`" ] 646 if [ -z "`egetent group ${egid}`" ]
744 then 647 then
745 if useq ppc-macos ; then 648 if [[ "${USERLAND}" == "Darwin" ]]; then
746 opts="${opts} ${egid}" 649 opts="${opts} ${egid}"
747 else 650 else
748 opts="${opts} -g ${egid}" 651 opts="${opts} -g ${egid}"
749 fi 652 fi
750 else 653 else
764 opts="${opts} ${eextra}" 667 opts="${opts} ${eextra}"
765 668
766 # add the group 669 # add the group
767 local oldsandbox="${SANDBOX_ON}" 670 local oldsandbox="${SANDBOX_ON}"
768 export SANDBOX_ON="0" 671 export SANDBOX_ON="0"
769 if useq ppc-macos ; then 672 if [[ "${USERLAND}" == "Darwin" ]]; then
770 if [ ! -z "${eextra}" ]; 673 if [ ! -z "${eextra}" ];
771 then 674 then
772 einfo "Extra options are not supported on macos yet" 675 einfo "Extra options are not supported on Darwin/OS X yet"
773 einfo "Please report the ebuild along with the info below" 676 einfo "Please report the ebuild along with the info below"
774 einfo "eextra: ${eextra}" 677 einfo "eextra: ${eextra}"
775 die "Required function missing" 678 die "Required function missing"
776 fi 679 fi
777 680
782 [ -z "`egetent group ${egid}`" ] && break 685 [ -z "`egetent group ${egid}`" ] && break
783 done 686 done
784 esac 687 esac
785 dscl . create /groups/${egroup} gid ${egid} 688 dscl . create /groups/${egroup} gid ${egid}
786 dscl . create /groups/${egroup} passwd '*' 689 dscl . create /groups/${egroup} passwd '*'
787 elif use x86-fbsd ; then 690 elif [[ "${USERLAND}" == "BSD" ]] ; then
788 case ${egid} in 691 case ${egid} in
789 *[!0-9]*) # Non numeric 692 *[!0-9]*) # Non numeric
790 for egid in `jot 898 101`; do 693 for egid in `jot 898 101`; do
791 [ -z "`egetent group ${egid}`" ] && break 694 [ -z "`egetent group ${egid}`" ] && break
792 done 695 done
939 *) 842 *)
940 type= 843 type=
941 ;; 844 ;;
942 esac 845 esac
943 fi 846 fi
944 847 if [ "${SLOT}" == "0" ] ; then
848 local desktop_name="${PN}"
849 else
850 local desktop_name="${PN}-${SLOT}"
851 fi
945 local desktop=${T}/${exec%% *}-${P}.desktop 852 local desktop=${T}/${exec%% *}-${desktop_name}.desktop
946 853
947echo "[Desktop Entry] 854echo "[Desktop Entry]
948Encoding=UTF-8 855Encoding=UTF-8
949Version=0.9.2 856Version=0.9.2
950Name=${name} 857Name=${name}
1527 while ((i--)) ; do 1434 while ((i--)) ; do
1528 ewarn "PLEASE UPDATE TO YOUR PACKAGE TO USE linux-info.eclass" 1435 ewarn "PLEASE UPDATE TO YOUR PACKAGE TO USE linux-info.eclass"
1529 done 1436 done
1530 export EUTILS_ECLASS_PORTAGE_ARCH="${ARCH}" 1437 export EUTILS_ECLASS_PORTAGE_ARCH="${ARCH}"
1531 case ${ARCH} in 1438 case ${ARCH} in
1532 x86) export ARCH="i386";; 1439 x86) export ARCH="i386";;
1533 amd64) export ARCH="x86_64";; 1440 amd64) export ARCH="x86_64";;
1534 hppa) export ARCH="parisc";; 1441 hppa) export ARCH="parisc";;
1535 mips) export ARCH="mips";; 1442 mips) export ARCH="mips";;
1536 sparc) export ARCH="$(tc-arch-kernel)";; # Yeah this is ugly, but it's even WORSE if you don't do this. linux-info.eclass's set_arch_to_kernel is fixed, but won't get used over this one! 1443 sparc) export ARCH="$(tc-arch-kernel)";; # Yeah this is ugly, but it's even WORSE if you don't do this. linux-info.eclass's set_arch_to_kernel is fixed, but won't get used over this one!
1537 *) export ARCH="${ARCH}";; 1444 *) export ARCH="${ARCH}";;
1538 esac 1445 esac
1539} 1446}
1540 1447
1541# set's ARCH back to what portage expects 1448# set's ARCH back to what portage expects
1542set_arch_to_portage() { 1449set_arch_to_portage() {

Legend:
Removed from v.1.173  
changed lines
  Added in v.1.182

  ViewVC Help
Powered by ViewVC 1.1.20