From: Mike Frysinger <vapier@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Vadim A. Misbakh-Soloviov" <mva@mva.name>, azamat.hackimov@gmail.com
Subject: [gentoo-dev] unpacker.eclass: add decompress probe helper
Date: Sat, 22 Jun 2013 13:55:24 -0400 [thread overview]
Message-ID: <201306221355.25904.vapier@gentoo.org> (raw)
In-Reply-To: <201306170155.10347.vapier@gentoo.org>
[-- Attachment #1: Type: Text/Plain, Size: 6471 bytes --]
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
-mike
--- 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="recur -_+^+_- s
# @DEFAULT_UNSET
# @DESCRIPTION:
# Utility to use to decompress bzip2 files. Will dynamically pick between
-# `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.
# for internal use only (unpack_pdv and unpack_makeself)
@@ -74,9 +81,9 @@ unpack_banner() {
# parameter. Here is an example:
#
# @CODE
-# vapier@vapier 0 pdv_unpack # strings hldsupdatetool.bin | grep lseek
+# $ strings hldsupdatetool.bin | grep lseek
# lseek
-# vapier@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin
+# $ strace -elseek ./hldsupdatetool.bin
# lseek(3, -4, SEEK_END) = 2981250
# @CODE
#
@@ -105,19 +112,17 @@ unpack_pdv() {
local tmpfile="${T}/${FUNCNAME}"
tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > "${tmpfile}"
- local iscompressed=$(file -b "${tmpfile}")
- if [[ ${iscompressed:0:8} == "compress" ]] ; then
- iscompressed=1
+ local comp=$(decompress_prog "${tmpfile}")
+ if [[ -n ${comp} ]] ; then
+ comp="| ${comp}"
mv "${tmpfile}"{,.Z}
gunzip "${tmpfile}"
- else
- iscompressed=0
fi
- local istar=$(file -b "${tmpfile}")
- if [[ ${istar:0:9} == "POSIX tar" ]] ; then
- istar=1
+ local istar filetype=$(file -b "${tmpfile}")
+ if [[ ${filetype} == "POSIX tar"* ]] ; then
+ istar=true
else
- istar=0
+ istar=false
fi
#for some reason gzip dies with this ... dd cant provide buffer fast enough ?
@@ -125,29 +130,18 @@ unpack_pdv() {
# | dd ibs=${tailskip} skip=1 \
# | gzip -dc \
# > ${datafile}
- if [ ${iscompressed} -eq 1 ] ; then
- if [ ${istar} -eq 1 ] ; then
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
- | head -c $((${metaskip}-${tailskip})) \
- | tar -xzf -
- else
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
- | head -c $((${metaskip}-${tailskip})) \
- | gzip -dc \
- > ${datafile}
- 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
- if [ ${istar} -eq 1 ] ; then
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
- | head -c $((${metaskip}-${tailskip})) \
- | tar --no-same-owner -xf -
- else
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \
- | head -c $((${metaskip}-${tailskip})) \
- > ${datafile}
- fi
+ eval th ${comp} > "${datafile}"
fi
- true
+ exit 0
+ )
#[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
#assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')"
}
@@ -218,31 +212,11 @@ unpack_makeself() {
esac
# lets grab the first few bytes of the file to figure out what kind of archive it is
- local filetype tmpfile="${T}/${FUNCNAME}"
+ local tmpfile="${T}/${FUNCNAME}"
eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}"
- filetype=$(file -b "${tmpfile}") || die
- case ${filetype} in
- *tar\ archive*)
- eval ${exe} | tar --no-same-owner -xf -
- ;;
- bzip2*)
- eval ${exe} | bzip2 -dc | tar --no-same-owner -xf -
- ;;
- gzip*)
- eval ${exe} | tar --no-same-owner -xzf -
- ;;
- compress*)
- eval ${exe} | gunzip | tar --no-same-owner -xf -
- ;;
- XZ*)
- eval ${exe} | unxz | tar --no-same-owner -xf -
- ;;
- *)
- eerror "Unknown filetype \"${filetype}\" ?"
- false
- ;;
- esac
- assert "failure unpacking (${filetype}) makeself ${src##*/} ('${ver}' +${skip})"
+ local comp=$(decompress_prog "${tmpfile}")
+ eval ${exe} | eval "${comp:+${comp} |}" tar --no-same-owner -xf -
+ assert "failure unpacking makeself ${src##*/} ('${ver}' +${skip})"
}
# @FUNCTION: unpack_deb
@@ -319,6 +293,54 @@ unpack_zip() {
[[ $? -le 1 ]] || die "unpacking ${zip} failed (arch=unpack_zip)"
}
+# @FUNCTION: decompress_prog
+# @USAGE: <mime|format|filename>
+# @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} <mime|format|filename>"
+
+ local comp
+
+ case $1 in
+ application/x-bzip2\;*|\
+ bzip2|bz2|\
+ *.bz2|*.tbz|*.tbz2)
+ local bzcmd=${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzip2)}
+ local bzuncmd=${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d}
+ : ${UNPACKER_BZ2:=${bzuncmd}}
+ comp="${UNPACKER_BZ2} -dc"
+ ;;
+
+ application/x-gzip\;*|\
+ application/x-compress\;*|\
+ gzip|gz|\
+ *.z|*.gz|*.tgz)
+ : ${UNPACKER_GZIP:=$(type -P pigz || type -P gzip)}
+ comp="${UNPACKER_GZIP} -dc"
+ ;;
+
+ application/x-xz\;*|\
+ lzma|xz|\
+ *.lzma|*.xz|*.txz)
+ comp="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: <one archive to unpack>
# @INTERNAL
@@ -333,19 +355,7 @@ _unpacker() {
a=$(find_unpackable_file "${a}")
# first figure out the decompression method
- case ${m} in
- *.bz2|*.tbz|*.tbz2)
- local bzcmd=${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzip2)}
- local bzuncmd=${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d}
- : ${UNPACKER_BZ2:=${bzuncmd}}
- comp="${UNPACKER_BZ2} -c"
- ;;
- *.z|*.gz|*.tgz)
- comp="gzip -dc" ;;
- *.lzma|*.xz|*.txz)
- comp="xz -dc" ;;
- *) comp="" ;;
- esac
+ comp=$(decompress_prog "${n}")
# then figure out if there are any archiving aspects
arch=""
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
prev parent reply other threads:[~2013-06-22 17:55 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-15 8:39 [gentoo-dev] [RFC] unpacker.eclass extensions Vadim A. Misbakh-Soloviov
2013-06-15 14:33 ` Markos Chandras
2013-06-15 14:37 ` Markos Chandras
2013-06-17 5:55 ` Mike Frysinger
2013-06-17 7:15 ` Diego Elio Pettenò
2013-06-17 16:08 ` Mike Frysinger
2013-06-17 16:54 ` Rick "Zero_Chaos" Farina
2013-06-17 20:19 ` Diego Elio Pettenò
2013-06-17 20:37 ` Rick "Zero_Chaos" Farina
2013-06-17 21:41 ` Brian Dolbec
2013-06-19 21:15 ` Mike Frysinger
2013-06-22 17:55 ` Mike Frysinger [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201306221355.25904.vapier@gentoo.org \
--to=vapier@gentoo.org \
--cc=azamat.hackimov@gmail.com \
--cc=gentoo-dev@lists.gentoo.org \
--cc=mva@mva.name \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox