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

Diff of /eclass/eutils.eclass

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

Revision 1.83 Revision 1.84
1# Copyright 1999-2004 Gentoo Technologies, Inc. 1# Copyright 1999-2004 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.83 2004/02/27 20:39:19 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.84 2004/02/29 07:17:27 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.
496 then 496 then
497 eerror "No username specified !" 497 eerror "No username specified !"
498 die "Cannot call enewuser without a username" 498 die "Cannot call enewuser without a username"
499 fi 499 fi
500 500
501 # setup a file for testing usernames/groups
502 local tmpfile="`mymktemp ${T}`"
503 chown ${euser} ${tmpfile} >& /dev/null
504 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
505
506 # see if user already exists 501 # lets see if the username already exists
507 if [ "${euser}" == "${realuser}" ] 502 if [ "${euser}" == "`getent passwd \"${euser}\" | cut -d: -f1`" ]
508 then 503 then
509 return 0 504 return 0
510 fi 505 fi
511 einfo "Adding user '${euser}' to your system ..." 506 einfo "Adding user '${euser}' to your system ..."
512 507
517 local euid="$1"; shift 512 local euid="$1"; shift
518 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] 513 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ]
519 then 514 then
520 if [ "${euid}" -gt 0 ] 515 if [ "${euid}" -gt 0 ]
521 then 516 then
522 chown ${euid} ${tmpfile} >& /dev/null 517 if [ ! -z "`getent passwd ${euid}`" ]
523 realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
524 if [ "${realuser//[0-9]}" != "" ]
525 then 518 then
526 euid="uid is taken; using next available" 519 euid="next"
527 else
528 opts="${opts} -u ${euid}"
529 fi 520 fi
530 else 521 else
531 eerror "Userid given but is not greater than 0 !" 522 eerror "Userid given but is not greater than 0 !"
532 die "${euid} is not a valid UID" 523 die "${euid} is not a valid UID"
533 fi 524 fi
534 else 525 else
535 euid="next available" 526 euid="next"
536 fi 527 fi
528 if [ "${euid}" == "next" ]
529 then
530 for euid in `seq 101 999` ; do
531 [ -z "`getent passwd ${euid}`" ] && break
532 done
533 fi
534 opts="${opts} -u ${euid}"
537 einfo " - Userid: ${euid}" 535 einfo " - Userid: ${euid}"
538 536
539 # handle shell 537 # handle shell
540 local eshell="$1"; shift 538 local eshell="$1"; shift
541 if [ ! -z "${eshell}" ] && [ "${eshell}" != "-1" ] 539 if [ ! -z "${eshell}" ] && [ "${eshell}" != "-1" ]
625 then 623 then
626 eerror "No group specified !" 624 eerror "No group specified !"
627 die "Cannot call enewgroup without a group" 625 die "Cannot call enewgroup without a group"
628 fi 626 fi
629 627
630 # setup a file for testing groupname
631 local tmpfile="`mymktemp ${T}`"
632 chgrp ${egroup} ${tmpfile} >& /dev/null
633 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
634
635 # see if group already exists 628 # see if group already exists
636 if [ "${egroup}" == "${realgroup}" ] 629 if [ "${egroup}" == "`getent group \"${egroup}\" | cut -d: -f1`" ]
637 then 630 then
638 return 0 631 return 0
639 fi 632 fi
640 einfo "Adding group '${egroup}' to your system ..." 633 einfo "Adding group '${egroup}' to your system ..."
641 634
646 local egid="$1"; shift 639 local egid="$1"; shift
647 if [ ! -z "${egid}" ] 640 if [ ! -z "${egid}" ]
648 then 641 then
649 if [ "${egid}" -gt 0 ] 642 if [ "${egid}" -gt 0 ]
650 then 643 then
651 chgrp ${egid} ${tmpfile} >& /dev/null 644 if [ -z "`getent group ${egid}`" ]
652 realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
653 if [ "${realuser//[0-9]}" != "" ]
654 then 645 then
655 euid="gid is taken; using next available" 646 opts="${opts} -g ${egid}"
656 else 647 else
657 opts="${opts} -g ${egid}" 648 egid="next available; requested gid taken"
658 fi 649 fi
659 else 650 else
660 eerror "Groupid given but is not greater than 0 !" 651 eerror "Groupid given but is not greater than 0 !"
661 die "${egid} is not a valid GID" 652 die "${egid} is not a valid GID"
662 fi 653 fi

Legend:
Removed from v.1.83  
changed lines
  Added in v.1.84

  ViewVC Help
Powered by ViewVC 1.1.20