| 1 | # Copyright 1999-2004 Gentoo Foundation |
1 | # Copyright 1999-2004 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.111 2004/10/04 05:40:01 eradicator Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/eutils.eclass,v 1.112 2004/10/05 03:43:02 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. |
| … | |
… | |
| 1085 | # Unpack those pesky makeself generated files ... |
1085 | # Unpack those pesky makeself generated files ... |
| 1086 | # They're shell scripts with the binary package tagged onto |
1086 | # They're shell scripts with the binary package tagged onto |
| 1087 | # the end of the archive. Loki utilized the format as does |
1087 | # the end of the archive. Loki utilized the format as does |
| 1088 | # many other game companies. |
1088 | # many other game companies. |
| 1089 | # |
1089 | # |
| 1090 | # Usage: unpack_makeself [file to unpack] [offset] |
1090 | # Usage: unpack_makeself [file to unpack] [offset] [tail|dd] |
| 1091 | # - If the file is not specified then unpack will utilize ${A}. |
1091 | # - If the file is not specified then unpack will utilize ${A}. |
| 1092 | # - If the offset is not specified then we will attempt to extract |
1092 | # - If the offset is not specified then we will attempt to extract |
| 1093 | # the proper offset from the script itself. |
1093 | # the proper offset from the script itself. |
| 1094 | unpack_makeself() { |
1094 | unpack_makeself() { |
| 1095 | local src="`find_unpackable_file $1`" |
1095 | local src="$(find_unpackable_file "$1")" |
| 1096 | local skip="$2" |
1096 | local skip="$2" |
|
|
1097 | local exe="$3" |
| 1097 | |
1098 | |
| 1098 | local shrtsrc="`basename ${src}`" |
1099 | local shrtsrc="$(basename "${src}")" |
| 1099 | echo ">>> Unpacking ${shrtsrc} to ${PWD}" |
1100 | echo ">>> Unpacking ${shrtsrc} to ${PWD}" |
| 1100 | if [ -z "${skip}" ] |
1101 | if [ -z "${skip}" ] |
| 1101 | then |
1102 | then |
| 1102 | local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`" |
1103 | local ver="`grep -a '#.*Makeself' ${src} | awk '{print $NF}'`" |
| 1103 | local skip=0 |
1104 | local skip=0 |
|
|
1105 | exe=tail |
| 1104 | case ${ver} in |
1106 | case ${ver} in |
| 1105 | 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same |
1107 | 1.5.*) # tested 1.5.{3,4,5} ... guessing 1.5.x series is same |
| 1106 | skip=`grep -a ^skip= ${src} | cut -d= -f2` |
1108 | skip=$(grep -a ^skip= "${src}" | cut -d= -f2) |
| 1107 | ;; |
1109 | ;; |
| 1108 | 2.0|2.0.1) |
1110 | 2.0|2.0.1) |
| 1109 | skip=`grep -a ^$'\t'tail ${src} | awk '{print $2}' | cut -b2-` |
1111 | skip=$(grep -a ^$'\t'tail "${src}" | awk '{print $2}' | cut -b2-) |
| 1110 | ;; |
1112 | ;; |
| 1111 | 2.1.1) |
1113 | 2.1.1) |
| 1112 | skip=`grep -a ^offset= ${src} | awk '{print $2}' | cut -b2-` |
1114 | skip=$(grep -a ^offset= "${src}" | awk '{print $2}' | cut -b2-) |
| 1113 | let skip="skip + 1" |
1115 | let skip="skip + 1" |
| 1114 | ;; |
1116 | ;; |
| 1115 | 2.1.2) |
1117 | 2.1.2) |
| 1116 | skip=`grep -a ^offset= ${src} | awk '{print $3}' | head -n 1` |
1118 | skip=$(grep -a ^offset= "${src}" | awk '{print $3}' | head -n 1) |
| 1117 | let skip="skip + 1" |
1119 | let skip="skip + 1" |
| 1118 | ;; |
1120 | ;; |
| 1119 | 2.1.3) |
1121 | 2.1.3) |
| 1120 | skip=`grep -a ^offset= ${src} | awk '{print $3}'` |
1122 | skip=`grep -a ^offset= "${src}" | awk '{print $3}'` |
| 1121 | let skip="skip + 1" |
1123 | let skip="skip + 1" |
|
|
1124 | ;; |
|
|
1125 | 2.1.4) |
|
|
1126 | skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1) |
|
|
1127 | skip=$(head -n ${skip} "${src}" | wc -c) |
|
|
1128 | exe="dd" |
| 1122 | ;; |
1129 | ;; |
| 1123 | *) |
1130 | *) |
| 1124 | eerror "I'm sorry, but I was unable to support the Makeself file." |
1131 | eerror "I'm sorry, but I was unable to support the Makeself file." |
| 1125 | eerror "The version I detected was '${ver}'." |
1132 | eerror "The version I detected was '${ver}'." |
| 1126 | eerror "Please file a bug about the file ${shrtsrc} at" |
1133 | eerror "Please file a bug about the file ${shrtsrc} at" |
| … | |
… | |
| 1128 | die "makeself version '${ver}' not supported" |
1135 | die "makeself version '${ver}' not supported" |
| 1129 | ;; |
1136 | ;; |
| 1130 | esac |
1137 | esac |
| 1131 | debug-print "Detected Makeself version ${ver} ... using ${skip} as offset" |
1138 | debug-print "Detected Makeself version ${ver} ... using ${skip} as offset" |
| 1132 | fi |
1139 | fi |
|
|
1140 | case ${exe} in |
|
|
1141 | tail) exe="tail -n +${skip} '${src}'";; |
|
|
1142 | dd) exe="dd ibs=${skip} skip=1 obs=1024 conv=sync if='${src}'";; |
|
|
1143 | *) die "makeself cant handle exe '${exe}'" |
|
|
1144 | esac |
| 1133 | |
1145 | |
| 1134 | # lets grab the first few bytes of the file to figure out what kind of archive it is |
1146 | # lets grab the first few bytes of the file to figure out what kind of archive it is |
| 1135 | local tmpfile="`mymktemp ${T}`" |
1147 | local tmpfile="$(mymktemp "${T}")" |
| 1136 | tail -n +${skip} ${src} 2>/dev/null | head -c 512 > ${tmpfile} |
1148 | eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}" |
| 1137 | local filetype="`file -b ${tmpfile}`" |
1149 | local filetype="$(file -b "${tmpfile}")" |
| 1138 | case ${filetype} in |
1150 | case ${filetype} in |
| 1139 | *tar\ archive) |
1151 | *tar\ archive) |
| 1140 | tail -n +${skip} ${src} | tar --no-same-owner -xf - |
1152 | eval ${exe} | tar --no-same-owner -xf - |
| 1141 | ;; |
1153 | ;; |
| 1142 | bzip2*) |
1154 | bzip2*) |
| 1143 | tail -n +${skip} ${src} | bzip2 -dc | tar --no-same-owner -xf - |
1155 | eval ${exe} | bzip2 -dc | tar --no-same-owner -xf - |
| 1144 | ;; |
1156 | ;; |
| 1145 | gzip*) |
1157 | gzip*) |
| 1146 | tail -n +${skip} ${src} | tar --no-same-owner -xzf - |
1158 | eval ${exe} | tar --no-same-owner -xzf - |
| 1147 | ;; |
1159 | ;; |
| 1148 | compress*) |
1160 | compress*) |
| 1149 | tail -n +${skip} ${src} | gunzip | tar --no-same-owner -xf - |
1161 | eval ${exe} | gunzip | tar --no-same-owner -xf - |
| 1150 | ;; |
1162 | ;; |
| 1151 | *) |
1163 | *) |
| 1152 | eerror "Unknown filetype \"${filetype}\" ?" |
1164 | eerror "Unknown filetype \"${filetype}\" ?" |
| 1153 | false |
1165 | false |
| 1154 | ;; |
1166 | ;; |