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

Diff of /eclass/eutils.eclass

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

Revision 1.35 Revision 1.52
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.35 2003/06/22 05:44:04 drobbins Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.52 2003/09/13 19:24:21 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.
10# NB: If you add anything, please comment it! 10# NB: If you add anything, please comment it!
11 11
12ECLASS=eutils 12ECLASS=eutils
13INHERITED="$INHERITED $ECLASS" 13INHERITED="$INHERITED $ECLASS"
14 14
15DEPEND="$DEPEND !bootstrap? ( sys-devel/patch )" 15newdepend "!bootstrap? ( sys-devel/patch )"
16 16
17DESCRIPTION="Based on the ${ECLASS} eclass" 17DESCRIPTION="Based on the ${ECLASS} eclass"
18 18
19# This function generate linker scripts in /usr/lib for dynamic 19# This function generate linker scripts in /usr/lib for dynamic
20# libs in /lib. This is to fix linking problems when you have 20# libs in /lib. This is to fix linking problems when you have
454 export MAKEOPTS="${MAKEOPTS} -j${jobs}" 454 export MAKEOPTS="${MAKEOPTS} -j${jobs}"
455 fi 455 fi
456 fi 456 fi
457} 457}
458 458
459# Cheap replacement for when debianutils (and thus mktemp)
460# do not exist on the users system
461# vapier@gentoo.org
462#
463# Takes just 1 parameter (the directory to create tmpfile in)
464mymktemp() {
465 local topdir=$1
466 [ -z "${topdir}" ] && topdir=/tmp
467 if [ `which mktemp 2>/dev/null` ] ; then
468 mktemp -p ${topdir}
469 else
470 local tmp="${topdir}/tmp.${RANDOM}.${RANDOM}.${RANDOM}"
471 touch ${tmp}
472 echo ${tmp}
473 fi
474}
475
459# Simplify/standardize adding users to the system 476# Simplify/standardize adding users to the system
460# vapier@gentoo.org 477# vapier@gentoo.org
461# 478#
462# enewuser(username, uid, shell, homedir, groups, extra options) 479# enewuser(username, uid, shell, homedir, groups, extra options)
463# 480#
474 local euser="$1"; shift 491 local euser="$1"; shift
475 if [ -z "${euser}" ] ; then 492 if [ -z "${euser}" ] ; then
476 eerror "No username specified !" 493 eerror "No username specified !"
477 die "Cannot call enewuser without a username" 494 die "Cannot call enewuser without a username"
478 fi 495 fi
479 einfo "Adding user '${euser}' to your system ..."
480 496
481 # setup a file for testing usernames/groups 497 # setup a file for testing usernames/groups
482 local tmpfile="`mktemp -p ${T}`" 498 local tmpfile="`mymktemp ${T}`"
483 touch ${tmpfile}
484 chown ${euser} ${tmpfile} >& /dev/null 499 chown ${euser} ${tmpfile} >& /dev/null
485 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`" 500 local realuser="`ls -l ${tmpfile} | awk '{print $3}'`"
486 501
487 # see if user already exists 502 # see if user already exists
488 if [ "${euser}" == "${realuser}" ] ; then 503 if [ "${euser}" == "${realuser}" ] ; then
489 einfo "${euser} already exists on your system :)"
490 return 0 504 return 0
491 fi 505 fi
506 einfo "Adding user '${euser}' to your system ..."
492 507
493 # options to pass to useradd 508 # options to pass to useradd
494 local opts="" 509 local opts=""
495 510
496 # handle uid 511 # handle uid
549 fi 564 fi
550 einfo " - Groups: ${egroups}" 565 einfo " - Groups: ${egroups}"
551 566
552 # handle extra and add the user 567 # handle extra and add the user
553 local eextra="$@" 568 local eextra="$@"
554 local oldsandbox="${oldsandbox}" 569 local oldsandbox=${SANDBOX_ON}
555 export SANDBOX_ON="0" 570 export SANDBOX_ON="0"
556 if [ -z "${eextra}" ] ; then 571 if [ -z "${eextra}" ] ; then
557 useradd ${opts} ${euser} \ 572 useradd ${opts} ${euser} \
558 -c "added by portage for ${PN}" \ 573 -c "added by portage for ${PN}" \
559 || die "enewuser failed" 574 || die "enewuser failed"
565 export SANDBOX_ON="${oldsandbox}" 580 export SANDBOX_ON="${oldsandbox}"
566 581
567 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then 582 if [ ! -e ${ehome} ] && [ ! -e ${D}/${ehome} ] ; then
568 einfo " - Creating ${ehome} in ${D}" 583 einfo " - Creating ${ehome} in ${D}"
569 dodir ${ehome} 584 dodir ${ehome}
570 fperms ${euser} ${ehome} 585 fowners ${euser} ${ehome}
586 fperms 755 ${ehome}
571 fi 587 fi
572} 588}
573 589
574# Simplify/standardize adding groups to the system 590# Simplify/standardize adding groups to the system
575# vapier@gentoo.org 591# vapier@gentoo.org
585 local egroup="$1"; shift 601 local egroup="$1"; shift
586 if [ -z "${egroup}" ] ; then 602 if [ -z "${egroup}" ] ; then
587 eerror "No group specified !" 603 eerror "No group specified !"
588 die "Cannot call enewgroup without a group" 604 die "Cannot call enewgroup without a group"
589 fi 605 fi
590 einfo "Adding group '${egroup}' to your system ..."
591 606
592 # setup a file for testing groupname 607 # setup a file for testing groupname
593 local tmpfile="`mktemp -p ${T}`" 608 local tmpfile="`mymktemp ${T}`"
594 touch ${tmpfile}
595 chgrp ${egroup} ${tmpfile} >& /dev/null 609 chgrp ${egroup} ${tmpfile} >& /dev/null
596 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`" 610 local realgroup="`ls -l ${tmpfile} | awk '{print $4}'`"
597 611
598 # see if group already exists 612 # see if group already exists
599 if [ "${egroup}" == "${realgroup}" ] ; then 613 if [ "${egroup}" == "${realgroup}" ] ; then
600 einfo "${egroup} already exists on your system :)"
601 return 0 614 return 0
602 fi 615 fi
616 einfo "Adding group '${egroup}' to your system ..."
603 617
604 # options to pass to useradd 618 # options to pass to useradd
605 local opts="" 619 local opts=""
606 620
607 # handle gid 621 # handle gid
621 # handle extra 635 # handle extra
622 local eextra="$@" 636 local eextra="$@"
623 opts="${opts} ${eextra}" 637 opts="${opts} ${eextra}"
624 638
625 # add the group 639 # add the group
626 local oldsandbox="${oldsandbox}" 640 local oldsandbox=${SANDBOX_ON}
627 export SANDBOX_ON="0" 641 export SANDBOX_ON="0"
628 groupadd ${opts} ${egroup} || die "enewgroup failed" 642 groupadd ${opts} ${egroup} || die "enewgroup failed"
629 export SANDBOX_ON="${oldsandbox}" 643 export SANDBOX_ON="${oldsandbox}"
630} 644}
631 645
636edos2unix() { 650edos2unix() {
637 for f in $@ ; do 651 for f in $@ ; do
638 cp ${f} ${T}/edos2unix 652 cp ${f} ${T}/edos2unix
639 sed 's/\r$//' ${T}/edos2unix > ${f} 653 sed 's/\r$//' ${T}/edos2unix > ${f}
640 done 654 done
655}
656
657# Make a desktop file !
658# Great for making those icons in kde/gnome startmenu !
659# Amaze your friends ! Get the women ! Join today !
660# gnome2 /usr/share/applications
661# gnome1 /usr/share/gnome/apps/
662# KDE ${KDEDIR}/share/applnk /usr/share/applnk
663#
664# make_desktop_entry(<binary>, [name], [icon], [type], [path])
665#
666# binary: what binary does the app run with ?
667# name: the name that will show up in the menu
668# icon: give your little like a pretty little icon ...
669# this can be relative (to /usr/share/pixmaps) or
670# a full path to an icon
671# type: what kind of application is this ? for categories:
672# http://www.freedesktop.org/standards/menu/draft/menu-spec/menu-spec.html
673# path: if your app needs to startup in a specific dir
674make_desktop_entry() {
675 [ -z "$1" ] && eerror "You must specify the executable" && return 1
676
677 local exec=${1}
678 local name=${2:-${PN}}
679 local icon=${3:-${PN}.png}
680 local type=${4}
681 local path=${5:-${GAMES_PREFIX}}
682 if [ -z "${type}" ] ; then
683 case ${CATEGORY} in
684 app-emulation) type=Emulator ;;
685 app-games) type=Game ;;
686 *) type="" ;;
687 esac
688 fi
689 local desktop=${T}/${exec}.desktop
690
691echo "[Desktop Entry]
692Encoding=UTF-8
693Version=0.9.2
694Name=${name}
695Type=Application
696Comment=${DESCRIPTION}
697Exec=${exec}
698Path=${path}
699Icon=${icon}
700Categories=Application;${type};" > ${desktop}
701
702 if [ -d /usr/share/applications ] ; then
703 insinto /usr/share/applications
704 doins ${desktop}
705 fi
706
707 #if [ -d /usr/share/gnome/apps ] ; then
708 # insinto /usr/share/gnome/apps/Games
709 # doins ${desktop}
710 #fi
711
712 #if [ ! -z "`ls /usr/kde/* 2>/dev/null`" ] ; then
713 # for ver in /usr/kde/* ; do
714 # insinto ${ver}/share/applnk/Games
715 # doins ${desktop}
716 # done
717 #fi
718
719 if [ -d /usr/share/applnk ] ; then
720 insinto /usr/share/applnk/${type}
721 doins ${desktop}
722 fi
723
724 return 0
641} 725}
642 726
643# new convenience patch wrapper function to eventually replace epatch(), 727# new convenience patch wrapper function to eventually replace epatch(),
644# $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and 728# $PATCHES, $PATCHES1, src_unpack:patch, src_unpack:autopatch and
645# /usr/bin/patch 729# /usr/bin/patch
755 eend $? 839 eend $?
756 840
757 done 841 done
758 842
759} 843}
844
845# Unpack those pesky makeself generated files ...
846# They're shell scripts with the binary package tagged onto
847# the end of the archive. Loki utilized the format as does
848# many other game companies.
849#
850# Usage: unpack_makeself [file to unpack] [offset]
851# - If the file is not specified then unpack will utilize ${A}.
852# - If the offset is not specified then we will attempt to extract
853# the proper offset from the script itself.
854unpack_makeself() {
855 local src=$1
856 local skip=$2
857
858 if [ -z "${src}" ] ; then
859 src="${DISTDIR}/${A}"
860 else
861 if [ -e "${DISTDIR}/${src}" ] ; then
862 src="${DISTDIR}/${src}"
863 elif [ -e "${PWD}/${src}" ] ; then
864 src="${PWD}/${src}"
865 elif [ -e "${src}" ] ; then
866 src="${src}"
867 fi
868 fi
869 [ ! -e "${src}" ] && die "Could not find requested makeself archive ${src}"
870
871 local shrtsrc=`basename ${src}`
872 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
873 if [ -z "${skip}" ] ; then
874 local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`"
875 local skip=0
876 case ${ver} in
877 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
878 skip=`grep -a ^skip= ${src} | cut -d= -f2`
879 ;;
880 2.0|2.0.1)
881 skip=`grep -a ^$'\t'tail ${src} | awk '{print $2}' | cut -b2-`
882 ;;
883 2.1.1)
884 skip=`grep -a ^offset= ${src} | awk '{print $2}' | cut -b2-`
885 let skip="skip + 1"
886 ;;
887 2.1.2)
888 skip=`grep -a ^offset= ${src} | awk '{print $3}' | head -n 1`
889 let skip="skip + 1"
890 ;;
891 2.1.3)
892 skip=`grep -a ^offset= ${src} | awk '{print $3}'`
893 let skip="skip + 1"
894 ;;
895 *)
896 eerror "I'm sorry, but I was unable to support the Makeself file."
897 eerror "The version I detected was '${ver}'."
898 eerror "Please file a bug about the file ${shrtsrc} at"
899 eerror "http://bugs.gentoo.org/ so that support can be added."
900 die "makeself version '${ver}' not supported"
901 ;;
902 esac
903 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
904 fi
905
906 # we do this because otherwise a failure in gzip will cause 0 bytes to be sent
907 # to tar which will make tar not extract anything and exit with 0
908 tail -n +${skip} ${src} | gzip -cd | tar -x --no-same-owner -f - 2>/dev/null
909 local pipestatus="${PIPESTATUS[*]}"
910 pipestatus="${pipestatus// }"
911 if [ "${pipestatus//0}" != "" ] ; then
912 # maybe it isnt gzipped ... they usually are, but not always ...
913 tail -n +${skip} ${src} | tar -x --no-same-owner -f - \
914 || die "failure unpacking makeself ${shrtsrc} ('${ver}' +${skip})"
915 fi
916}

Legend:
Removed from v.1.35  
changed lines
  Added in v.1.52

  ViewVC Help
Powered by ViewVC 1.1.20