| 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.175 2005/05/25 00:04:25 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 | |
| 12 | inherit multilib |
12 | inherit multilib |
| 13 | ECLASS=eutils |
13 | ECLASS=eutils |
| 14 | INHERITED="$INHERITED $ECLASS" |
14 | INHERITED="$INHERITED $ECLASS" |
| 15 | |
15 | |
| 16 | DEPEND="!bootstrap? ( sys-devel/patch )" |
16 | DEPEND="!bootstrap? ( sys-devel/patch userland_GNU? ( sys-apps/shadow ) )" |
|
|
17 | # sys-apps/shadow is needed for useradd, etc, bug #94745. |
| 17 | |
18 | |
| 18 | DESCRIPTION="Based on the ${ECLASS} eclass" |
19 | DESCRIPTION="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##*/} |
| … | |
… | |
| 409 | # Joe Jezak <josejx@gmail.com> and usata@gentoo.org |
410 | # Joe Jezak <josejx@gmail.com> and usata@gentoo.org |
| 410 | # FBSD stuff: Aaron Walker <ka0ttic@gentoo.org> |
411 | # FBSD stuff: Aaron Walker <ka0ttic@gentoo.org> |
| 411 | # |
412 | # |
| 412 | # egetent(database, key) |
413 | # egetent(database, key) |
| 413 | egetent() { |
414 | egetent() { |
| 414 | if useq ppc-macos ; then |
415 | if [[ "${USERLAND}" == "Darwin" ]] ; then |
| 415 | case "$2" in |
416 | case "$2" in |
| 416 | *[!0-9]*) # Non numeric |
417 | *[!0-9]*) # Non numeric |
| 417 | nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }" |
418 | nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }" |
| 418 | ;; |
419 | ;; |
| 419 | *) # Numeric |
420 | *) # Numeric |
| 420 | nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" |
421 | nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" |
| 421 | ;; |
422 | ;; |
| 422 | esac |
423 | esac |
| 423 | elif useq x86-fbsd ; then |
424 | elif [[ "${USERLAND}" == "BSD" ]] ; then |
| 424 | local action |
425 | local action |
| 425 | if [ "$1" == "passwd" ] |
426 | if [ "$1" == "passwd" ] |
| 426 | then |
427 | then |
| 427 | action="user" |
428 | action="user" |
| 428 | else |
429 | else |
| … | |
… | |
| 448 | # homedir: /dev/null |
449 | # homedir: /dev/null |
| 449 | # groups: none |
450 | # groups: none |
| 450 | # extra: comment of 'added by portage for ${PN}' |
451 | # extra: comment of 'added by portage for ${PN}' |
| 451 | enewuser() { |
452 | enewuser() { |
| 452 | # get the username |
453 | # get the username |
| 453 | local euser="$1"; shift |
454 | local euser=$1; shift |
| 454 | if [ -z "${euser}" ] |
455 | if [[ -z ${euser} ]] ; then |
| 455 | then |
|
|
| 456 | eerror "No username specified !" |
456 | eerror "No username specified !" |
| 457 | die "Cannot call enewuser without a username" |
457 | die "Cannot call enewuser without a username" |
| 458 | fi |
458 | fi |
| 459 | |
459 | |
| 460 | # lets see if the username already exists |
460 | # lets see if the username already exists |
| 461 | if [ "${euser}" == "`egetent passwd \"${euser}\" | cut -d: -f1`" ] |
461 | if [[ ${euser} == $(egetent passwd "${euser}" | cut -d: -f1) ]] ; then |
| 462 | then |
|
|
| 463 | return 0 |
462 | return 0 |
| 464 | fi |
463 | fi |
| 465 | einfo "Adding user '${euser}' to your system ..." |
464 | einfo "Adding user '${euser}' to your system ..." |
| 466 | |
465 | |
| 467 | # options to pass to useradd |
466 | # options to pass to useradd |
| 468 | local opts= |
467 | local opts= |
| 469 | |
468 | |
| 470 | # handle uid |
469 | # handle uid |
| 471 | local euid="$1"; shift |
470 | local euid=$1; shift |
| 472 | if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] |
471 | if [[ ! -z ${euid} ]] && [[ ${euid} != "-1" ]] ; then |
| 473 | then |
|
|
| 474 | if [ "${euid}" -gt 0 ] |
472 | if [[ ${euid} -gt 0 ]] ; then |
| 475 | then |
|
|
| 476 | if [ ! -z "`egetent passwd ${euid}`" ] |
473 | if [[ ! -z $(egetent passwd ${euid}) ]] ; then |
| 477 | then |
|
|
| 478 | euid="next" |
474 | euid="next" |
| 479 | fi |
475 | fi |
| 480 | else |
476 | else |
| 481 | eerror "Userid given but is not greater than 0 !" |
477 | eerror "Userid given but is not greater than 0 !" |
| 482 | die "${euid} is not a valid UID" |
478 | die "${euid} is not a valid UID" |
| 483 | fi |
479 | fi |
| 484 | else |
480 | else |
| 485 | euid="next" |
481 | euid="next" |
| 486 | fi |
482 | fi |
| 487 | if [ "${euid}" == "next" ] |
483 | if [[ ${euid} == "next" ]] ; then |
| 488 | then |
|
|
| 489 | local pwrange |
484 | local pwrange |
| 490 | if [ "${USERLAND}" == "BSD" ] ; then |
485 | if [[ ${USERLAND} == "BSD" ]] ; then |
| 491 | pwrange="`jot 898 101`" |
486 | pwrange=$(jot 898 101) |
| 492 | else |
487 | else |
| 493 | pwrange="`seq 101 999`" |
488 | pwrange=$(seq 101 999) |
| 494 | fi |
489 | fi |
| 495 | for euid in ${pwrange} ; do |
490 | for euid in ${pwrange} ; do |
| 496 | [ -z "`egetent passwd ${euid}`" ] && break |
491 | [[ -z $(egetent passwd ${euid}) ]] && break |
| 497 | done |
492 | done |
| 498 | fi |
493 | fi |
| 499 | opts="${opts} -u ${euid}" |
494 | opts="${opts} -u ${euid}" |
| 500 | einfo " - Userid: ${euid}" |
495 | einfo " - Userid: ${euid}" |
| 501 | |
496 | |
| 502 | # handle shell |
497 | # handle shell |
| 503 | local eshell="$1"; shift |
498 | local eshell=$1; shift |
| 504 | if [ ! -z "${eshell}" ] && [ "${eshell}" != "-1" ] |
499 | if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then |
| 505 | then |
|
|
| 506 | if [ ! -e "${eshell}" ] |
500 | if [[ ! -e ${eshell} ]] ; then |
| 507 | then |
|
|
| 508 | eerror "A shell was specified but it does not exist !" |
501 | eerror "A shell was specified but it does not exist !" |
| 509 | die "${eshell} does not exist" |
502 | die "${eshell} does not exist" |
| 510 | fi |
503 | fi |
| 511 | else |
504 | else |
| 512 | if [ "${USERLAND}" == "BSD" ] |
505 | case ${USERLAND} in |
| 513 | then |
|
|
| 514 | eshell="/usr/bin/false" |
506 | Darwin) eshell="/usr/bin/false";; |
| 515 | else |
507 | BSD) eshell="/usr/sbin/nologin";; |
| 516 | eshell="/bin/false" |
508 | *) eshell="/bin/false";; |
| 517 | fi |
509 | esac |
| 518 | fi |
510 | fi |
| 519 | einfo " - Shell: ${eshell}" |
511 | einfo " - Shell: ${eshell}" |
| 520 | opts="${opts} -s ${eshell}" |
512 | opts="${opts} -s ${eshell}" |
| 521 | |
513 | |
| 522 | # handle homedir |
514 | # handle homedir |
| 523 | local ehome="$1"; shift |
515 | local ehome=$1; shift |
| 524 | if [ ! -z "${ehome}" ] && [ "${eshell}" != "-1" ] |
516 | if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then |
| 525 | then |
|
|
| 526 | ehome="/dev/null" |
517 | ehome="/dev/null" |
| 527 | fi |
518 | fi |
| 528 | einfo " - Home: ${ehome}" |
519 | einfo " - Home: ${ehome}" |
| 529 | opts="${opts} -d ${ehome}" |
520 | opts="${opts} -d ${ehome}" |
| 530 | |
521 | |
| 531 | # handle groups |
522 | # handle groups |
| 532 | local egroups="$1"; shift |
523 | local egroups=$1; shift |
| 533 | if [ ! -z "${egroups}" ] |
524 | if [[ ! -z ${egroups} ]] ; then |
| 534 | then |
|
|
| 535 | local oldifs="${IFS}" |
525 | local oldifs=${IFS} |
| 536 | local defgroup="" exgroups="" |
526 | local defgroup="" exgroups="" |
| 537 | |
527 | |
| 538 | export IFS="," |
528 | export IFS="," |
| 539 | for g in ${egroups} |
529 | for g in ${egroups} ; do |
| 540 | do |
|
|
| 541 | export IFS="${oldifs}" |
530 | export IFS=${oldifs} |
| 542 | if [ -z "`egetent group \"${g}\"`" ] |
531 | if [[ -z $(egetent group "${g}") ]] ; then |
| 543 | then |
|
|
| 544 | eerror "You must add group ${g} to the system first" |
532 | eerror "You must add group ${g} to the system first" |
| 545 | die "${g} is not a valid GID" |
533 | die "${g} is not a valid GID" |
| 546 | fi |
534 | fi |
| 547 | if [ -z "${defgroup}" ] |
535 | if [[ -z ${defgroup} ]] ; then |
| 548 | then |
|
|
| 549 | defgroup="${g}" |
536 | defgroup=${g} |
| 550 | else |
537 | else |
| 551 | exgroups="${exgroups},${g}" |
538 | exgroups="${exgroups},${g}" |
| 552 | fi |
539 | fi |
| 553 | export IFS="," |
540 | export IFS="," |
| 554 | done |
541 | done |
| 555 | export IFS="${oldifs}" |
542 | export IFS=${oldifs} |
| 556 | |
543 | |
| 557 | opts="${opts} -g ${defgroup}" |
544 | opts="${opts} -g ${defgroup}" |
| 558 | if [ ! -z "${exgroups}" ] |
545 | if [[ ! -z ${exgroups} ]] ; then |
| 559 | then |
|
|
| 560 | opts="${opts} -G ${exgroups:1}" |
546 | opts="${opts} -G ${exgroups:1}" |
| 561 | fi |
547 | fi |
| 562 | else |
548 | else |
| 563 | egroups="(none)" |
549 | egroups="(none)" |
| 564 | fi |
550 | fi |
| 565 | einfo " - Groups: ${egroups}" |
551 | einfo " - Groups: ${egroups}" |
| 566 | |
552 | |
| 567 | # handle extra and add the user |
553 | # handle extra and add the user |
| 568 | local eextra="$@" |
|
|
| 569 | local oldsandbox="${SANDBOX_ON}" |
554 | local oldsandbox=${SANDBOX_ON} |
| 570 | export SANDBOX_ON="0" |
555 | export SANDBOX_ON="0" |
| 571 | if useq ppc-macos |
556 | case ${USERLAND} in |
| 572 | then |
557 | Darwin) |
| 573 | ### Make the user |
558 | ### Make the user |
| 574 | if [ -z "${eextra}" ] |
559 | if [[ -z $@ ]] ; then |
| 575 | then |
|
|
| 576 | dscl . create /users/${euser} uid ${euid} |
560 | dscl . create /users/${euser} uid ${euid} |
| 577 | dscl . create /users/${euser} shell ${eshell} |
561 | dscl . create /users/${euser} shell ${eshell} |
| 578 | dscl . create /users/${euser} home ${ehome} |
562 | dscl . create /users/${euser} home ${ehome} |
| 579 | dscl . create /users/${euser} realname "added by portage for ${PN}" |
563 | dscl . create /users/${euser} realname "added by portage for ${PN}" |
| 580 | ### Add the user to the groups specified |
564 | ### Add the user to the groups specified |
| 581 | local oldifs="${IFS}" |
565 | local oldifs=${IFS} |
| 582 | export IFS="," |
566 | export IFS="," |
| 583 | for g in ${egroups} |
567 | for g in ${egroups} ; do |
| 584 | do |
|
|
| 585 | dscl . merge /groups/${g} users ${euser} |
568 | dscl . merge /groups/${g} users ${euser} |
| 586 | done |
569 | done |
| 587 | export IFS="${oldifs}" |
570 | export IFS=${oldifs} |
| 588 | else |
571 | else |
| 589 | einfo "Extra options are not supported on macos yet" |
572 | einfo "Extra options are not supported on Darwin yet" |
| 590 | einfo "Please report the ebuild along with the info below" |
573 | einfo "Please report the ebuild along with the info below" |
| 591 | einfo "eextra: ${eextra}" |
574 | einfo "eextra: $@" |
| 592 | die "Required function missing" |
575 | die "Required function missing" |
| 593 | fi |
576 | fi |
| 594 | elif use x86-fbsd ; then |
577 | ;; |
| 595 | if [ -z "${eextra}" ] |
578 | BSD) |
| 596 | then |
579 | if [[ -z $@ ]] ; then |
| 597 | pw useradd ${euser} ${opts} \ |
580 | pw useradd ${euser} ${opts} \ |
| 598 | -c "added by portage for ${PN}" \ |
581 | -c "added by portage for ${PN}" \ |
| 599 | die "enewuser failed" |
582 | die "enewuser failed" |
| 600 | else |
583 | else |
| 601 | einfo " - Extra: ${eextra}" |
584 | einfo " - Extra: $@" |
| 602 | pw useradd ${euser} ${opts} \ |
585 | pw useradd ${euser} ${opts} \ |
| 603 | -c ${eextra} || die "enewuser failed" |
586 | "$@" || die "enewuser failed" |
| 604 | fi |
587 | fi |
| 605 | else |
588 | ;; |
| 606 | if [ -z "${eextra}" ] |
589 | *) |
| 607 | then |
590 | if [[ -z $@ ]] ; then |
| 608 | useradd ${opts} ${euser} \ |
591 | useradd ${opts} ${euser} \ |
| 609 | -c "added by portage for ${PN}" \ |
592 | -c "added by portage for ${PN}" \ |
| 610 | || die "enewuser failed" |
593 | || die "enewuser failed" |
| 611 | else |
594 | else |
| 612 | einfo " - Extra: ${eextra}" |
595 | einfo " - Extra: $@" |
| 613 | useradd ${opts} ${euser} ${eextra} \ |
596 | useradd ${opts} ${euser} "$@" \ |
| 614 | || die "enewuser failed" |
597 | || die "enewuser failed" |
| 615 | fi |
598 | fi |
| 616 | fi |
599 | ;; |
|
|
600 | esac |
| 617 | export SANDBOX_ON="${oldsandbox}" |
601 | export SANDBOX_ON=${oldsandbox} |
| 618 | |
602 | |
| 619 | if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ] |
603 | if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ] |
| 620 | then |
604 | then |
| 621 | einfo " - Creating ${ehome} in ${D}" |
605 | einfo " - Creating ${ehome} in ${D}" |
| 622 | dodir ${ehome} |
606 | dodir ${ehome} |
| … | |
… | |
| 659 | then |
643 | then |
| 660 | if [ "${egid}" -gt 0 ] |
644 | if [ "${egid}" -gt 0 ] |
| 661 | then |
645 | then |
| 662 | if [ -z "`egetent group ${egid}`" ] |
646 | if [ -z "`egetent group ${egid}`" ] |
| 663 | then |
647 | then |
| 664 | if useq ppc-macos ; then |
648 | if [[ "${USERLAND}" == "Darwin" ]]; then |
| 665 | opts="${opts} ${egid}" |
649 | opts="${opts} ${egid}" |
| 666 | else |
650 | else |
| 667 | opts="${opts} -g ${egid}" |
651 | opts="${opts} -g ${egid}" |
| 668 | fi |
652 | fi |
| 669 | else |
653 | else |
| … | |
… | |
| 683 | opts="${opts} ${eextra}" |
667 | opts="${opts} ${eextra}" |
| 684 | |
668 | |
| 685 | # add the group |
669 | # add the group |
| 686 | local oldsandbox="${SANDBOX_ON}" |
670 | local oldsandbox="${SANDBOX_ON}" |
| 687 | export SANDBOX_ON="0" |
671 | export SANDBOX_ON="0" |
| 688 | if useq ppc-macos ; then |
672 | if [[ "${USERLAND}" == "Darwin" ]]; then |
| 689 | if [ ! -z "${eextra}" ]; |
673 | if [ ! -z "${eextra}" ]; |
| 690 | then |
674 | then |
| 691 | einfo "Extra options are not supported on macos yet" |
675 | einfo "Extra options are not supported on Darwin/OS X yet" |
| 692 | einfo "Please report the ebuild along with the info below" |
676 | einfo "Please report the ebuild along with the info below" |
| 693 | einfo "eextra: ${eextra}" |
677 | einfo "eextra: ${eextra}" |
| 694 | die "Required function missing" |
678 | die "Required function missing" |
| 695 | fi |
679 | fi |
| 696 | |
680 | |
| … | |
… | |
| 701 | [ -z "`egetent group ${egid}`" ] && break |
685 | [ -z "`egetent group ${egid}`" ] && break |
| 702 | done |
686 | done |
| 703 | esac |
687 | esac |
| 704 | dscl . create /groups/${egroup} gid ${egid} |
688 | dscl . create /groups/${egroup} gid ${egid} |
| 705 | dscl . create /groups/${egroup} passwd '*' |
689 | dscl . create /groups/${egroup} passwd '*' |
| 706 | elif use x86-fbsd ; then |
690 | elif [[ "${USERLAND}" == "BSD" ]] ; then |
| 707 | case ${egid} in |
691 | case ${egid} in |
| 708 | *[!0-9]*) # Non numeric |
692 | *[!0-9]*) # Non numeric |
| 709 | for egid in `jot 898 101`; do |
693 | for egid in `jot 898 101`; do |
| 710 | [ -z "`egetent group ${egid}`" ] && break |
694 | [ -z "`egetent group ${egid}`" ] && break |
| 711 | done |
695 | done |
| … | |
… | |
| 858 | *) |
842 | *) |
| 859 | type= |
843 | type= |
| 860 | ;; |
844 | ;; |
| 861 | esac |
845 | esac |
| 862 | fi |
846 | fi |
| 863 | |
847 | if [ "${SLOT}" == "0" ] ; then |
|
|
848 | local desktop_name="${PN}" |
|
|
849 | else |
|
|
850 | local desktop_name="${PN}-${SLOT}" |
|
|
851 | fi |
| 864 | local desktop=${T}/${exec%% *}-${P}.desktop |
852 | local desktop=${T}/${exec%% *}-${desktop_name}.desktop |
| 865 | |
853 | |
| 866 | echo "[Desktop Entry] |
854 | echo "[Desktop Entry] |
| 867 | Encoding=UTF-8 |
855 | Encoding=UTF-8 |
| 868 | Version=0.9.2 |
856 | Version=0.9.2 |
| 869 | Name=${name} |
857 | Name=${name} |
| … | |
… | |
| 1446 | while ((i--)) ; do |
1434 | while ((i--)) ; do |
| 1447 | ewarn "PLEASE UPDATE TO YOUR PACKAGE TO USE linux-info.eclass" |
1435 | ewarn "PLEASE UPDATE TO YOUR PACKAGE TO USE linux-info.eclass" |
| 1448 | done |
1436 | done |
| 1449 | export EUTILS_ECLASS_PORTAGE_ARCH="${ARCH}" |
1437 | export EUTILS_ECLASS_PORTAGE_ARCH="${ARCH}" |
| 1450 | case ${ARCH} in |
1438 | case ${ARCH} in |
| 1451 | x86) export ARCH="i386";; |
1439 | x86) export ARCH="i386";; |
| 1452 | amd64) export ARCH="x86_64";; |
1440 | amd64) export ARCH="x86_64";; |
| 1453 | hppa) export ARCH="parisc";; |
1441 | hppa) export ARCH="parisc";; |
| 1454 | mips) export ARCH="mips";; |
1442 | mips) export ARCH="mips";; |
| 1455 | 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! |
| 1456 | *) export ARCH="${ARCH}";; |
1444 | *) export ARCH="${ARCH}";; |
| 1457 | esac |
1445 | esac |
| 1458 | } |
1446 | } |
| 1459 | |
1447 | |
| 1460 | # set's ARCH back to what portage expects |
1448 | # set's ARCH back to what portage expects |
| 1461 | set_arch_to_portage() { |
1449 | set_arch_to_portage() { |