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

Diff of /eclass/eutils.eclass

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

Revision 1.197 Revision 1.212
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.197 2005/09/18 17:33:44 flameeyes Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.212 2005/10/22 02:32:48 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.
166# hand its a directory, it will set EPATCH_SOURCE to this. 166# hand its a directory, it will set EPATCH_SOURCE to this.
167# 167#
168# <azarah@gentoo.org> (10 Nov 2002) 168# <azarah@gentoo.org> (10 Nov 2002)
169# 169#
170epatch() { 170epatch() {
171 _epatch_assert() { local _pipestatus=${PIPESTATUS[*]}; [[ ${_pipestatus// /} -eq 0 ]] ; }
171 local PIPE_CMD="" 172 local PIPE_CMD=""
172 local STDERR_TARGET="${T}/$$.out" 173 local STDERR_TARGET="${T}/$$.out"
173 local PATCH_TARGET="${T}/$$.patch" 174 local PATCH_TARGET="${T}/$$.patch"
174 local PATCH_SUFFIX="" 175 local PATCH_SUFFIX=""
175 local SINGLE_PATCH="no" 176 local SINGLE_PATCH="no"
313 count=5 314 count=5
314 break 315 break
315 fi 316 fi
316 fi 317 fi
317 318
318 if (cat ${PATCH_TARGET} | patch -p${count} ${popts} --dry-run -f) >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 2>&1 319 if (cat ${PATCH_TARGET} | patch -p${count} ${popts} --dry-run -f ; _epatch_assert) >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 2>&1
319 then 320 then
320 draw_line "***** ${patchname} *****" > ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real 321 draw_line "***** ${patchname} *****" > ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
321 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real 322 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
322 echo "ACTUALLY APPLYING ${patchname} ..." >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real 323 echo "ACTUALLY APPLYING ${patchname} ..." >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
323 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real 324 echo >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
324 draw_line "***** ${patchname} *****" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real 325 draw_line "***** ${patchname} *****" >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real
325 326
326 cat ${PATCH_TARGET} | patch -p${count} ${popts} >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real 2>&1 327 cat ${PATCH_TARGET} | patch -p${count} ${popts} >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real 2>&1
328 _epatch_assert
327 329
328 if [ "$?" -ne 0 ] 330 if [ "$?" -ne 0 ]
329 then 331 then
330 cat ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/} 332 cat ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}.real >> ${STDERR_TARGET%/*}/${patchname}-${STDERR_TARGET##*/}
331 echo 333 echo
408# Joe Jezak <josejx@gmail.com> and usata@gentoo.org 410# Joe Jezak <josejx@gmail.com> and usata@gentoo.org
409# FBSD stuff: Aaron Walker <ka0ttic@gentoo.org> 411# FBSD stuff: Aaron Walker <ka0ttic@gentoo.org>
410# 412#
411# egetent(database, key) 413# egetent(database, key)
412egetent() { 414egetent() {
413 if [[ "${USERLAND}" == "Darwin" ]] ; then 415 case ${CHOST} in
416 *-darwin*)
414 case "$2" in 417 case "$2" in
415 *[!0-9]*) # Non numeric 418 *[!0-9]*) # Non numeric
416 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }" 419 nidump $1 . | awk -F":" "{ if (\$1 ~ /^$2$/) {print \$0;exit;} }"
417 ;; 420 ;;
418 *) # Numeric 421 *) # Numeric
419 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }" 422 nidump $1 . | awk -F":" "{ if (\$3 == $2) {print \$0;exit;} }"
420 ;; 423 ;;
421 esac 424 esac
422 elif [[ "${USERLAND}" == "BSD" ]] ; then 425 ;;
423 local action 426 *-freebsd*)
424 if [ "$1" == "passwd" ] 427 local opts action="user"
425 then 428 [[ $1 == "passwd" ]] || action="group"
426 action="user" 429
427 else 430 # lookup by uid/gid
428 action="group" 431 if [[ $2 == [[:digit:]]* ]] ; then
432 [[ ${action} == "user" ]] && opts="-u" || opts="-g"
429 fi 433 fi
434
430 pw show "${action}" "$2" -q 435 pw show ${action} ${opts} "$2" -q
431 else 436 ;;
437 *-netbsd*)
438 grep "$2:\*:" /etc/$1
439 ;;
440 *)
432 which nscd >& /dev/null && nscd -i "$1" 441 type -p nscd >& /dev/null && nscd -i "$1"
433 getent "$1" "$2" 442 getent "$1" "$2"
434 fi 443 ;;
444 esac
435} 445}
436 446
437# Simplify/standardize adding users to the system 447# Simplify/standardize adding users to the system
438# vapier@gentoo.org 448# vapier@gentoo.org
439# 449#
492 if [[ ! -e ${eshell} ]] ; then 502 if [[ ! -e ${eshell} ]] ; then
493 eerror "A shell was specified but it does not exist !" 503 eerror "A shell was specified but it does not exist !"
494 die "${eshell} does not exist" 504 die "${eshell} does not exist"
495 fi 505 fi
496 else 506 else
497 case ${USERLAND} in 507 for shell in /sbin/nologin /usr/sbin/nologin /bin/false /usr/bin/false /dev/null ; do
498 Darwin) eshell="/usr/bin/false";; 508 [[ -x ${ROOT}${shell} ]] && break
499 BSD) eshell="/usr/sbin/nologin";; 509 done
500 *) eshell="/bin/false";; 510
501 esac 511 if [[ ${shell} == "/dev/null" ]] ; then
512 eerror "Unable to identify the shell to use"
513 die "Unable to identify the shell to use"
514 fi
515
516 eshell=${shell}
502 fi 517 fi
503 einfo " - Shell: ${eshell}" 518 einfo " - Shell: ${eshell}"
504 opts="${opts} -s ${eshell}" 519 opts="${opts} -s ${eshell}"
505 520
506 # handle homedir 521 # handle homedir
543 einfo " - Groups: ${egroups}" 558 einfo " - Groups: ${egroups}"
544 559
545 # handle extra and add the user 560 # handle extra and add the user
546 local oldsandbox=${SANDBOX_ON} 561 local oldsandbox=${SANDBOX_ON}
547 export SANDBOX_ON="0" 562 export SANDBOX_ON="0"
548 case ${USERLAND} in 563 case ${CHOST} in
549 Darwin) 564 *-darwin*)
550 ### Make the user 565 ### Make the user
551 if [[ -z $@ ]] ; then 566 if [[ -z $@ ]] ; then
552 dscl . create /users/${euser} uid ${euid} 567 dscl . create /users/${euser} uid ${euid}
553 dscl . create /users/${euser} shell ${eshell} 568 dscl . create /users/${euser} shell ${eshell}
554 dscl . create /users/${euser} home ${ehome} 569 dscl . create /users/${euser} home ${ehome}
565 einfo "Please report the ebuild along with the info below" 580 einfo "Please report the ebuild along with the info below"
566 einfo "eextra: $@" 581 einfo "eextra: $@"
567 die "Required function missing" 582 die "Required function missing"
568 fi 583 fi
569 ;; 584 ;;
570 BSD) 585 *-freebsd*)
571 if [[ -z $@ ]] ; then 586 if [[ -z $@ ]] ; then
572 pw useradd ${euser} ${opts} \ 587 pw useradd ${euser} ${opts} \
573 -c "added by portage for ${PN}" \ 588 -c "added by portage for ${PN}" \
574 die "enewuser failed" 589 die "enewuser failed"
575 else 590 else
576 einfo " - Extra: $@" 591 einfo " - Extra: $@"
577 pw useradd ${euser} ${opts} \ 592 pw useradd ${euser} ${opts} \
578 "$@" || die "enewuser failed" 593 "$@" || die "enewuser failed"
594 fi
595 ;;
596
597 *-netbsd*)
598 if [[ -z $@ ]] ; then
599 useradd ${opts} ${euser} || die "enewuser failed"
600 else
601 einfo " - Extra: $@"
602 useradd ${opts} ${euser} "$@" || die "enewuser failed"
579 fi 603 fi
580 ;; 604 ;;
581 *) 605 *)
582 if [[ -z $@ ]] ; then 606 if [[ -z $@ ]] ; then
583 useradd ${opts} ${euser} \ 607 useradd ${opts} ${euser} \
635 then 659 then
636 if [ "${egid}" -gt 0 ] 660 if [ "${egid}" -gt 0 ]
637 then 661 then
638 if [ -z "`egetent group ${egid}`" ] 662 if [ -z "`egetent group ${egid}`" ]
639 then 663 then
640 if [[ "${USERLAND}" == "Darwin" ]]; then 664 if [[ "${CHOST}" == *-darwin* ]]; then
641 opts="${opts} ${egid}" 665 opts="${opts} ${egid}"
642 else 666 else
643 opts="${opts} -g ${egid}" 667 opts="${opts} -g ${egid}"
644 fi 668 fi
645 else 669 else
659 opts="${opts} ${eextra}" 683 opts="${opts} ${eextra}"
660 684
661 # add the group 685 # add the group
662 local oldsandbox="${SANDBOX_ON}" 686 local oldsandbox="${SANDBOX_ON}"
663 export SANDBOX_ON="0" 687 export SANDBOX_ON="0"
664 if [[ "${USERLAND}" == "Darwin" ]]; then 688 case ${CHOST} in
689 *-darwin*)
665 if [ ! -z "${eextra}" ]; 690 if [ ! -z "${eextra}" ];
666 then 691 then
667 einfo "Extra options are not supported on Darwin/OS X yet" 692 einfo "Extra options are not supported on Darwin/OS X yet"
668 einfo "Please report the ebuild along with the info below" 693 einfo "Please report the ebuild along with the info below"
669 einfo "eextra: ${eextra}" 694 einfo "eextra: ${eextra}"
670 die "Required function missing" 695 die "Required function missing"
671 fi 696 fi
672 697
673 # If we need the next available 698 # If we need the next available
674 case ${egid} in 699 case ${egid} in
675 *[!0-9]*) # Non numeric 700 *[!0-9]*) # Non numeric
676 for egid in $(seq 101 999); do 701 for egid in $(seq 101 999); do
677 [ -z "`egetent group ${egid}`" ] && break 702 [ -z "`egetent group ${egid}`" ] && break
678 done 703 done
679 esac 704 esac
680 dscl . create /groups/${egroup} gid ${egid} 705 dscl . create /groups/${egroup} gid ${egid}
681 dscl . create /groups/${egroup} passwd '*' 706 dscl . create /groups/${egroup} passwd '*'
682 elif [[ "${USERLAND}" == "BSD" ]] ; then 707 ;;
708
709 *-freebsd*)
683 case ${egid} in 710 case ${egid} in
684 *[!0-9]*) # Non numeric 711 *[!0-9]*) # Non numeric
685 for egid in $(seq 101 999); do 712 for egid in $(seq 101 999); do
686 [ -z "`egetent group ${egid}`" ] && break 713 [ -z "`egetent group ${egid}`" ] && break
687 done 714 done
688 esac 715 esac
689 pw groupadd ${egroup} -g ${egid} || die "enewgroup failed" 716 pw groupadd ${egroup} -g ${egid} || die "enewgroup failed"
690 else 717 ;;
718
719 *-netbsd*)
720 case ${egid} in
721 *[!0-9]*) # Non numeric
722 for egid in $(seq 101 999); do
723 [ -z "`egetent group ${egid}`" ] && break
724 done
725 esac
726 groupadd -g ${egid} ${egroup} || die "enewgroup failed"
727 ;;
728
729 *)
691 groupadd ${opts} ${egroup} || die "enewgroup failed" 730 groupadd ${opts} ${egroup} || die "enewgroup failed"
692 fi 731 ;;
732 esac
693 export SANDBOX_ON="${oldsandbox}" 733 export SANDBOX_ON="${oldsandbox}"
694} 734}
695 735
696# Simple script to replace 'dos2unix' binaries 736# Simple script to replace 'dos2unix' binaries
697# vapier@gentoo.org 737# vapier@gentoo.org
850Exec=${exec} 890Exec=${exec}
851Path=${path} 891Path=${path}
852Icon=${icon} 892Icon=${icon}
853Categories=Application;${type};" > "${desktop}" 893Categories=Application;${type};" > "${desktop}"
854 894
895 (
896 # wrap the env here so that the 'insinto' call
897 # doesn't corrupt the env of the caller
855 insinto /usr/share/applications 898 insinto /usr/share/applications
856 doins "${desktop}" 899 doins "${desktop}"
857 900 )
858 return 0
859} 901}
860 902
861# Make a GDM/KDM Session file 903# Make a GDM/KDM Session file
862# 904#
863# make_desktop_entry(<title>, <command>) 905# make_desktop_entry(<title>, <command>)
968 local sizeoff_t=$2 1010 local sizeoff_t=$2
969 1011
970 [[ -z ${src} ]] && die "Could not locate source for '$1'" 1012 [[ -z ${src} ]] && die "Could not locate source for '$1'"
971 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :(" 1013 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :("
972 1014
973 local shrtsrc="`basename ${src}`" 1015 local shrtsrc=$(basename "${src}")
974 echo ">>> Unpacking ${shrtsrc} to ${PWD}" 1016 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
975 local metaskip=`tail -c ${sizeoff_t} ${src} | hexdump -e \"%i\"` 1017 local metaskip=`tail -c ${sizeoff_t} ${src} | hexdump -e \"%i\"`
976 local tailskip=`tail -c $((${sizeoff_t}*2)) ${src} | head -c ${sizeoff_t} | hexdump -e \"%i\"` 1018 local tailskip=`tail -c $((${sizeoff_t}*2)) ${src} | head -c ${sizeoff_t} | hexdump -e \"%i\"`
977 1019
978 # grab metadata for debug reasons 1020 # grab metadata for debug reasons
1050 1092
1051 [[ -z ${src} ]] && die "Could not locate source for '$1'" 1093 [[ -z ${src} ]] && die "Could not locate source for '$1'"
1052 1094
1053 local shrtsrc=$(basename "${src}") 1095 local shrtsrc=$(basename "${src}")
1054 echo ">>> Unpacking ${shrtsrc} to ${PWD}" 1096 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1055 if [ -z "${skip}" ] 1097 if [[ -z ${skip} ]] ; then
1056 then
1057 local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`" 1098 local ver=$(grep -a '#.*Makeself' "${src}" | awk '{print $NF}')
1058 local skip=0 1099 local skip=0
1059 exe=tail 1100 exe=tail
1060 case ${ver} in 1101 case ${ver} in
1061 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same 1102 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
1062 skip=$(grep -a ^skip= "${src}" | cut -d= -f2) 1103 skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
1074 ;; 1115 ;;
1075 2.1.3) 1116 2.1.3)
1076 skip=`grep -a ^offset= "${src}" | awk '{print $3}'` 1117 skip=`grep -a ^offset= "${src}" | awk '{print $3}'`
1077 let skip="skip + 1" 1118 let skip="skip + 1"
1078 ;; 1119 ;;
1079 2.1.4) 1120 2.1.4|2.1.5)
1080 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1) 1121 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1)
1081 skip=$(head -n ${skip} "${src}" | wc -c) 1122 skip=$(head -n ${skip} "${src}" | wc -c)
1082 exe="dd" 1123 exe="dd"
1083 ;; 1124 ;;
1084 *) 1125 *)
1129check_license() { 1170check_license() {
1130 local lic=$1 1171 local lic=$1
1131 if [ -z "${lic}" ] ; then 1172 if [ -z "${lic}" ] ; then
1132 lic="${PORTDIR}/licenses/${LICENSE}" 1173 lic="${PORTDIR}/licenses/${LICENSE}"
1133 else 1174 else
1134 if [ -e "${PORTDIR}/licenses/${src}" ] ; then 1175 if [ -e "${PORTDIR}/licenses/${lic}" ] ; then
1135 lic="${PORTDIR}/licenses/${src}" 1176 lic="${PORTDIR}/licenses/${lic}"
1136 elif [ -e "${PWD}/${src}" ] ; then 1177 elif [ -e "${PWD}/${lic}" ] ; then
1137 lic="${PWD}/${src}" 1178 lic="${PWD}/${lic}"
1138 elif [ -e "${src}" ] ; then 1179 elif [ -e "${lic}" ] ; then
1139 lic="${src}" 1180 lic="${lic}"
1140 fi
1141 fi 1181 fi
1182 fi
1142 [ ! -f "${lic}" ] && die "Could not find requested license ${src}" 1183 [ ! -f "${lic}" ] && die "Could not find requested license ${lic}"
1143 local l="`basename ${lic}`" 1184 local l="`basename ${lic}`"
1144 1185
1145 # here is where we check for the licenses the user already 1186 # here is where we check for the licenses the user already
1146 # accepted ... if we don't find a match, we make the user accept 1187 # accepted ... if we don't find a match, we make the user accept
1147 local shopts=$- 1188 local shopts=$-
1323 local dir=$(dirname "$*") 1364 local dir=$(dirname "$*")
1324 local file=$(basename "$*") 1365 local file=$(basename "$*")
1325 local mline="" 1366 local mline=""
1326 local showedmsg=0 1367 local showedmsg=0
1327 1368
1328 for mline in $(mount | egrep -e '(iso|cdrom)' | awk '{print $3}') ; do 1369 for mline in $(mount | egrep -e '(iso|cdrom|fs=cdfss)' | awk '{print $3}') ; do
1329 [[ -d ${mline}/${dir} ]] || continue 1370 [[ -d ${mline}/${dir} ]] || continue
1330 [[ ! -z $(find ${mline}/${dir} -maxdepth 1 -iname ${file}) ]] \ 1371 [[ ! -z $(find ${mline}/${dir} -maxdepth 1 -iname ${file}) ]] \
1331 && export CDROM_ROOT=${mline} 1372 && export CDROM_ROOT=${mline}
1332 done 1373 done
1333 1374
1577# $4 == extra LD_LIBRARY_PATH's (make it : delimited) 1618# $4 == extra LD_LIBRARY_PATH's (make it : delimited)
1578# $5 == path for wrapper 1619# $5 == path for wrapper
1579make_wrapper() { 1620make_wrapper() {
1580 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5 1621 local wrapper=$1 bin=$2 chdir=$3 libdir=$4 path=$5
1581 local tmpwrapper=$(emktemp) 1622 local tmpwrapper=$(emktemp)
1623 # We don't want to quote ${bin} so that people can pass complex
1624 # things as $bin ... "./someprog --args"
1582 cat << EOF > "${tmpwrapper}" 1625 cat << EOF > "${tmpwrapper}"
1583#!/bin/sh 1626#!/bin/sh
1584cd "${chdir}" 1627cd "${chdir:-.}"
1628if [ -n "${libdir}" ] ; then
1629 if [ "\${LD_LIBRARY_PATH+set}" = "set" ] ; then
1585export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}" 1630 export LD_LIBRARY_PATH="\${LD_LIBRARY_PATH}:${libdir}"
1631 else
1632 export LD_LIBRARY_PATH="${libdir}"
1633 fi
1634fi
1586exec ${bin} "\$@" 1635exec ${bin} "\$@"
1587EOF 1636EOF
1588 chmod go+rx "${tmpwrapper}" 1637 chmod go+rx "${tmpwrapper}"
1589 if [ -n "${5}" ] 1638 if [[ -n ${path} ]] ; then
1590 then
1591 exeinto ${5} 1639 exeinto "${path}"
1592 newexe "${tmpwrapper}" "${wrapper}" 1640 newexe "${tmpwrapper}" "${wrapper}"
1593 else 1641 else
1594 newbin "${tmpwrapper}" "${wrapper}" 1642 newbin "${tmpwrapper}" "${wrapper}"
1595 fi 1643 fi
1596} 1644}

Legend:
Removed from v.1.197  
changed lines
  Added in v.1.212

  ViewVC Help
Powered by ViewVC 1.1.20