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

Diff of /eclass/eutils.eclass

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

Revision 1.67 Revision 1.70
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.67 2003/11/18 18:45:04 vapier Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.70 2003/11/30 11:22:32 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.
896 896
897 done 897 done
898 898
899} 899}
900 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 the file if need be
963 local tmpfile="`mymktemp ${T}`"
964 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile}
965 local filetype="`file -b ${tmpfile}`"
966 case ${filetype} in
967 compress*)
968 #for some reason gzip dies with this ... dd cant provide buffer fast enough ?
969 #dd if=${src} ibs=${metaskip} count=1 \
970 # | dd ibs=${tailskip} skip=1 \
971 # | gzip -dc \
972 # > ${datafile}
973 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
974 | head -c $((${metaskip}-${tailskip})) \
975 | gzip -dc \
976 > ${datafile}
977 ;;
978 *)
979 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
980 | head -c $((${metaskip}-${tailskip})) \
981 > ${datafile}
982 #dd if=${src} ibs=${metaskip} count=1 \
983 # | dd ibs=${tailskip} skip=1 of=${datafile}
984 ;;
985 esac
986 [ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
987 #assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
988}
989
901# Unpack those pesky makeself generated files ... 990# Unpack those pesky makeself generated files ...
902# They're shell scripts with the binary package tagged onto 991# They're shell scripts with the binary package tagged onto
903# the end of the archive. Loki utilized the format as does 992# the end of the archive. Loki utilized the format as does
904# many other game companies. 993# many other game companies.
905# 994#
906# Usage: unpack_makeself [file to unpack] [offset] 995# Usage: unpack_makeself [file to unpack] [offset]
907# - If the file is not specified then unpack will utilize ${A}. 996# - If the file is not specified then unpack will utilize ${A}.
908# - If the offset is not specified then we will attempt to extract 997# - If the offset is not specified then we will attempt to extract
909# the proper offset from the script itself. 998# the proper offset from the script itself.
910unpack_makeself() { 999unpack_makeself() {
911 local src="$1" 1000 local src="`find_unpackable_file $1`"
912 local skip="$2" 1001 local skip="$2"
913
914 if [ -z "${src}" ]
915 then
916 src="${DISTDIR}/${A}"
917 else
918 if [ -e "${DISTDIR}/${src}" ]
919 then
920 src="${DISTDIR}/${src}"
921 elif [ -e "${PWD}/${src}" ]
922 then
923 src="${PWD}/${src}"
924 elif [ -e "${src}" ]
925 then
926 src="${src}"
927 fi
928 fi
929 [ ! -e "${src}" ] && die "Could not find requested makeself archive ${src}"
930 1002
931 local shrtsrc="`basename ${src}`" 1003 local shrtsrc="`basename ${src}`"
932 echo ">>> Unpacking ${shrtsrc} to ${PWD}" 1004 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
933 if [ -z "${skip}" ] 1005 if [ -z "${skip}" ]
934 then 1006 then
962 ;; 1034 ;;
963 esac 1035 esac
964 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset" 1036 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
965 fi 1037 fi
966 1038
967 # we do this because otherwise a failure in gzip will cause 0 bytes to be sent 1039 # lets grab the first few bytes of the file to figure out what kind of archive it is
968 # to tar which will make tar not extract anything and exit with 0 1040 local tmpfile="`mymktemp ${T}`"
969 tail -n +${skip} ${src} 2>/dev/null \ 1041 tail -n +${skip} ${src} 2>/dev/null | head -c 512 > ${tmpfile}
970 | gzip -cd 2>/dev/null \ 1042 local filetype="`file -b ${tmpfile}`"
971 | tar -x --no-same-owner -f - 2>/dev/null 1043 case ${filetype} in
972 local pipestatus="${PIPESTATUS[*]}" 1044 *tar\ archive)
973 pipestatus="${pipestatus// }" 1045 tail -n +${skip} ${src} | tar -xf -
974 if [ "${pipestatus//0}" != "" ] 1046 ;;
975 then 1047 bzip2*)
976 # maybe it isnt gzipped ... they usually are, but not always ... 1048 tail -n +${skip} ${src} | bzip2 -dc | tar -xf -
977 tail -n +${skip} ${src} 2>/dev/null \ 1049 ;;
978 | tar -x --no-same-owner -f - 2>/dev/null 1050 gzip*)
979 pipestatus="${pipestatus// }" 1051 tail -n +${skip} ${src} | tar -xzf -
980 if [ "${pipestatus//0}" != "" ] 1052 ;;
981 then 1053 *)
982 # and every once in a while they are bzipped2 ... 1054 false
983 tail -n +${skip} ${src} 2>/dev/null \ 1055 ;;
984 | bunzip2 -c 2>/dev/null \ 1056 esac
985 | tar -x --no-same-owner -f - 2>/dev/null \
986 || die "failure unpacking makeself ${shrtsrc} ('${ver}' +${skip})" 1057 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
987 fi
988 fi
989} 1058}
990 1059
991# Display a license for user to accept. 1060# Display a license for user to accept.
992# 1061#
993# Usage: check_license [license] 1062# Usage: check_license [license]

Legend:
Removed from v.1.67  
changed lines
  Added in v.1.70

  ViewVC Help
Powered by ViewVC 1.1.20