| 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/unpacker.eclass,v 1.2 2012/02/05 05:48:00 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/unpacker.eclass,v 1.10 2012/08/22 01:41:12 ottxor Exp $ |
| 4 | |
4 | |
| 5 | # @ECLASS: unpacker.eclass |
5 | # @ECLASS: unpacker.eclass |
| 6 | # @MAINTAINER: |
6 | # @MAINTAINER: |
| 7 | # base-system@gentoo.org |
7 | # base-system@gentoo.org |
| 8 | # @BLURB: helpers for extraneous file formats and consistent behavior across EAPIs |
8 | # @BLURB: helpers for extraneous file formats and consistent behavior across EAPIs |
| … | |
… | |
| 194 | ;; |
194 | ;; |
| 195 | 2.1.3) |
195 | 2.1.3) |
| 196 | skip=`grep -a ^offset= "${src}" | awk '{print $3}'` |
196 | skip=`grep -a ^offset= "${src}" | awk '{print $3}'` |
| 197 | (( skip++ )) |
197 | (( skip++ )) |
| 198 | ;; |
198 | ;; |
| 199 | 2.1.4|2.1.5) |
199 | 2.1.4|2.1.5|2.1.6) |
| 200 | skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1) |
200 | skip=$(grep -a offset=.*head.*wc "${src}" | awk '{print $3}' | head -n 1) |
| 201 | skip=$(head -n ${skip} "${src}" | wc -c) |
201 | skip=$(head -n ${skip} "${src}" | wc -c) |
| 202 | exe="dd" |
202 | exe="dd" |
| 203 | ;; |
203 | ;; |
| 204 | *) |
204 | *) |
| … | |
… | |
| 251 | |
251 | |
| 252 | local deb=$(find_unpackable_file "$1") |
252 | local deb=$(find_unpackable_file "$1") |
| 253 | |
253 | |
| 254 | unpack_banner "${deb}" |
254 | unpack_banner "${deb}" |
| 255 | |
255 | |
|
|
256 | # on AIX ar doesn't work out as their ar used a different format |
|
|
257 | # from what GNU ar (and thus what .deb files) produce |
|
|
258 | if [[ -n ${EPREFIX} ]] ; then |
|
|
259 | { |
|
|
260 | read # global header |
|
|
261 | [[ ${REPLY} = "!<arch>" ]] || die "${deb} does not seem to be a deb archive" |
|
|
262 | local f timestamp uid gid mode size magic |
|
|
263 | while read f timestamp uid gid mode size magic ; do |
|
|
264 | [[ -n ${f} && -n ${size} ]] || continue # ignore empty lines |
|
|
265 | if [[ ${f} = "data.tar"* ]] ; then |
|
|
266 | head -c "${size}" > "${f}" |
|
|
267 | else |
|
|
268 | head -c "${size}" > /dev/null # trash it |
|
|
269 | fi |
|
|
270 | done |
|
|
271 | } < "${deb}" |
|
|
272 | else |
| 256 | ar x "${deb}" |
273 | ar x "${deb}" |
|
|
274 | fi |
|
|
275 | |
| 257 | unpack ./data.tar* |
276 | unpacker ./data.tar* |
|
|
277 | } |
|
|
278 | |
|
|
279 | # @FUNCTION: unpack_cpio |
|
|
280 | # @USAGE: <one cpio to unpack> |
|
|
281 | # @DESCRIPTION: |
|
|
282 | # Unpack a cpio archive, file "-" means stdin. |
|
|
283 | unpack_cpio() { |
|
|
284 | [[ $# -eq 1 ]] || die "Usage: ${FUNCNAME} <file>" |
|
|
285 | |
|
|
286 | # needed as cpio always reads from stdin |
|
|
287 | local cpio_cmd=( cpio --make-directories --extract --preserve-modification-time ) |
|
|
288 | if [[ $1 == "-" ]] ; then |
|
|
289 | unpack_banner "stdin" |
|
|
290 | "${cpio_cmd[@]}" |
|
|
291 | else |
|
|
292 | local cpio=$(find_unpackable_file "$1") |
|
|
293 | unpack_banner "${cpio}" |
|
|
294 | "${cpio_cmd[@]}" <"${cpio}" |
|
|
295 | fi |
| 258 | } |
296 | } |
| 259 | |
297 | |
| 260 | # @FUNCTION: _unpacker |
298 | # @FUNCTION: _unpacker |
| 261 | # @USAGE: <one archive to unpack> |
299 | # @USAGE: <one archive to unpack> |
| 262 | # @INTERNAL |
300 | # @INTERNAL |
| … | |
… | |
| 271 | a=$(find_unpackable_file "${a}") |
309 | a=$(find_unpackable_file "${a}") |
| 272 | |
310 | |
| 273 | # first figure out the decompression method |
311 | # first figure out the decompression method |
| 274 | case ${m} in |
312 | case ${m} in |
| 275 | *.bz2|*.tbz|*.tbz2) |
313 | *.bz2|*.tbz|*.tbz2) |
| 276 | local bzcmd=${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || bzip2)} |
314 | local bzcmd=${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzip2)} |
| 277 | local bzuncmd=${PORTAGE_BUNZIP2_COMMAND:-${PORTAGE_BZIP2_COMMAND} -d} |
315 | local bzuncmd=${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d} |
| 278 | : ${UNPACKER_BZ2:=${bzuncmd}} |
316 | : ${UNPACKER_BZ2:=${bzuncmd}} |
| 279 | comp="${UNPACKER_BZ2} -c" |
317 | comp="${UNPACKER_BZ2} -c" |
| 280 | ;; |
318 | ;; |
| 281 | *.z|*.gz|*.tgz) |
319 | *.z|*.gz|*.tgz) |
| 282 | comp="gzip -dc" ;; |
320 | comp="gzip -dc" ;; |
| … | |
… | |
| 284 | comp="xz -dc" ;; |
322 | comp="xz -dc" ;; |
| 285 | *) comp="" ;; |
323 | *) comp="" ;; |
| 286 | esac |
324 | esac |
| 287 | |
325 | |
| 288 | # then figure out if there are any archiving aspects |
326 | # then figure out if there are any archiving aspects |
|
|
327 | arch="" |
| 289 | case ${m} in |
328 | case ${m} in |
| 290 | *.tgz|*.tbz|*.tbz2|*.txz|*.tar.*|*.tar) |
329 | *.tgz|*.tbz|*.tbz2|*.txz|*.tar.*|*.tar) |
| 291 | arch="tar --no-same-owner -xof" ;; |
330 | arch="tar --no-same-owner -xof" ;; |
|
|
331 | *.cpio.*|*.cpio) |
|
|
332 | arch="unpack_cpio" ;; |
| 292 | *.deb) |
333 | *.deb) |
| 293 | arch="unpack_deb" ;; |
334 | arch="unpack_deb" ;; |
| 294 | *.run) |
335 | *.run) |
| 295 | arch="unpack_makeself" ;; |
336 | arch="unpack_makeself" ;; |
| 296 | *) arch="" ;; |
337 | *.sh) |
|
|
338 | # Not all shell scripts are makeself |
|
|
339 | if head -n 30 "${a}" | grep -qs '#.*Makeself' ; then |
|
|
340 | arch="unpack_makeself" |
|
|
341 | fi |
|
|
342 | ;; |
|
|
343 | *.bin) |
|
|
344 | # Makeself archives can be annoyingly named |
|
|
345 | if head -c 100 "${a}" | grep -qs '#.*Makeself' ; then |
|
|
346 | arch="unpack_makeself" |
|
|
347 | fi |
|
|
348 | ;; |
| 297 | esac |
349 | esac |
| 298 | |
350 | |
| 299 | # finally do the unpack |
351 | # finally do the unpack |
| 300 | if [[ -z ${arch}${comp} ]] ; then |
352 | if [[ -z ${arch}${comp} ]] ; then |
| 301 | unpack "${a}" |
353 | unpack "$1" |
| 302 | return $? |
354 | return $? |
| 303 | fi |
355 | fi |
| 304 | |
356 | |
| 305 | [[ ${arch} != unpack_* ]] && unpack_banner "${a}" |
357 | [[ ${arch} != unpack_* ]] && unpack_banner "${a}" |
| 306 | |
358 | |
| 307 | if [[ -z ${arch} ]] ; then |
359 | if [[ -z ${arch} ]] ; then |
|
|
360 | # Need to decompress the file into $PWD #408801 |
|
|
361 | local _a=${a%.*} |
| 308 | ${comp} "${a}" > "${a%.*}" |
362 | ${comp} "${a}" > "${_a##*/}" |
| 309 | elif [[ -z ${comp} ]] ; then |
363 | elif [[ -z ${comp} ]] ; then |
| 310 | ${arch} "${a}" |
364 | ${arch} "${a}" |
| 311 | else |
365 | else |
| 312 | ${comp} "${a}" | ${arch} - |
366 | ${comp} "${a}" | ${arch} - |
| 313 | fi |
367 | fi |
| … | |
… | |
| 346 | |
400 | |
| 347 | [[ $# -eq 0 ]] && set -- ${SRC_URI} |
401 | [[ $# -eq 0 ]] && set -- ${SRC_URI} |
| 348 | |
402 | |
| 349 | for uri in "$@" ; do |
403 | for uri in "$@" ; do |
| 350 | case ${uri} in |
404 | case ${uri} in |
|
|
405 | *.cpio.*|*.cpio) |
|
|
406 | d="app-arch/cpio" ;; |
| 351 | *.rar|*.RAR) |
407 | *.rar|*.RAR) |
| 352 | d="app-arch/unrar" ;; |
408 | d="app-arch/unrar" ;; |
| 353 | *.7z) |
409 | *.7z) |
| 354 | d="app-arch/p7zip" ;; |
410 | d="app-arch/p7zip" ;; |
| 355 | *.xz) |
411 | *.xz) |