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

Diff of /eclass/eutils.eclass

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

Revision 1.33 Revision 1.45
1# Copyright 1999-2003 Gentoo Technologies, Inc. 1# Copyright 1999-2003 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.33 2003/06/12 18:21:23 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.45 2003/07/18 20:43:00 wolf31o2 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.
400 ADMINPARAM="${ADMINPARAM/-j}" 400 ADMINPARAM="${ADMINPARAM/-j}"
401 fi 401 fi
402 402
403 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`" 403 export MAKEOPTS="`echo ${MAKEOPTS} | sed -e 's:-j *[0-9]*::g'`"
404 404
405 if [ "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \ 405 if [ "${ARCH}" = "amd64" -o "${ARCH}" = "x86" -o "${ARCH}" = "hppa" -o \
406 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ] 406 "${ARCH}" = "arm" -o "${ARCH}" = "mips" ]
407 then 407 then
408 # these archs will always have "[Pp]rocessor" 408 # these archs will always have "[Pp]rocessor"
409 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))" 409 jobs="$((`grep -c ^[Pp]rocessor /proc/cpuinfo` * 2))"
410 410
474 local euser="$1"; shift 474 local euser="$1"; shift
475 if [ -z "${euser}" ] ; then 475 if [ -z "${euser}" ] ; then
476 eerror "No username specified !" 476 eerror "No username specified !"
477 die "Cannot call enewuser without a username" 477 die "Cannot call enewuser without a username"
478 fi 478 fi
479 einfo "Adding user '${euser}' to your system ..."
480 479
481 # setup a file for testing usernames/groups 480 # setup a file for testing usernames/groups
482 local tmpfile="`mktemp -p ${T}`" 481 local tmpfile="`mktemp -p ${T}`"
483 touch ${tmpfile} 482 touch ${tmpfile}
484 chown ${euser} ${tmpfile} >& /dev/null 483 chown ${euser} ${tmpfile} >& /dev/null
485 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`" 484 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
486 485
487 # see if user already exists 486 # see if user already exists
488 if [ "${euser}" == "${realuser}" ] ; then 487 if [ "${euser}" == "${realuser}" ] ; then
489 einfo "${euser} already exists on your system :)"
490 return 0 488 return 0
491 fi 489 fi
490 einfo "Adding user '${euser}' to your system ..."
492 491
493 # options to pass to useradd 492 # options to pass to useradd
494 local opts="" 493 local opts=""
495 494
496 # handle uid 495 # handle uid
549 fi 548 fi
550 einfo " - Groups: ${egroups}" 549 einfo " - Groups: ${egroups}"
551 550
552 # handle extra and add the user 551 # handle extra and add the user
553 local eextra="$@" 552 local eextra="$@"
554 local oldsandbox="${oldsandbox}" 553 local oldsandbox=${SANDBOX_ON}
555 export SANDBOX_ON="0" 554 export SANDBOX_ON="0"
556 if [ -z "${eextra}" ] ; then 555 if [ -z "${eextra}" ] ; then
557 useradd ${opts} ${euser} \ 556 useradd ${opts} ${euser} \
558 -c "added by portage for ${PN}" \ 557 -c "added by portage for ${PN}" \
559 || die "enewuser failed" 558 || die "enewuser failed"
565 export SANDBOX_ON="${oldsandbox}" 564 export SANDBOX_ON="${oldsandbox}"
566 565
567 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then 566 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then
568 einfo " - Creating ${ehome} in ${D}" 567 einfo " - Creating ${ehome} in ${D}"
569 dodir ${ehome} 568 dodir ${ehome}
570 fperms ${euser} ${ehome} 569 fowners ${euser} ${ehome}
570 fperms 755 ${ehome}
571 fi 571 fi
572} 572}
573 573
574# Simplify/standardize adding groups to the system 574# Simplify/standardize adding groups to the system
575# vapier@gentoo.org 575# vapier@gentoo.org
585 local egroup="$1"; shift 585 local egroup="$1"; shift
586 if [ -z "${egroup}" ] ; then 586 if [ -z "${egroup}" ] ; then
587 eerror "No group specified !" 587 eerror "No group specified !"
588 die "Cannot call enewgroup without a group" 588 die "Cannot call enewgroup without a group"
589 fi 589 fi
590 einfo "Adding group '${egroup}' to your system ..."
591 590
592 # setup a file for testing groupname 591 # setup a file for testing groupname
593 local tmpfile="`mktemp -p ${T}`" 592 local tmpfile="`mktemp -p ${T}`"
594 touch ${tmpfile} 593 touch ${tmpfile}
595 chgrp ${egroup} ${tmpfile} >& /dev/null 594 chgrp ${egroup} ${tmpfile} >& /dev/null
596 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`" 595 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
597 596
598 # see if group already exists 597 # see if group already exists
599 if [ "${egroup}" == "${realgroup}" ] ; then 598 if [ "${egroup}" == "${realgroup}" ] ; then
600 einfo "${egroup} already exists on your system :)"
601 return 0 599 return 0
602 fi 600 fi
601 einfo "Adding group '${egroup}' to your system ..."
603 602
604 # options to pass to useradd 603 # options to pass to useradd
605 local opts="" 604 local opts=""
606 605
607 # handle gid 606 # handle gid
621 # handle extra 620 # handle extra
622 local eextra="$@" 621 local eextra="$@"
623 opts="${opts} ${eextra}" 622 opts="${opts} ${eextra}"
624 623
625 # add the group 624 # add the group
626 local oldsandbox="${oldsandbox}" 625 local oldsandbox=${SANDBOX_ON}
627 export SANDBOX_ON="0" 626 export SANDBOX_ON="0"
628 groupadd ${opts} ${egroup} || die "enewgroup failed" 627 groupadd ${opts} ${egroup} || die "enewgroup failed"
629 export SANDBOX_ON="${oldsandbox}" 628 export SANDBOX_ON="${oldsandbox}"
630} 629}
631 630
638 cp ${f} ${T}/edos2unix 637 cp ${f} ${T}/edos2unix
639 sed 's/\r$//' ${T}/edos2unix > ${f} 638 sed 's/\r$//' ${T}/edos2unix > ${f}
640 done 639 done
641} 640}
642 641
643# new convinience patch wapper function to eventually replace epatch(), $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and /usr/bin/patch 642# Make a desktop file !
643# Great for making those icons in kde/gnome startmenu !
644# Amaze your friends ! Get the women ! Join today !
645# gnome2 /usr/share/applications
646# gnome1 /usr/share/gnome/apps/
647# KDE ${KDEDIR}/share/applnk /usr/share/applnk
648#
649# make_desktop_entry(<binary>, [name], [icon], [type], [path])
650#
651# binary: what binary does the app run with ?
652# name: the name that will show up in the menu
653# icon: give your little like a pretty little icon ...
654# this can be relative (to /usr/share/pixmaps) or
655# a full path to an icon
656# type: what kind of application is this ? for categories:
657# http://www.freedesktop.org/standards/menu/draft/menu-spec/menu-spec.html
658# path: if your app needs to startup in a specific dir
659make_desktop_entry() {
660 [ -z "$1" ] && eerror "You must specify the executable" && return 1
661
662 local exec=${1}
663 local name=${2:-${PN}}
664 local icon=${3:-${PN}.png}
665 local type=${4}
666 local path=${5:-${GAMES_PREFIX}}
667 if [ -z "${type}" ] ; then
668 case ${CATEGORY} in
669 app-emulation) type=Emulator ;;
670 app-games) type=Game ;;
671 *) type="" ;;
672 esac
673 fi
674 local desktop=${T}/${exec}.desktop
675
676echo "[Desktop Entry]
677Encoding=UTF-8
678Version=0.9.2
679Name=${name}
680Type=Application
681Comment=${DESCRIPTION}
682Exec=${exec}
683Path=${path}
684Icon=${icon}
685Categories=Application;${type};" > ${desktop}
686
687 if [ -d /usr/share/applications ] ; then
688 insinto /usr/share/applications
689 doins ${desktop}
690 fi
691
692 #if [ -d /usr/share/gnome/apps ] ; then
693 # insinto /usr/share/gnome/apps/Games
694 # doins ${desktop}
695 #fi
696
697 #if [ ! -z "`ls /usr/kde/* 2>/dev/null`" ] ; then
698 # for ver in /usr/kde/* ; do
699 # insinto ${ver}/share/applnk/Games
700 # doins ${desktop}
701 # done
702 #fi
703
704 if [ -d /usr/share/applnk ] ; then
705 insinto /usr/share/applnk/${type}
706 doins ${desktop}
707 fi
708
709 return 0
710}
711
712# new convenience patch wrapper function to eventually replace epatch(),
713# $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and
714# /usr/bin/patch
644# Features: 715# Features:
645# - bulk patch handling similar to epatch()'s 716# - bulk patch handling similar to epatch()'s
646# - automatic patch level detection like epatch()'s 717# - automatic patch level detection like epatch()'s
647# - semiautomatic patch uncompression like epatch()'s (may switch to using /usr/bin/file for extra power, instead of just looking at the filename) 718# - automatic patch uncompression like epatch()'s
648# - doesn't have the --dry-run overhead of epatch() - inspects patchfiles manually instead 719# - doesn't have the --dry-run overhead of epatch() - inspects patchfiles
649# - is called from base_src_unpack to handle $PATCHES to avoid defining src_unpack(-) just to use xpatch 720# manually instead
721# - once I decide it's production-ready, it'll be called from base_src_unpack
722# to handle $PATCHES to avoid defining src_unpack just to use xpatch
650 723
651# accepts zero or more parameters specifying patchfiles and/or patchdirs 724# accepts zero or more parameters specifying patchfiles and/or patchdirs
652 725
653# known issues: 726# known issues:
654# - only supports unified style patches (does anyone _really_ use anything else?) 727# - only supports unified style patches (does anyone _really_ use anything
655# - first file addressed in a patch can't have spaces in its name or in the path mentioned in the patchfile 728# else?)
656# (can be easily fixed to be: at least one file addressed in the patch must have no spaces...) 729# - because it doesn't use --dry-run there is a risk of it failing
730# to find the files to patch, ie detect the patchlevel, properly. It doesn't use
731# any of the backup heuristics that patch employs to discover a filename.
732# however, this isn't dangerous because if it works for the developer who's
733# writing the ebuild, it'll always work for the users, and if it doesn't,
734# then we'll fix it :-)
735# - no support as yet for patches applying outside $S (and not directly in $WORKDIR).
657xpatch() { 736xpatch() {
658 737
659 debug-print-function $FUNCNAME $* 738 debug-print-function $FUNCNAME $*
660 739
661 local list="" 740 local list=""
695 *) die "Could not determine filetype of patch $x";; 774 *) die "Could not determine filetype of patch $x";;
696 esac 775 esac
697 debug-print "$FUNCNAME: patchfile=$patchfile" 776 debug-print "$FUNCNAME: patchfile=$patchfile"
698 777
699 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base. 778 # determine patchlevel. supports p0 and higher with either $S or $WORKDIR as base.
700 target="`/bin/grep '+++' $patchfile | /usr/bin/tail -1`" 779 target="`/bin/grep -m 1 '^+++ ' $patchfile`"
701 debug-print "$FUNCNAME: raw target=$target" 780 debug-print "$FUNCNAME: raw target=$target"
702 # strip target down to the path/filename. NOTE doesn't support filenames/paths with spaces in them :-( 781 # strip target down to the path/filename, remove leading +++
703 # remove leading +++ 782 target="${target/+++ }"; target="${target%% *}"
704 target="${target/+++ }"
705 # ugly, yes. i dunno why doesn't this work instead: target=${target%% *}
706 for foo in $target; do target="$foo"; break; done
707 # duplicate slashes are discarded by patch wrt the patchlevel. therefore we need to discard them as well 783 # duplicate slashes are discarded by patch wrt the patchlevel. therefore we need
708 # to calculate the correct patchlevel. 784 # to discard them as well to calculate the correct patchlevel.
709 while [ "$target" != "${target/\/\/}" ]; do
710 target="${target/\/\//\/}" 785 target="${target//\/\//\/}"
711 done
712 debug-print "$FUNCNAME: stripped target=$target" 786 debug-print "$FUNCNAME: stripped target=$target"
713 787
714 # look for target 788 # look for target
715 for basedir in "$S" "$WORKDIR" "`pwd`"; do 789 for basedir in "$S" "$WORKDIR" "${PWD}"; do
716 debug-print "$FUNCNAME: looking in basedir=$basedir" 790 debug-print "$FUNCNAME: looking in basedir=$basedir"
717 cd "$basedir" 791 cd "$basedir"
718 792
719 # try stripping leading directories 793 # try stripping leading directories
720 target2="$target" 794 target2="$target"
750 eend $? 824 eend $?
751 825
752 done 826 done
753 827
754} 828}
829
830# Unpack those pesky makeself generated files ...
831# They're shell scripts with the binary package tagged onto
832# the end of the archive. Loki utilized the format as does
833# many other game companies.
834#
835# Usage: unpack_makeself [file to unpack] [offset]
836# - If the file is not specified then unpack will utilize ${A}.
837# - If the offset is not specified then we will attempt to extract
838# the proper offset from the script itself.
839unpack_makeself() {
840 local src=$1
841 local skip=$2
842
843 [ -z "${src}" ] && src=${A}
844 [ -e ./${src} ] \
845 && src=${PWD}/${src} \
846 || src=${DISTDIR}/${src}
847 local shrtsrc=`basename ${src}`
848 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
849 if [ -z "${skip}" ] ; then
850 local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`"
851 local skip=0
852 case ${ver} in
853 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
854 skip=`grep -a ^skip= ${src} | cut -d= -f2`
855 ;;
856 2.0|2.0.1)
857 skip=`grep -a ^$'\t'tail ${src} | awk '{print $2}' | cut -b2-`
858 ;;
859 2.1.1)
860 skip=`grep -a ^offset= ${src} | awk '{print $2}' | cut -b2-`
861 let skip="skip + 1"
862 ;;
863 *)
864 eerror "I'm sorry, but I was unable to support the Makeself file."
865 eerror "The version I detected was '${ver}'."
866 eerror "Please file a bug about the file ${shrtsrc} at"
867 eerror "http://bugs.gentoo.org/ so that support can be added."
868 die "makeself version '${ver}' not supported"
869 ;;
870 esac
871 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
872 fi
873
874 # we do this because otherwise a failure in gzip will cause 0 bytes to be sent
875 # to tar which will make tar not extract anything and exit with 0
876 local out="`tail +${skip} ${src} | gzip -cd | tar -x --no-same-owner -v -f -`"
877 [ -z "${out}" ] && die "failure unpacking makeself ${shrtsrc} ('${ver}' +${skip})"
878}

Legend:
Removed from v.1.33  
changed lines
  Added in v.1.45

  ViewVC Help
Powered by ViewVC 1.1.20