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

Diff of /eclass/eutils.eclass

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

Revision 1.90 Revision 1.91
1# Copyright 1999-2004 Gentoo Foundation 1# Copyright 1999-2004 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.90 2004/06/25 00:39:48 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.91 2004/07/23 11:11:57 usata 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.
478 touch ${tmp} 478 touch ${tmp}
479 echo ${tmp} 479 echo ${tmp}
480 fi 480 fi
481} 481}
482 482
483# Small wrapper for getent (Linux) and nidump (Mac OS X)
484# used in enewuser()/enewgroup()
485# Joe Jezak <josejx@gmail.com> and usata@gentoo.org
486#
487# egetent(database, key)
488egetent() {
489 if [ "${ARCH}" == "macos" ] ; then
490 case "$2" in
491 *[!0-9]*) # Non numeric
492 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
493 ;;
494 *) # Numeric
495 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
496 ;;
497 esac
498 else
499 getent $1 $2
500 fi
501}
502
483# Simplify/standardize adding users to the system 503# Simplify/standardize adding users to the system
484# vapier@gentoo.org 504# vapier@gentoo.org
485# 505#
486# enewuser(username, uid, shell, homedir, groups, extra options) 506# enewuser(username, uid, shell, homedir, groups, extra options)
487# 507#
501 eerror "No username specified !" 521 eerror "No username specified !"
502 die "Cannot call enewuser without a username" 522 die "Cannot call enewuser without a username"
503 fi 523 fi
504 524
505 # lets see if the username already exists 525 # lets see if the username already exists
506 if [ "${euser}" == "`getent passwd \"${euser}\" | cut -d: -f1`" ] 526 if [ "${euser}" == "`egetent passwd \"${euser}\" | cut -d: -f1`" ]
507 then 527 then
508 return 0 528 return 0
509 fi 529 fi
510 einfo "Adding user '${euser}' to your system ..." 530 einfo "Adding user '${euser}' to your system ..."
511 531
516 local euid="$1"; shift 536 local euid="$1"; shift
517 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] 537 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ]
518 then 538 then
519 if [ "${euid}" -gt 0 ] 539 if [ "${euid}" -gt 0 ]
520 then 540 then
521 if [ ! -z "`getent passwd ${euid}`" ] 541 if [ ! -z "`egetent passwd ${euid}`" ]
522 then 542 then
523 euid="next" 543 euid="next"
524 fi 544 fi
525 else 545 else
526 eerror "Userid given but is not greater than 0 !" 546 eerror "Userid given but is not greater than 0 !"
529 else 549 else
530 euid="next" 550 euid="next"
531 fi 551 fi
532 if [ "${euid}" == "next" ] 552 if [ "${euid}" == "next" ]
533 then 553 then
534 for euid in `seq 101 999` ; do 554 local pwrange
555 if [ "${ARCH}" == "macos" ] ; then
556 pwrange="`jot 898 101`"
557 else
558 pwrange="`seq 101 999`"
559 fi
560 for euid in ${pwrange} ; do
535 [ -z "`getent passwd ${euid}`" ] && break 561 [ -z "`egetent passwd ${euid}`" ] && break
536 done 562 done
537 fi 563 fi
538 opts="${opts} -u ${euid}" 564 opts="${opts} -u ${euid}"
539 einfo " - Userid: ${euid}" 565 einfo " - Userid: ${euid}"
540 566
568 then 594 then
569 local oldifs="${IFS}" 595 local oldifs="${IFS}"
570 export IFS="," 596 export IFS=","
571 for g in ${egroups} 597 for g in ${egroups}
572 do 598 do
573 if [ -z "`getent group \"${g}\"`" ] 599 if [ -z "`egetent group \"${g}\"`" ]
574 then 600 then
575 eerror "You must add group ${g} to the system first" 601 eerror "You must add group ${g} to the system first"
576 die "${g} is not a valid GID" 602 die "${g} is not a valid GID"
577 fi 603 fi
578 done 604 done
585 611
586 # handle extra and add the user 612 # handle extra and add the user
587 local eextra="$@" 613 local eextra="$@"
588 local oldsandbox="${SANDBOX_ON}" 614 local oldsandbox="${SANDBOX_ON}"
589 export SANDBOX_ON="0" 615 export SANDBOX_ON="0"
616 if [ "${ARCH}" == "macos" ];
617 then
618 ### Make the user
590 if [ -z "${eextra}" ] 619 if [ -z "${eextra}" ]
591 then 620 then
621 dscl . create /users/${euser} uid ${euid}
622 dscl . create /users/${euser} shell ${eshell}
623 dscl . create /users/${euser} home ${ehome}
624 dscl . create /users/${euser} realname "added by portage for ${PN}"
625 ### Add the user to the groups specified
626 for g in ${egroups}
627 do
628 dscl . merge /groups/${g} users ${euser}
629 done
630 else
631 einfo "Extra options are not supported on macos yet"
632 einfo "Please report the ebuild along with the info below"
633 einfo "eextra: ${eextra}"
634 die "Required function missing"
635 fi
636 else
637 if [ -z "${eextra}" ]
638 then
592 useradd ${opts} ${euser} \ 639 useradd ${opts} ${euser} \
593 -c "added by portage for ${PN}" \ 640 -c "added by portage for ${PN}" \
594 || die "enewuser failed" 641 || die "enewuser failed"
595 else 642 else
596 einfo " - Extra: ${eextra}" 643 einfo " - Extra: ${eextra}"
597 useradd ${opts} ${euser} ${eextra} \ 644 useradd ${opts} ${euser} ${eextra} \
598 || die "enewuser failed" 645 || die "enewuser failed"
646 fi
599 fi 647 fi
600 export SANDBOX_ON="${oldsandbox}" 648 export SANDBOX_ON="${oldsandbox}"
601 649
602 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ] 650 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ]
603 then 651 then
625 eerror "No group specified !" 673 eerror "No group specified !"
626 die "Cannot call enewgroup without a group" 674 die "Cannot call enewgroup without a group"
627 fi 675 fi
628 676
629 # see if group already exists 677 # see if group already exists
630 if [ "${egroup}" == "`getent group \"${egroup}\" | cut -d: -f1`" ] 678 if [ "${egroup}" == "`egetent group \"${egroup}\" | cut -d: -f1`" ]
631 then 679 then
632 return 0 680 return 0
633 fi 681 fi
634 einfo "Adding group '${egroup}' to your system ..." 682 einfo "Adding group '${egroup}' to your system ..."
635 683
640 local egid="$1"; shift 688 local egid="$1"; shift
641 if [ ! -z "${egid}" ] 689 if [ ! -z "${egid}" ]
642 then 690 then
643 if [ "${egid}" -gt 0 ] 691 if [ "${egid}" -gt 0 ]
644 then 692 then
645 if [ -z "`getent group ${egid}`" ] 693 if [ -z "`egetent group ${egid}`" ]
646 then 694 then
695 if [ "${ARCH}" == "macos" ] ; then
696 opts="${opts} ${egid}"
697 else
647 opts="${opts} -g ${egid}" 698 opts="${opts} -g ${egid}"
699 fi
648 else 700 else
649 egid="next available; requested gid taken" 701 egid="next available; requested gid taken"
650 fi 702 fi
651 else 703 else
652 eerror "Groupid given but is not greater than 0 !" 704 eerror "Groupid given but is not greater than 0 !"
662 opts="${opts} ${eextra}" 714 opts="${opts} ${eextra}"
663 715
664 # add the group 716 # add the group
665 local oldsandbox="${SANDBOX_ON}" 717 local oldsandbox="${SANDBOX_ON}"
666 export SANDBOX_ON="0" 718 export SANDBOX_ON="0"
719 if [ "${ARCH}" == "macos" ];
720 then
721 if [ ! -z "${eextra}" ];
722 then
723 einfo "Extra options are not supported on macos yet"
724 einfo "Please report the ebuild along with the info below"
725 einfo "eextra: ${eextra}"
726 die "Required function missing"
727 fi
728
729 # If we need the next available
730 case ${egid} in
731 *[!0-9]*) # Non numeric
732 for egid in `jot 898 101`; do
733 [ -z "`egetent group ${egid}`" ] && break
734 done
735 esac
736 dscl . create /groups/${egroup} gid ${egid}
737 dscl . create /groups/${egroup} passwd '*'
738 else
667 groupadd ${opts} ${egroup} || die "enewgroup failed" 739 groupadd ${opts} ${egroup} || die "enewgroup failed"
740 fi
668 export SANDBOX_ON="${oldsandbox}" 741 export SANDBOX_ON="${oldsandbox}"
669} 742}
670 743
671# Simple script to replace 'dos2unix' binaries 744# Simple script to replace 'dos2unix' binaries
672# vapier@gentoo.org 745# vapier@gentoo.org

Legend:
Removed from v.1.90  
changed lines
  Added in v.1.91

  ViewVC Help
Powered by ViewVC 1.1.20