From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id F00831381F3 for ; Sat, 22 Jun 2013 17:55:28 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 28237E0AA8; Sat, 22 Jun 2013 17:55:25 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 27410E0A62 for ; Sat, 22 Jun 2013 17:55:24 +0000 (UTC) Received: from vapier.localnet (localhost [127.0.0.1]) by smtp.gentoo.org (Postfix) with ESMTP id 2727F33E2B1; Sat, 22 Jun 2013 17:55:23 +0000 (UTC) From: Mike Frysinger Organization: wh0rd.org To: gentoo-dev@lists.gentoo.org Subject: [gentoo-dev] unpacker.eclass: add decompress probe helper Date: Sat, 22 Jun 2013 13:55:24 -0400 User-Agent: KMail/1.13.7 (Linux/3.8.3; KDE/4.6.5; x86_64; ; ) Cc: "Vadim A. Misbakh-Soloviov" , azamat.hackimov@gmail.com References: <51BC282E.9020306@mva.name> <201306170155.10347.vapier@gentoo.org> In-Reply-To: <201306170155.10347.vapier@gentoo.org> Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-dev@lists.gentoo.org Reply-to: gentoo-dev@lists.gentoo.org MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1856593.ZKnvSk0zI7"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <201306221355.25904.vapier@gentoo.org> X-Archives-Salt: 1ac25885-7595-438a-b846-9300fd57b6fb X-Archives-Hash: ed901812c7b93f115a65c3314138c495 --nextPart1856593.ZKnvSk0zI7 Content-Type: Text/Plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Monday 17 June 2013 01:55:09 Mike Frysinger wrote: > i wish we could merge with the file detection in unpack_makeself somehow this patch should unify that aspect =2Dmike =2D-- unpacker.eclass 10 Apr 2013 14:47:49 -0000 1.13 +++ unpacker.eclass 22 Jun 2013 17:54:09 -0000 @@ -22,7 +22,14 @@ ___ECLASS_ONCE_UNPACKER=3D"recur -_+^+_- s # @DEFAULT_UNSET # @DESCRIPTION: # Utility to use to decompress bzip2 files. Will dynamically pick between =2D# `pbzip2` and `bzip2`. Make sure your choice accepts the "-c" option. +# `pbzip2` and `bzip2`. Make sure your choice accepts the "-dc" options. +# Note: this is meant for users to set, not ebuilds. + +# @ECLASS-VARIABLE: UNPACKER_GZIP +# @DEFAULT_UNSET +# @DESCRIPTION: +# Utility to use to decompress gzip files. Will dynamically pick between +# `gzip` and `pigz`. Make sure your choice accepts the "-dc" options. # Note: this is meant for users to set, not ebuilds. =20 # for internal use only (unpack_pdv and unpack_makeself) @@ -74,9 +81,9 @@ unpack_banner() { # parameter. Here is an example: # # @CODE =2D# vapier@vapier 0 pdv_unpack # strings hldsupdatetool.bin | grep lseek +# $ strings hldsupdatetool.bin | grep lseek # lseek =2D# vapier@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin +# $ strace -elseek ./hldsupdatetool.bin # lseek(3, -4, SEEK_END) =3D 2981250 # @CODE # @@ -105,19 +112,17 @@ unpack_pdv() { local tmpfile=3D"${T}/${FUNCNAME}" tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > "${tmpfile= }" =20 =2D local iscompressed=3D$(file -b "${tmpfile}") =2D if [[ ${iscompressed:0:8} =3D=3D "compress" ]] ; then =2D iscompressed=3D1 + local comp=3D$(decompress_prog "${tmpfile}") + if [[ -n ${comp} ]] ; then + comp=3D"| ${comp}" mv "${tmpfile}"{,.Z} gunzip "${tmpfile}" =2D else =2D iscompressed=3D0 fi =2D local istar=3D$(file -b "${tmpfile}") =2D if [[ ${istar:0:9} =3D=3D "POSIX tar" ]] ; then =2D istar=3D1 + local istar filetype=3D$(file -b "${tmpfile}") + if [[ ${filetype} =3D=3D "POSIX tar"* ]] ; then + istar=3Dtrue else =2D istar=3D0 + istar=3Dfalse fi =20 #for some reason gzip dies with this ... dd cant provide buffer fast enou= gh ? @@ -125,29 +130,18 @@ unpack_pdv() { # | dd ibs=3D${tailskip} skip=3D1 \ # | gzip -dc \ # > ${datafile} =2D if [ ${iscompressed} -eq 1 ] ; then =2D if [ ${istar} -eq 1 ] ; then =2D tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \ =2D | head -c $((${metaskip}-${tailskip})) \ =2D | tar -xzf - =2D else =2D tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \ =2D | head -c $((${metaskip}-${tailskip})) \ =2D | gzip -dc \ =2D > ${datafile} =2D fi + ( + th() { + tail -c +$(( tailskip + 1 )) "${src}" 2>/dev/null | \ + head -c $(( metaskip - tailskip )) + } + if ${istar} ; then + eval th ${comp} | tar --no-same-owner -xf - else =2D if [ ${istar} -eq 1 ] ; then =2D tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \ =2D | head -c $((${metaskip}-${tailskip})) \ =2D | tar --no-same-owner -xf - =2D else =2D tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \ =2D | head -c $((${metaskip}-${tailskip})) \ =2D > ${datafile} =2D fi + eval th ${comp} > "${datafile}" fi =2D true + exit 0 + ) #[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tai= lskip}' '${datafile}')" #assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}'= )" } @@ -218,31 +212,11 @@ unpack_makeself() { esac =20 # lets grab the first few bytes of the file to figure out what kind of ar= chive it is =2D local filetype tmpfile=3D"${T}/${FUNCNAME}" + local tmpfile=3D"${T}/${FUNCNAME}" eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}" =2D filetype=3D$(file -b "${tmpfile}") || die =2D case ${filetype} in =2D *tar\ archive*) =2D eval ${exe} | tar --no-same-owner -xf - =2D ;; =2D bzip2*) =2D eval ${exe} | bzip2 -dc | tar --no-same-owner -xf - =2D ;; =2D gzip*) =2D eval ${exe} | tar --no-same-owner -xzf - =2D ;; =2D compress*) =2D eval ${exe} | gunzip | tar --no-same-owner -xf - =2D ;; =2D XZ*) =2D eval ${exe} | unxz | tar --no-same-owner -xf - =2D ;; =2D *) =2D eerror "Unknown filetype \"${filetype}\" ?" =2D false =2D ;; =2D esac =2D assert "failure unpacking (${filetype}) makeself ${src##*/} ('${ver}' += ${skip})" + local comp=3D$(decompress_prog "${tmpfile}") + eval ${exe} | eval "${comp:+${comp} |}" tar --no-same-owner -xf - + assert "failure unpacking makeself ${src##*/} ('${ver}' +${skip})" } =20 # @FUNCTION: unpack_deb @@ -319,6 +293,54 @@ unpack_zip() { [[ $? -le 1 ]] || die "unpacking ${zip} failed (arch=3Dunpack_zip)" } =20 +# @FUNCTION: decompress_prog +# @USAGE: +# @DESCRIPTION: +# Get the program name (and args) needed to decompress things. +# You can give this a mime type, or a format name (bz2/gz/xz/etc...), +# or you can give it a filename. If the type can be detected based on +# the suffix alone, we'll use that, otherwise we'll rely on `file` to +# probe the type. +decompress_prog() { + [[ $# -eq 1 ]] || die "Usage: ${FUNCNAME} " + + local comp + + case $1 in + application/x-bzip2\;*|\ + bzip2|bz2|\ + *.bz2|*.tbz|*.tbz2) + local bzcmd=3D${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzip2= )} + local bzuncmd=3D${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d} + : ${UNPACKER_BZ2:=3D${bzuncmd}} + comp=3D"${UNPACKER_BZ2} -dc" + ;; + + application/x-gzip\;*|\ + application/x-compress\;*|\ + gzip|gz|\ + *.z|*.gz|*.tgz) + : ${UNPACKER_GZIP:=3D$(type -P pigz || type -P gzip)} + comp=3D"${UNPACKER_GZIP} -dc" + ;; + + application/x-xz\;*|\ + lzma|xz|\ + *.lzma|*.xz|*.txz) + comp=3D"xz -dc" + ;; + esac + + if [[ -n ${comp} ]] ; then + echo "${comp}" + return 0 + fi + + if [[ -s $1 ]] ; then + decompress_prog "$(file -ib "$1")" + fi +} + # @FUNCTION: _unpacker # @USAGE: # @INTERNAL @@ -333,19 +355,7 @@ _unpacker() { a=3D$(find_unpackable_file "${a}") =20 # first figure out the decompression method =2D case ${m} in =2D *.bz2|*.tbz|*.tbz2) =2D local bzcmd=3D${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzi= p2)} =2D local bzuncmd=3D${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d} =2D : ${UNPACKER_BZ2:=3D${bzuncmd}} =2D comp=3D"${UNPACKER_BZ2} -c" =2D ;; =2D *.z|*.gz|*.tgz) =2D comp=3D"gzip -dc" ;; =2D *.lzma|*.xz|*.txz) =2D comp=3D"xz -dc" ;; =2D *) comp=3D"" ;; =2D esac + comp=3D$(decompress_prog "${n}") =20 # then figure out if there are any archiving aspects arch=3D"" --nextPart1856593.ZKnvSk0zI7 Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.17 (GNU/Linux) iQIcBAABAgAGBQJRxeUNAAoJEEFjO5/oN/WBqM0QAN9u5JP5WH4LqOoe5udBhBJO 4bfIla4bFakNSMNeXqtMBerghObzwlIYCFgi8ANdJdJvtlqNHQ/ck3We9TEltvVV tf9Eh5PNb1E7fLi8llE7fWD5Vrq380Hik/r2l95djjn8U5zpa4xwotYNTCz8HyC+ DL3bwQOCRxon/SjvomHB7CP4CI2s8JqhQU5UVCl9olwDTCIq2DclMs2EySk12HcR daxR40vOmN2WwGKKu+wJjyJTEmDSb3aeZLOnB23JDQITIJNWx2akkOjUtZwuk2lY 7QV2QWFZtBX4KNhWSvbalfGtpet2nHaehJ7GiUTPLQDZxhALBLIoaAHoVlbcG+8s n1eRFgy0y2Cr6Ba4f2siiathndA0SGL5KhYDtao+/7k68gqKRLJOYI/4eA2RfrJx y2xwUeeXSl0vFBP2C9ldUe1svgylQeqscuTnSOGTk5jjxmjroJfcSBZcRzqjClF8 BDpxjLnXkGulEqhSPjOOT8EiRaylgyUdvnIpVZoF7rNyxCtY749U1hYlzvp6FjNM vf4aiKeW7seTh0g1mGOIdCyYE5B4KgqgQnxojQqnEBNZxI3mFcZGP5TSt8yVtL02 j/5iXcifUBgBBlwWzlqM5JzLM5l3SH0vOuck67i2aQv8fsasHKYEGnsgzOqB4EIV aT5/9mgHdObBe7iM1NTH =oGI+ -----END PGP SIGNATURE----- --nextPart1856593.ZKnvSk0zI7--