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

Diff of /eclass/eutils.eclass

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

Revision 1.181 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.181 2005/06/09 15:25:56 azarah 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.
449# homedir: /dev/null 449# homedir: /dev/null
450# groups: none 450# groups: none
451# extra: comment of 'added by portage for ${PN}' 451# extra: comment of 'added by portage for ${PN}'
452enewuser() { 452enewuser() {
453 # get the username 453 # get the username
454 local euser="$1"; shift 454 local euser=$1; shift
455 if [ -z "${euser}" ] 455 if [[ -z ${euser} ]] ; then
456 then
457 eerror "No username specified !" 456 eerror "No username specified !"
458 die "Cannot call enewuser without a username" 457 die "Cannot call enewuser without a username"
459 fi 458 fi
460 459
461 # lets see if the username already exists 460 # lets see if the username already exists
462 if [ "${euser}" == "`egetent passwd \"${euser}\" | cut -d: -f1`" ] 461 if [[ ${euser} == $(egetent passwd "${euser}" | cut -d: -f1) ]] ; then
463 then
464 return 0 462 return 0
465 fi 463 fi
466 einfo "Adding user '${euser}' to your system ..." 464 einfo "Adding user '${euser}' to your system ..."
467 465
468 # options to pass to useradd 466 # options to pass to useradd
469 local opts= 467 local opts=
470 468
471 # handle uid 469 # handle uid
472 local euid="$1"; shift 470 local euid=$1; shift
473 if [ ! -z "${euid}" ] && [ "${euid}" != "-1" ] 471 if [[ ! -z ${euid} ]] && [[ ${euid} != "-1" ]] ; then
474 then
475 if [ "${euid}" -gt 0 ] 472 if [[ ${euid} -gt 0 ]] ; then
476 then
477 if [ ! -z "`egetent passwd ${euid}`" ] 473 if [[ ! -z $(egetent passwd ${euid}) ]] ; then
478 then
479 euid="next" 474 euid="next"
480 fi 475 fi
481 else 476 else
482 eerror "Userid given but is not greater than 0 !" 477 eerror "Userid given but is not greater than 0 !"
483 die "${euid} is not a valid UID" 478 die "${euid} is not a valid UID"
484 fi 479 fi
485 else 480 else
486 euid="next" 481 euid="next"
487 fi 482 fi
488 if [ "${euid}" == "next" ] 483 if [[ ${euid} == "next" ]] ; then
489 then
490 local pwrange 484 local pwrange
491 if [ "${USERLAND}" == "BSD" ] ; then 485 if [[ ${USERLAND} == "BSD" ]] ; then
492 pwrange="`jot 898 101`" 486 pwrange=$(jot 898 101)
493 else 487 else
494 pwrange="`seq 101 999`" 488 pwrange=$(seq 101 999)
495 fi 489 fi
496 for euid in ${pwrange} ; do 490 for euid in ${pwrange} ; do
497 [ -z "`egetent passwd ${euid}`" ] && break 491 [[ -z $(egetent passwd ${euid}) ]] && break
498 done 492 done
499 fi 493 fi
500 opts="${opts} -u ${euid}" 494 opts="${opts} -u ${euid}"
501 einfo " - Userid: ${euid}" 495 einfo " - Userid: ${euid}"
502 496
503 # handle shell 497 # handle shell
504 local eshell="$1"; shift 498 local eshell=$1; shift
505 if [ ! -z "${eshell}" ] && [ "${eshell}" != "-1" ] 499 if [[ ! -z ${eshell} ]] && [[ ${eshell} != "-1" ]] ; then
506 then
507 if [ ! -e "${eshell}" ] 500 if [[ ! -e ${eshell} ]] ; then
508 then
509 eerror "A shell was specified but it does not exist !" 501 eerror "A shell was specified but it does not exist !"
510 die "${eshell} does not exist" 502 die "${eshell} does not exist"
511 fi 503 fi
512 else 504 else
513 if [[ "${USERLAND}" == "Darwin" ]]; then 505 case ${USERLAND} in
514 eshell="/usr/bin/false" 506 Darwin) eshell="/usr/bin/false";;
515 elif [[ "${USERLAND}" == "BSD" ]]; then
516 eshell="/usr/sbin/nologin" 507 BSD) eshell="/usr/sbin/nologin";;
517 else
518 eshell="/bin/false" 508 *) eshell="/bin/false";;
519 fi 509 esac
520 fi 510 fi
521 einfo " - Shell: ${eshell}" 511 einfo " - Shell: ${eshell}"
522 opts="${opts} -s ${eshell}" 512 opts="${opts} -s ${eshell}"
523 513
524 # handle homedir 514 # handle homedir
525 local ehome="$1"; shift 515 local ehome=$1; shift
526 if [ -z "${ehome}" ] || [ "${ehome}" == "-1" ] 516 if [[ -z ${ehome} ]] || [[ ${ehome} == "-1" ]] ; then
527 then
528 ehome="/dev/null" 517 ehome="/dev/null"
529 fi 518 fi
530 einfo " - Home: ${ehome}" 519 einfo " - Home: ${ehome}"
531 opts="${opts} -d ${ehome}" 520 opts="${opts} -d ${ehome}"
532 521
533 # handle groups 522 # handle groups
534 local egroups="$1"; shift 523 local egroups=$1; shift
535 if [ ! -z "${egroups}" ] 524 if [[ ! -z ${egroups} ]] ; then
536 then
537 local oldifs="${IFS}" 525 local oldifs=${IFS}
538 local defgroup="" exgroups="" 526 local defgroup="" exgroups=""
539 527
540 export IFS="," 528 export IFS=","
541 for g in ${egroups} 529 for g in ${egroups} ; do
542 do
543 export IFS="${oldifs}" 530 export IFS=${oldifs}
544 if [ -z "`egetent group \"${g}\"`" ] 531 if [[ -z $(egetent group "${g}") ]] ; then
545 then
546 eerror "You must add group ${g} to the system first" 532 eerror "You must add group ${g} to the system first"
547 die "${g} is not a valid GID" 533 die "${g} is not a valid GID"
548 fi 534 fi
549 if [ -z "${defgroup}" ] 535 if [[ -z ${defgroup} ]] ; then
550 then
551 defgroup="${g}" 536 defgroup=${g}
552 else 537 else
553 exgroups="${exgroups},${g}" 538 exgroups="${exgroups},${g}"
554 fi 539 fi
555 export IFS="," 540 export IFS=","
556 done 541 done
557 export IFS="${oldifs}" 542 export IFS=${oldifs}
558 543
559 opts="${opts} -g ${defgroup}" 544 opts="${opts} -g ${defgroup}"
560 if [ ! -z "${exgroups}" ] 545 if [[ ! -z ${exgroups} ]] ; then
561 then
562 opts="${opts} -G ${exgroups:1}" 546 opts="${opts} -G ${exgroups:1}"
563 fi 547 fi
564 else 548 else
565 egroups="(none)" 549 egroups="(none)"
566 fi 550 fi
567 einfo " - Groups: ${egroups}" 551 einfo " - Groups: ${egroups}"
568 552
569 # handle extra and add the user 553 # handle extra and add the user
570 local eextra="$@"
571 local oldsandbox="${SANDBOX_ON}" 554 local oldsandbox=${SANDBOX_ON}
572 export SANDBOX_ON="0" 555 export SANDBOX_ON="0"
573 if [[ "${USERLAND}" == "Darwin" ]] 556 case ${USERLAND} in
574 then 557 Darwin)
575 ### Make the user 558 ### Make the user
576 if [ -z "${eextra}" ] 559 if [[ -z $@ ]] ; then
577 then
578 dscl . create /users/${euser} uid ${euid} 560 dscl . create /users/${euser} uid ${euid}
579 dscl . create /users/${euser} shell ${eshell} 561 dscl . create /users/${euser} shell ${eshell}
580 dscl . create /users/${euser} home ${ehome} 562 dscl . create /users/${euser} home ${ehome}
581 dscl . create /users/${euser} realname "added by portage for ${PN}" 563 dscl . create /users/${euser} realname "added by portage for ${PN}"
582 ### Add the user to the groups specified 564 ### Add the user to the groups specified
583 local oldifs="${IFS}" 565 local oldifs=${IFS}
584 export IFS="," 566 export IFS=","
585 for g in ${egroups} 567 for g in ${egroups} ; do
586 do
587 dscl . merge /groups/${g} users ${euser} 568 dscl . merge /groups/${g} users ${euser}
588 done 569 done
589 export IFS="${oldifs}" 570 export IFS=${oldifs}
590 else 571 else
591 einfo "Extra options are not supported on macos yet" 572 einfo "Extra options are not supported on Darwin yet"
592 einfo "Please report the ebuild along with the info below" 573 einfo "Please report the ebuild along with the info below"
593 einfo "eextra: ${eextra}" 574 einfo "eextra: $@"
594 die "Required function missing" 575 die "Required function missing"
595 fi 576 fi
596 elif [[ "${USERLAND}" == "BSD" ]] ; then 577 ;;
597 if [ -z "${eextra}" ] 578 BSD)
598 then 579 if [[ -z $@ ]] ; then
599 pw useradd ${euser} ${opts} \ 580 pw useradd ${euser} ${opts} \
600 -c "added by portage for ${PN}" \ 581 -c "added by portage for ${PN}" \
601 die "enewuser failed" 582 die "enewuser failed"
602 else 583 else
603 einfo " - Extra: ${eextra}" 584 einfo " - Extra: $@"
604 pw useradd ${euser} ${opts} \ 585 pw useradd ${euser} ${opts} \
605 -c ${eextra} || die "enewuser failed" 586 "$@" || die "enewuser failed"
606 fi 587 fi
607 else 588 ;;
608 if [ -z "${eextra}" ] 589 *)
609 then 590 if [[ -z $@ ]] ; then
610 useradd ${opts} ${euser} \ 591 useradd ${opts} ${euser} \
611 -c "added by portage for ${PN}" \ 592 -c "added by portage for ${PN}" \
612 || die "enewuser failed" 593 || die "enewuser failed"
613 else 594 else
614 einfo " - Extra: ${eextra}" 595 einfo " - Extra: $@"
615 useradd ${opts} ${euser} ${eextra} \ 596 useradd ${opts} ${euser} "$@" \
616 || die "enewuser failed" 597 || die "enewuser failed"
617 fi 598 fi
618 fi 599 ;;
600 esac
619 export SANDBOX_ON="${oldsandbox}" 601 export SANDBOX_ON=${oldsandbox}
620 602
621 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ] 603 if [ ! -e "${ehome}" ] && [ ! -e "${D}/${ehome}" ]
622 then 604 then
623 einfo " - Creating ${ehome} in ${D}" 605 einfo " - Creating ${ehome} in ${D}"
624 dodir ${ehome} 606 dodir ${ehome}

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

  ViewVC Help
Powered by ViewVC 1.1.20