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

Diff of /eclass/eutils.eclass

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

Revision 1.380 Revision 1.381
1# Copyright 1999-2012 Gentoo Foundation 1# Copyright 1999-2012 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.380 2012/01/31 06:55:37 ulm Exp $ 3# $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.381 2012/02/14 16:01:21 vapier Exp $
4 4
5# @ECLASS: eutils.eclass 5# @ECLASS: eutils.eclass
6# @MAINTAINER: 6# @MAINTAINER:
7# base-system@gentoo.org 7# base-system@gentoo.org
8# @BLURB: many extra (but common) functions that are used in ebuilds 8# @BLURB: many extra (but common) functions that are used in ebuilds
940 # wrap the env here so that the 'insinto' call 940 # wrap the env here so that the 'insinto' call
941 # doesn't corrupt the env of the caller 941 # doesn't corrupt the env of the caller
942 insinto /usr/share/pixmaps 942 insinto /usr/share/pixmaps
943 newins "$@" 943 newins "$@"
944 ) 944 )
945}
946
947# for internal use only (unpack_pdv and unpack_makeself)
948find_unpackable_file() {
949 local src=$1
950 if [[ -z ${src} ]] ; then
951 src=${DISTDIR}/${A}
952 else
953 if [[ -e ${DISTDIR}/${src} ]] ; then
954 src=${DISTDIR}/${src}
955 elif [[ -e ${PWD}/${src} ]] ; then
956 src=${PWD}/${src}
957 elif [[ -e ${src} ]] ; then
958 src=${src}
959 fi
960 fi
961 [[ ! -e ${src} ]] && return 1
962 echo "${src}"
963}
964
965# @FUNCTION: unpack_pdv
966# @USAGE: <file to unpack> <size of off_t>
967# @DESCRIPTION:
968# Unpack those pesky pdv generated files ...
969# They're self-unpacking programs with the binary package stuffed in
970# the middle of the archive. Valve seems to use it a lot ... too bad
971# it seems to like to segfault a lot :(. So lets take it apart ourselves.
972#
973# You have to specify the off_t size ... I have no idea how to extract that
974# information out of the binary executable myself. Basically you pass in
975# the size of the off_t type (in bytes) on the machine that built the pdv
976# archive.
977#
978# One way to determine this is by running the following commands:
979#
980# @CODE
981# strings <pdv archive> | grep lseek
982# strace -elseek <pdv archive>
983# @CODE
984#
985# Basically look for the first lseek command (we do the strings/grep because
986# sometimes the function call is _llseek or something) and steal the 2nd
987# parameter. Here is an example:
988#
989# @CODE
990# vapier@vapier 0 pdv_unpack # strings hldsupdatetool.bin | grep lseek
991# lseek
992# vapier@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin
993# lseek(3, -4, SEEK_END) = 2981250
994# @CODE
995#
996# Thus we would pass in the value of '4' as the second parameter.
997unpack_pdv() {
998 local src=$(find_unpackable_file "$1")
999 local sizeoff_t=$2
1000
1001 [[ -z ${src} ]] && die "Could not locate source for '$1'"
1002 [[ -z ${sizeoff_t} ]] && die "No idea what off_t size was used for this pdv :("
1003
1004 local shrtsrc=$(basename "${src}")
1005 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1006 local metaskip=$(tail -c ${sizeoff_t} "${src}" | hexdump -e \"%i\")
1007 local tailskip=$(tail -c $((${sizeoff_t}*2)) "${src}" | head -c ${sizeoff_t} | hexdump -e \"%i\")
1008
1009 # grab metadata for debug reasons
1010 local metafile=$(emktemp)
1011 tail -c +$((${metaskip}+1)) "${src}" > "${metafile}"
1012
1013 # rip out the final file name from the metadata
1014 local datafile=$(tail -c +$((${metaskip}+1)) "${src}" | strings | head -n 1)
1015 datafile=$(basename "${datafile}")
1016
1017 # now lets uncompress/untar the file if need be
1018 local tmpfile=$(emktemp)
1019 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > ${tmpfile}
1020
1021 local iscompressed=$(file -b "${tmpfile}")
1022 if [[ ${iscompressed:0:8} == "compress" ]] ; then
1023 iscompressed=1
1024 mv ${tmpfile}{,.Z}
1025 gunzip ${tmpfile}
1026 else
1027 iscompressed=0
1028 fi
1029 local istar=$(file -b "${tmpfile}")
1030 if [[ ${istar:0:9} == "POSIX tar" ]] ; then
1031 istar=1
1032 else
1033 istar=0
1034 fi
1035
1036 #for some reason gzip dies with this ... dd cant provide buffer fast enough ?
1037 #dd if=${src} ibs=${metaskip} count=1 \
1038 # | dd ibs=${tailskip} skip=1 \
1039 # | gzip -dc \
1040 # > ${datafile}
1041 if [ ${iscompressed} -eq 1 ] ; then
1042 if [ ${istar} -eq 1 ] ; then
1043 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1044 | head -c $((${metaskip}-${tailskip})) \
1045 | tar -xzf -
1046 else
1047 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1048 | head -c $((${metaskip}-${tailskip})) \
1049 | gzip -dc \
1050 > ${datafile}
1051 fi
1052 else
1053 if [ ${istar} -eq 1 ] ; then
1054 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1055 | head -c $((${metaskip}-${tailskip})) \
1056 | tar --no-same-owner -xf -
1057 else
1058 tail -c +$((${tailskip}+1)) ${src} 2>/dev/null \
1059 | head -c $((${metaskip}-${tailskip})) \
1060 > ${datafile}
1061 fi
1062 fi
1063 true
1064 #[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1065 #assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
1066}
1067
1068# @FUNCTION: unpack_makeself
1069# @USAGE: [file to unpack] [offset] [tail|dd]
1070# @DESCRIPTION:
1071# Unpack those pesky makeself generated files ...
1072# They're shell scripts with the binary package tagged onto
1073# the end of the archive. Loki utilized the format as does
1074# many other game companies.
1075#
1076# If the file is not specified, then ${A} is used. If the
1077# offset is not specified then we will attempt to extract
1078# the proper offset from the script itself.
1079unpack_makeself() {
1080 local src_input=${1:-${A}}
1081 local src=$(find_unpackable_file "${src_input}")
1082 local skip=$2
1083 local exe=$3
1084
1085 [[ -z ${src} ]] && die "Could not locate source for '${src_input}'"
1086
1087 local shrtsrc=$(basename "${src}")
1088 echo ">>> Unpacking ${shrtsrc} to ${PWD}"
1089 if [[ -z ${skip} ]] ; then
1090 local ver=$(grep -m1 -a '#.*Makeself' "${src}" | awk '{print $NF}')
1091 local skip=0
1092 exe=tail
1093 case ${ver} in
1094 1.5.*|1.6.0-nv) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same
1095 skip=$(grep -a ^skip= "${src}" | cut -d= -f2)
1096 ;;
1097 2.0|2.0.1)
1098 skip=$(grep -a ^$'\t'tail "${src}" | awk '{print $2}' | cut -b2-)
1099 ;;
1100 2.1.1)
1101 skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-)
1102 (( skip++ ))
1103 ;;
1104 2.1.2)
1105 skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1)
1106 (( skip++ ))
1107 ;;
1108 2.1.3)
1109 skip=`grep -a ^offset= "${src}" | awk '{print $3}'`
1110 (( skip++ ))
1111 ;;
1112 2.1.4|2.1.5)
1113 skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1)
1114 skip=$(head -n ${skip} "${src}" | wc -c)
1115 exe="dd"
1116 ;;
1117 *)
1118 eerror "I'm sorry, but I was unable to support the Makeself file."
1119 eerror "The version I detected was '${ver}'."
1120 eerror "Please file a bug about the file ${shrtsrc} at"
1121 eerror "http://bugs.gentoo.org/ so that support can be added."
1122 die "makeself version '${ver}' not supported"
1123 ;;
1124 esac
1125 debug-print "Detected Makeself version ${ver} ... using ${skip} as offset"
1126 fi
1127 case ${exe} in
1128 tail) exe="tail -n +${skip} '${src}'";;
1129 dd) exe="dd ibs=${skip} skip=1 if='${src}'";;
1130 *) die "makeself cant handle exe '${exe}'"
1131 esac
1132
1133 # lets grab the first few bytes of the file to figure out what kind of archive it is
1134 local filetype tmpfile=$(emktemp)
1135 eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
1136 filetype=$(file -b "${tmpfile}") || die
1137 case ${filetype} in
1138 *tar\ archive*)
1139 eval ${exe} | tar --no-same-owner -xf -
1140 ;;
1141 bzip2*)
1142 eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
1143 ;;
1144 gzip*)
1145 eval ${exe} | tar --no-same-owner -xzf -
1146 ;;
1147 compress*)
1148 eval ${exe} | gunzip | tar --no-same-owner -xf -
1149 ;;
1150 *)
1151 eerror "Unknown filetype \"${filetype}\" ?"
1152 false
1153 ;;
1154 esac
1155 assert "failure unpacking (${filetype}) makeself ${shrtsrc} ('${ver}' +${skip})"
1156} 945}
1157 946
1158# @FUNCTION: cdrom_get_cds 947# @FUNCTION: cdrom_get_cds
1159# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...] 948# @USAGE: <file on cd1> [file on cd2] [file on cd3] [...]
1160# @DESCRIPTION: 949# @DESCRIPTION:

Legend:
Removed from v.1.380  
changed lines
  Added in v.1.381

  ViewVC Help
Powered by ViewVC 1.1.20