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

Diff of /eclass/eutils.eclass

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

Revision 1.59 Revision 1.73
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.59 2003/09/22 22:44:49 azarah Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.73 2003/12/01 20:13:00 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.
529 fi 529 fi
530 einfo " - Userid: ${euid}" 530 einfo " - Userid: ${euid}"
531 531
532 # handle shell 532 # handle shell
533 local eshell="$1"; shift 533 local eshell="$1"; shift
534 if [ ! -z "${eshell}" ] 534 if [ ! -z "${eshell}" ] && [ "${eshell}" != "-1" ]
535 then 535 then
536 if [ ! -e "${eshell}" ] 536 if [ ! -e "${eshell}" ]
537 then 537 then
538 eerror "A shell was specified but it does not exist !" 538 eerror "A shell was specified but it does not exist !"
539 die "${eshell} does not exist" 539 die "${eshell} does not exist"
544 einfo " - Shell: ${eshell}" 544 einfo " - Shell: ${eshell}"
545 opts="${opts} -s ${eshell}" 545 opts="${opts} -s ${eshell}"
546 546
547 # handle homedir 547 # handle homedir
548 local ehome="$1"; shift 548 local ehome="$1"; shift
549 if [ -z "${ehome}" ] 549 if [ -z "${ehome}" ] && [ "${eshell}" != "-1" ]
550 then 550 then
551 ehome="/dev/null" 551 ehome="/dev/null"
552 fi 552 fi
553 einfo " - Home: ${ehome}" 553 einfo " - Home: ${ehome}"
554 opts="${opts} -d ${ehome}" 554 opts="${opts} -d ${ehome}"
665# Simple script to replace 'dos2unix' binaries 665# Simple script to replace 'dos2unix' binaries
666# vapier@gentoo.org 666# vapier@gentoo.org
667# 667#
668# edos2unix(file, <more files>...) 668# edos2unix(file, <more files>...)
669edos2unix() { 669edos2unix() {
670 for f in $@ 670 for f in "$@"
671 do 671 do
672 cp ${f} ${T}/edos2unix 672 cp "${f}" ${T}/edos2unix
673 sed 's/\r$//' ${T}/edos2unix > ${f} 673 sed 's/\r$//' ${T}/edos2unix > "${f}"
674 done 674 done
675} 675}
676 676
677# Make a desktop file ! 677# Make a desktop file !
678# Great for making those icons in kde/gnome startmenu ! 678# Great for making those icons in kde/gnome startmenu !
705 "app-emulation") 705 "app-emulation")
706 type=Emulator 706 type=Emulator
707 ;; 707 ;;
708 "games-"*) 708 "games-"*)
709 type=Game 709 type=Game
710 ;;
711 "net-"*)
712 type=Network;
710 ;; 713 ;;
711 *) 714 *)
712 type= 715 type=
713 ;; 716 ;;
714 esac 717 esac
893 896
894 done 897 done
895 898
896} 899}
897 900
901# for internal use only (unpack_pdv and unpack_makeself)
902find_unpackable_file() {
903 local src="$1"
904 if [ -z "${src}" ]
905 then
906 src="${DISTDIR}/${A}"
907 else
908 if [ -e "${DISTDIR}/${src}" ]
909 then
910 src="${DISTDIR}/${src}"
911 elif [ -e "${PWD}/${src}" ]
912 then
913 src="${PWD}/${src}"
914 elif [ -e "${src}" ]
915 then
916 src="${src}"
917 fi
918 fi
919 [ ! -e "${src}" ] && die "Could not find requested archive ${src}"
920 echo "${src}"
921}
922
923# Unpack those pesky pdv generated files ...
924# They're self-unpacking programs with the binary package stuffed in
925# the middle of the archive. Valve seems to use it a lot ... too bad
926# it seems to like to segfault a lot :(. So lets take it apart ourselves.
927#
928# Usage: unpack_pdv [file to unpack] [size of off_t]
929# - you have to specify the off_t size ... i have no idea how to extract that
930# information out of the binary executable myself. basically you pass in
931# the size of the off_t type (in bytes) on the machine that built the pdv
932# archive. one way to determine this is by running the following commands:
933# strings <pdv archive> | grep lseek
934# strace -elseek <pdv archive>
935# basically look for the first lseek command (we do the strings/grep because
936# sometimes the function call is _llseek or something) and steal the 2nd
937# parameter. here is an example:
938# root@vapier 0 pdv_unpack # strings hldsupdatetool.bin | grep lseek
939# lseek
940# root@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin
941# lseek(3, -4, SEEK_END) = 2981250
942# thus we would pass in the value of '4' as the second parameter.
943unpack_pdv() {
944 local src="`find_unpackable_file $1`"
945 local sizeoff_t="$2"
946
947 [ -z "${sizeoff_t}" ] && die "No idea what off_t size was used for this pdv :("
948
949 local shrtsrc="`basename ${src}`"
950 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
951 local metaskip=`tail -c ${sizeoff_t} ${src} | hexdump -e \"%i\"`
952 local tailskip=`tail -c $((${sizeoff_t}*2)) ${src} | head -c ${sizeoff_t} | hexdump -e \"%i\"`
953
954 # grab metadata for debug reasons
955 local metafile="`mymktemp ${T}`"
956 tail -c +$((${metaskip}+1)) ${src} > ${metafile}
957
958 # rip out the final file name from the metadata
959 local datafile="`tail -c +$((${metaskip}+1)) ${src} | strings | head -n 1`"
960 datafile="`basename ${datafile}`"
961
962 # now lets uncompress/untar the file if need be
963 local tmpfile="`mymktemp ${T}`"
964 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile}
965
966 local iscompressed="`file -b ${tmpfile}`"
967 if [ "${iscompressed:0:8}" == "compress" ] ; then
968 iscompressed=1
969 mv ${tmpfile}{,.Z}
970 gunzip ${tmpfile}
971 else
972 iscompressed=0
973 fi
974 local istar="`file -b ${tmpfile}`"
975 if [ "${istar:0:9}" == "POSIX tar" ] ; then
976 istar=1
977 else
978 istar=0
979 fi
980
981 #for some reason gzip dies with this ... dd cant provide buffer fast enough ?
982 #dd if=${src} ibs=${metaskip} count=1 \
983 # | dd ibs=${tailskip} skip=1 \
984 # | gzip -dc \
985 # > ${datafile}
986 if [ ${iscompressed} -eq 1 ] ; then
987 if [ ${istar} -eq 1 ] ; then
988 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
989 | head -c $((${metaskip}-${tailskip})) \
990 | tar -xzf -
991 else
992 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
993 | head -c $((${metaskip}-${tailskip})) \
994 | gzip -dc \
995 > ${datafile}
996 fi
997 else
998 if [ ${istar} -eq 1 ] ; then
999 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1000 | head -c $((${metaskip}-${tailskip})) \
1001 | tar --no-same-owner -xf -
1002 else
1003 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1004 | head -c $((${metaskip}-${tailskip})) \
1005 > ${datafile}
1006 fi
1007 fi
1008 true
1009 #[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1010 #assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1011}
1012
898# Unpack those pesky makeself generated files ... 1013# Unpack those pesky makeself generated files ...
899# They're shell scripts with the binary package tagged onto 1014# They're shell scripts with the binary package tagged onto
900# the end of the archive. Loki utilized the format as does 1015# the end of the archive. Loki utilized the format as does
901# many other game companies. 1016# many other game companies.
902# 1017#
903# Usage: unpack_makeself [file to unpack] [offset] 1018# Usage: unpack_makeself [file to unpack] [offset]
904# - If the file is not specified then unpack will utilize ${A}. 1019# - If the file is not specified then unpack will utilize ${A}.
905# - If the offset is not specified then we will attempt to extract 1020# - If the offset is not specified then we will attempt to extract
906# the proper offset from the script itself. 1021# the proper offset from the script itself.
907unpack_makeself() { 1022unpack_makeself() {
908 local src="$1" 1023 local src="`find_unpackable_file $1`"
909 local skip="$2" 1024 local skip="$2"
910
911 if [ -z "${src}" ]
912 then
913 src="${DISTDIR}/${A}"
914 else
915 if [ -e "${DISTDIR}/${src}" ]
916 then
917 src="${DISTDIR}/${src}"
918 elif [ -e "${PWD}/${src}" ]
919 then
920 src="${PWD}/${src}"
921 elif [ -e "${src}" ]
922 then
923 src="${src}"
924 fi
925 fi
926 [ ! -e "${src}" ] && die "Could not find requested makeself archive ${src}"
927 1025
928 local shrtsrc="`basename ${src}`" 1026 local shrtsrc="`basename ${src}`"
929 echo ">>> Unpacking ${shrtsrc} to ${PWD}" 1027 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
930 if [ -z "${skip}" ] 1028 if [ -z "${skip}" ]
931 then 1029 then
959 ;; 1057 ;;
960 esac 1058 esac
961 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset" 1059 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
962 fi 1060 fi
963 1061
964 # we do this because otherwise a failure in gzip will cause 0 bytes to be sent 1062 # lets grab the first few bytes of the file to figure out what kind of archive it is
965 # to tar which will make tar not extract anything and exit with 0 1063 local tmpfile="`mymktemp ${T}`"
966 tail -n +${skip} ${src} | gzip -cd | tar -x --no-same-owner -f - 2>/dev/null 1064 tail -n +${skip} ${src} 2>/dev/null | head -c 512 > ${tmpfile}
967 local pipestatus="${PIPESTATUS[*]}" 1065 local filetype="`file -b ${tmpfile}`"
968 pipestatus="${pipestatus// }" 1066 case ${filetype} in
969 if [ "${pipestatus//0}" != "" ] 1067 *tar\ archive)
970 then
971 # maybe it isnt gzipped ... they usually are, but not always ...
972 tail -n +${skip} ${src} | tar -x --no-same-owner -f - \ 1068 tail -n +${skip} ${src} | tar --no-same-owner -xf -
1069 ;;
1070 bzip2*)
1071 tail -n +${skip} ${src} | bzip2 -dc | tar --no-same-owner -xf -
1072 ;;
1073 gzip*)
1074 tail -n +${skip} ${src} | tar --no-same-owner -xzf -
1075 ;;
1076 *)
1077 false
1078 ;;
1079 esac
973 || die "failure unpacking makeself ${shrtsrc} ('${ver}' +${skip})" 1080 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
974 fi
975} 1081}
976 1082
977# Display a license for user to accept. 1083# Display a license for user to accept.
978# 1084#
979# Usage: check_license [license] 1085# Usage: check_license [license]
980# - If the file is not specified then ${LICENSE} is used. 1086# - If the file is not specified then ${LICENSE} is used.
981check_license() { 1087check_license() {
982 local src="$1" 1088 local lic=$1
983
984 if [ -z "${src}" ] 1089 if [ -z "${lic}" ] ; then
985 then
986 src="${PORTDIR}/licenses/${LICENSE}" 1090 lic="${PORTDIR}/licenses/${LICENSE}"
987 else 1091 else
988 if [ -e "${PORTDIR}/licenses/${src}" ] 1092 if [ -e "${PORTDIR}/licenses/${src}" ] ; then
989 then
990 src="${PORTDIR}/licenses/${src}" 1093 lic="${PORTDIR}/licenses/${src}"
991 elif [ -e "${PWD}/${src}" ] 1094 elif [ -e "${PWD}/${src}" ] ; then
992 then
993 src="${PWD}/${src}" 1095 lic="${PWD}/${src}"
994 elif [ -e "${src}" ] 1096 elif [ -e "${src}" ] ; then
995 then
996 src="${src}" 1097 lic="${src}"
997 fi
998 fi 1098 fi
1099 fi
999 [ ! -e "${src}" ] && die "Could not find requested license ${src}" 1100 [ ! -f "${lic}" ] && die "Could not find requested license ${src}"
1101 local l="`basename ${lic}`"
1000 1102
1001 # here is where we check for the license... 1103 # here is where we check for the licenses the user already
1002 # if we don't find one, we ask the user for it 1104 # accepted ... if we don't find a match, we make the user accept
1003 if [ ! -d "/usr/share/licenses" ] 1105 local alic
1004 then 1106 for alic in ${ACCEPT_LICENSE} ; do
1005 mkdir -p /usr/share/licenses 1107 [ "${alic}" == "*" ] && return 0
1006 fi 1108 [ "${alic}" == "${l}" ] && return 0
1007 if [ -f "/usr/share/licenses/${LICENSE}" ] 1109 done
1008 then 1110
1009 einfo "The license for this application has already been accepted." 1111 local licmsg="`mymktemp ${T}`"
1010 else 1112 cat << EOF > ${licmsg}
1113**********************************************************
1114The following license outlines the terms of use of this
1011 ewarn "You MUST accept this license for installation to continue." 1115package. You MUST accept this license for installation to
1116continue. When you are done viewing, hit 'q'. If you
1012 eerror "If you CTRL+C out of this, the install will not run!" 1117CTRL+C out of this, the install will not run!
1013 echo 1118**********************************************************
1014 1119
1015 ${PAGER} ${src} || die "Could not execute ${PAGER} ${src}" 1120EOF
1121 cat ${lic} >> ${licmsg}
1122 ${PAGER:-less} ${licmsg} || die "Could not execute pager (${PAGER}) to accept ${lic}"
1016 einfo "Do you accept the terms of this license? [yes/no]" 1123 einfon "Do you accept the terms of this license (${l})? [yes/no] "
1017 read ACCEPT_TERMS 1124 read alic
1018 case ${ACCEPT_TERMS} in 1125 case ${alic} in
1019 "yes"|"Yes"|"y"|"Y") 1126 yes|Yes|y|Y)
1020 cp ${src} /usr/share/licenses 1127 return 0
1021 exit 0
1022 ;; 1128 ;;
1023 *) 1129 *)
1130 echo;echo;echo
1024 eerror "You MUST accept the license to continue! Exiting!" 1131 eerror "You MUST accept the license to continue! Exiting!"
1025 die "Failed to accept license" 1132 die "Failed to accept license"
1026 ;; 1133 ;;
1027 esac 1134 esac
1028 fi
1029} 1135}
1030

Legend:
Removed from v.1.59  
changed lines
  Added in v.1.73

  ViewVC Help
Powered by ViewVC 1.1.20