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

Diff of /eclass/eutils.eclass

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

Revision 1.180 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.180 2005/06/03 21:58:01 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
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}'
451enewuser() { 452enewuser() {
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}" == "Darwin" ]]; then 505 case ${USERLAND} in
513 eshell="/usr/bin/false" 506 Darwin) eshell="/usr/bin/false";;
514 elif [[ "${USERLAND}" == "BSD" ]]; then
515 eshell="/usr/sbin/nologin" 507 BSD) eshell="/usr/sbin/nologin";;
516 else
517 eshell="/bin/false" 508 *) eshell="/bin/false";;
518 fi 509 esac
519 fi 510 fi
520 einfo " - Shell: ${eshell}" 511 einfo " - Shell: ${eshell}"
521 opts="${opts} -s ${eshell}" 512 opts="${opts} -s ${eshell}"
522 513
523 # handle homedir 514 # handle homedir
524 local ehome="$1"; shift 515 local ehome=$1; shift
525 if [ -z "${ehome}" ] || [ "${ehome}" == "-1" ] 516 if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then
526 then
527 ehome="/dev/null" 517 ehome="/dev/null"
528 fi 518 fi
529 einfo " - Home: ${ehome}" 519 einfo " - Home: ${ehome}"
530 opts="${opts} -d ${ehome}" 520 opts="${opts} -d ${ehome}"
531 521
532 # handle groups 522 # handle groups
533 local egroups="$1"; shift 523 local egroups=$1; shift
534 if [ ! -z "${egroups}" ] 524 if [[ ! -z ${egroups} ]] ; then
535 then
536 local oldifs="${IFS}" 525 local oldifs=${IFS}
537 local defgroup="" exgroups="" 526 local defgroup="" exgroups=""
538 527
539 export IFS="," 528 export IFS=","
540 for g in ${egroups} 529 for g in ${egroups} ; do
541 do
542 export IFS="${oldifs}" 530 export IFS=${oldifs}
543 if [ -z "`egetent group \"${g}\"`" ] 531 if [[ -z $(egetent group "${g}") ]] ; then
544 then
545 eerror "You must add group ${g} to the system first" 532 eerror "You must add group ${g} to the system first"
546 die "${g} is not a valid GID" 533 die "${g} is not a valid GID"
547 fi 534 fi
548 if [ -z "${defgroup}" ] 535 if [[ -z ${defgroup} ]] ; then
549 then
550 defgroup="${g}" 536 defgroup=${g}
551 else 537 else
552 exgroups="${exgroups},${g}" 538 exgroups="${exgroups},${g}"
553 fi 539 fi
554 export IFS="," 540 export IFS=","
555 done 541 done
556 export IFS="${oldifs}" 542 export IFS=${oldifs}
557 543
558 opts="${opts} -g ${defgroup}" 544 opts="${opts} -g ${defgroup}"
559 if [ ! -z "${exgroups}" ] 545 if [[ ! -z ${exgroups} ]] ; then
560 then
561 opts="${opts} -G ${exgroups:1}" 546 opts="${opts} -G ${exgroups:1}"
562 fi 547 fi
563 else 548 else
564 egroups="(none)" 549 egroups="(none)"
565 fi 550 fi
566 einfo " - Groups: ${egroups}" 551 einfo " - Groups: ${egroups}"
567 552
568 # handle extra and add the user 553 # handle extra and add the user
569 local eextra="$@"
570 local oldsandbox="${SANDBOX_ON}" 554 local oldsandbox=${SANDBOX_ON}
571 export SANDBOX_ON="0" 555 export SANDBOX_ON="0"
572 if [[ "${USERLAND}" == "Darwin" ]] 556 case ${USERLAND} in
573 then 557 Darwin)
574 ### Make the user 558 ### Make the user
575 if [ -z "${eextra}" ] 559 if [[ -z $@ ]] ; then
576 then
577 dscl . create /users/${euser} uid ${euid} 560 dscl . create /users/${euser} uid ${euid}
578 dscl . create /users/${euser} shell ${eshell} 561 dscl . create /users/${euser} shell ${eshell}
579 dscl . create /users/${euser} home ${ehome} 562 dscl . create /users/${euser} home ${ehome}
580 dscl . create /users/${euser} realname "added by portage for ${PN}" 563 dscl . create /users/${euser} realname "added by portage for ${PN}"
581 ### Add the user to the groups specified 564 ### Add the user to the groups specified
582 local oldifs="${IFS}" 565 local oldifs=${IFS}
583 export IFS="," 566 export IFS=","
584 for g in ${egroups} 567 for g in ${egroups} ; do
585 do
586 dscl . merge /groups/${g} users ${euser} 568 dscl . merge /groups/${g} users ${euser}
587 done 569 done
588 export IFS="${oldifs}" 570 export IFS=${oldifs}
589 else 571 else
590 einfo "Extra options are not supported on macos yet" 572 einfo "Extra options are not supported on Darwin yet"
591 einfo "Please report the ebuild along with the info below" 573 einfo "Please report the ebuild along with the info below"
592 einfo "eextra: ${eextra}" 574 einfo "eextra: $@"
593 die "Required function missing" 575 die "Required function missing"
594 fi 576 fi
595 elif [[ "${USERLAND}" == "BSD" ]] ; then 577 ;;
596 if [ -z "${eextra}" ] 578 BSD)
597 then 579 if [[ -z $@ ]] ; then
598 pw useradd ${euser} ${opts} \ 580 pw useradd ${euser} ${opts} \
599 -c "added by portage for ${PN}" \ 581 -c "added by portage for ${PN}" \
600 die "enewuser failed" 582 die "enewuser failed"
601 else 583 else
602 einfo " - Extra: ${eextra}" 584 einfo " - Extra: $@"
603 pw useradd ${euser} ${opts} \ 585 pw useradd ${euser} ${opts} \
604 -c ${eextra} || die "enewuser failed" 586 "$@" || die "enewuser failed"
605 fi 587 fi
606 else 588 ;;
607 if [ -z "${eextra}" ] 589 *)
608 then 590 if [[ -z $@ ]] ; then
609 useradd ${opts} ${euser} \ 591 useradd ${opts} ${euser} \
610 -c "added by portage for ${PN}" \ 592 -c "added by portage for ${PN}" \
611 || die "enewuser failed" 593 || die "enewuser failed"
612 else 594 else
613 einfo " - Extra: ${eextra}" 595 einfo " - Extra: $@"
614 useradd ${opts} ${euser} ${eextra} \ 596 useradd ${opts} ${euser} "$@" \
615 || die "enewuser failed" 597 || die "enewuser failed"
616 fi 598 fi
617 fi 599 ;;
600 esac
618 export SANDBOX_ON="${oldsandbox}" 601 export SANDBOX_ON=${oldsandbox}
619 602
620 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ] 603 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ]
621 then 604 then
622 einfo " - Creating ${ehome} in ${D}" 605 einfo " - Creating ${ehome} in ${D}"
623 dodir ${ehome} 606 dodir ${ehome}

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

  ViewVC Help
Powered by ViewVC 1.1.20