1 |
On Monday 17 June 2013 01:55:09 Mike Frysinger wrote: |
2 |
> i wish we could merge with the file detection in unpack_makeself somehow |
3 |
|
4 |
this patch should unify that aspect |
5 |
-mike |
6 |
|
7 |
--- unpacker.eclass 10 Apr 2013 14:47:49 -0000 1.13 |
8 |
+++ unpacker.eclass 22 Jun 2013 17:54:09 -0000 |
9 |
@@ -22,7 +22,14 @@ ___ECLASS_ONCE_UNPACKER="recur -_+^+_- s |
10 |
# @DEFAULT_UNSET |
11 |
# @DESCRIPTION: |
12 |
# Utility to use to decompress bzip2 files. Will dynamically pick between |
13 |
-# `pbzip2` and `bzip2`. Make sure your choice accepts the "-c" option. |
14 |
+# `pbzip2` and `bzip2`. Make sure your choice accepts the "-dc" options. |
15 |
+# Note: this is meant for users to set, not ebuilds. |
16 |
+ |
17 |
+# @ECLASS-VARIABLE: UNPACKER_GZIP |
18 |
+# @DEFAULT_UNSET |
19 |
+# @DESCRIPTION: |
20 |
+# Utility to use to decompress gzip files. Will dynamically pick between |
21 |
+# `gzip` and `pigz`. Make sure your choice accepts the "-dc" options. |
22 |
# Note: this is meant for users to set, not ebuilds. |
23 |
|
24 |
# for internal use only (unpack_pdv and unpack_makeself) |
25 |
@@ -74,9 +81,9 @@ unpack_banner() { |
26 |
# parameter. Here is an example: |
27 |
# |
28 |
# @CODE |
29 |
-# vapier@vapier 0 pdv_unpack # strings hldsupdatetool.bin | grep lseek |
30 |
+# $ strings hldsupdatetool.bin | grep lseek |
31 |
# lseek |
32 |
-# vapier@vapier 0 pdv_unpack # strace -elseek ./hldsupdatetool.bin |
33 |
+# $ strace -elseek ./hldsupdatetool.bin |
34 |
# lseek(3, -4, SEEK_END) = 2981250 |
35 |
# @CODE |
36 |
# |
37 |
@@ -105,19 +112,17 @@ unpack_pdv() { |
38 |
local tmpfile="${T}/${FUNCNAME}" |
39 |
tail -c +$((${tailskip}+1)) ${src} 2>/dev/null | head -c 512 > "${tmpfile}" |
40 |
|
41 |
- local iscompressed=$(file -b "${tmpfile}") |
42 |
- if [[ ${iscompressed:0:8} == "compress" ]] ; then |
43 |
- iscompressed=1 |
44 |
+ local comp=$(decompress_prog "${tmpfile}") |
45 |
+ if [[ -n ${comp} ]] ; then |
46 |
+ comp="| ${comp}" |
47 |
mv "${tmpfile}"{,.Z} |
48 |
gunzip "${tmpfile}" |
49 |
- else |
50 |
- iscompressed=0 |
51 |
fi |
52 |
- local istar=$(file -b "${tmpfile}") |
53 |
- if [[ ${istar:0:9} == "POSIX tar" ]] ; then |
54 |
- istar=1 |
55 |
+ local istar filetype=$(file -b "${tmpfile}") |
56 |
+ if [[ ${filetype} == "POSIX tar"* ]] ; then |
57 |
+ istar=true |
58 |
else |
59 |
- istar=0 |
60 |
+ istar=false |
61 |
fi |
62 |
|
63 |
#for some reason gzip dies with this ... dd cant provide buffer fast enough ? |
64 |
@@ -125,29 +130,18 @@ unpack_pdv() { |
65 |
# | dd ibs=${tailskip} skip=1 \ |
66 |
# | gzip -dc \ |
67 |
# > ${datafile} |
68 |
- if [ ${iscompressed} -eq 1 ] ; then |
69 |
- if [ ${istar} -eq 1 ] ; then |
70 |
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \ |
71 |
- | head -c $((${metaskip}-${tailskip})) \ |
72 |
- | tar -xzf - |
73 |
- else |
74 |
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \ |
75 |
- | head -c $((${metaskip}-${tailskip})) \ |
76 |
- | gzip -dc \ |
77 |
- > ${datafile} |
78 |
- fi |
79 |
+ ( |
80 |
+ th() { |
81 |
+ tail -c +$(( tailskip + 1 )) "${src}" 2>/dev/null | \ |
82 |
+ head -c $(( metaskip - tailskip )) |
83 |
+ } |
84 |
+ if ${istar} ; then |
85 |
+ eval th ${comp} | tar --no-same-owner -xf - |
86 |
else |
87 |
- if [ ${istar} -eq 1 ] ; then |
88 |
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \ |
89 |
- | head -c $((${metaskip}-${tailskip})) \ |
90 |
- | tar --no-same-owner -xf - |
91 |
- else |
92 |
- tail -c +$((${tailskip}+1)) "${src}" 2>/dev/null \ |
93 |
- | head -c $((${metaskip}-${tailskip})) \ |
94 |
- > ${datafile} |
95 |
- fi |
96 |
+ eval th ${comp} > "${datafile}" |
97 |
fi |
98 |
- true |
99 |
+ exit 0 |
100 |
+ ) |
101 |
#[ -s "${datafile}" ] || die "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')" |
102 |
#assert "failure unpacking pdv ('${metaskip}' '${tailskip}' '${datafile}')" |
103 |
} |
104 |
@@ -218,31 +212,11 @@ unpack_makeself() { |
105 |
esac |
106 |
|
107 |
# lets grab the first few bytes of the file to figure out what kind of archive it is |
108 |
- local filetype tmpfile="${T}/${FUNCNAME}" |
109 |
+ local tmpfile="${T}/${FUNCNAME}" |
110 |
eval ${exe} 2>/dev/null | head -c 512 > "${tmpfile}" |
111 |
- filetype=$(file -b "${tmpfile}") || die |
112 |
- case ${filetype} in |
113 |
- *tar\ archive*) |
114 |
- eval ${exe} | tar --no-same-owner -xf - |
115 |
- ;; |
116 |
- bzip2*) |
117 |
- eval ${exe} | bzip2 -dc | tar --no-same-owner -xf - |
118 |
- ;; |
119 |
- gzip*) |
120 |
- eval ${exe} | tar --no-same-owner -xzf - |
121 |
- ;; |
122 |
- compress*) |
123 |
- eval ${exe} | gunzip | tar --no-same-owner -xf - |
124 |
- ;; |
125 |
- XZ*) |
126 |
- eval ${exe} | unxz | tar --no-same-owner -xf - |
127 |
- ;; |
128 |
- *) |
129 |
- eerror "Unknown filetype \"${filetype}\" ?" |
130 |
- false |
131 |
- ;; |
132 |
- esac |
133 |
- assert "failure unpacking (${filetype}) makeself ${src##*/} ('${ver}' +${skip})" |
134 |
+ local comp=$(decompress_prog "${tmpfile}") |
135 |
+ eval ${exe} | eval "${comp:+${comp} |}" tar --no-same-owner -xf - |
136 |
+ assert "failure unpacking makeself ${src##*/} ('${ver}' +${skip})" |
137 |
} |
138 |
|
139 |
# @FUNCTION: unpack_deb |
140 |
@@ -319,6 +293,54 @@ unpack_zip() { |
141 |
[[ $? -le 1 ]] || die "unpacking ${zip} failed (arch=unpack_zip)" |
142 |
} |
143 |
|
144 |
+# @FUNCTION: decompress_prog |
145 |
+# @USAGE: <mime|format|filename> |
146 |
+# @DESCRIPTION: |
147 |
+# Get the program name (and args) needed to decompress things. |
148 |
+# You can give this a mime type, or a format name (bz2/gz/xz/etc...), |
149 |
+# or you can give it a filename. If the type can be detected based on |
150 |
+# the suffix alone, we'll use that, otherwise we'll rely on `file` to |
151 |
+# probe the type. |
152 |
+decompress_prog() { |
153 |
+ [[ $# -eq 1 ]] || die "Usage: ${FUNCNAME} <mime|format|filename>" |
154 |
+ |
155 |
+ local comp |
156 |
+ |
157 |
+ case $1 in |
158 |
+ application/x-bzip2\;*|\ |
159 |
+ bzip2|bz2|\ |
160 |
+ *.bz2|*.tbz|*.tbz2) |
161 |
+ local bzcmd=${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzip2)} |
162 |
+ local bzuncmd=${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d} |
163 |
+ : ${UNPACKER_BZ2:=${bzuncmd}} |
164 |
+ comp="${UNPACKER_BZ2} -dc" |
165 |
+ ;; |
166 |
+ |
167 |
+ application/x-gzip\;*|\ |
168 |
+ application/x-compress\;*|\ |
169 |
+ gzip|gz|\ |
170 |
+ *.z|*.gz|*.tgz) |
171 |
+ : ${UNPACKER_GZIP:=$(type -P pigz || type -P gzip)} |
172 |
+ comp="${UNPACKER_GZIP} -dc" |
173 |
+ ;; |
174 |
+ |
175 |
+ application/x-xz\;*|\ |
176 |
+ lzma|xz|\ |
177 |
+ *.lzma|*.xz|*.txz) |
178 |
+ comp="xz -dc" |
179 |
+ ;; |
180 |
+ esac |
181 |
+ |
182 |
+ if [[ -n ${comp} ]] ; then |
183 |
+ echo "${comp}" |
184 |
+ return 0 |
185 |
+ fi |
186 |
+ |
187 |
+ if [[ -s $1 ]] ; then |
188 |
+ decompress_prog "$(file -ib "$1")" |
189 |
+ fi |
190 |
+} |
191 |
+ |
192 |
# @FUNCTION: _unpacker |
193 |
# @USAGE: <one archive to unpack> |
194 |
# @INTERNAL |
195 |
@@ -333,19 +355,7 @@ _unpacker() { |
196 |
a=$(find_unpackable_file "${a}") |
197 |
|
198 |
# first figure out the decompression method |
199 |
- case ${m} in |
200 |
- *.bz2|*.tbz|*.tbz2) |
201 |
- local bzcmd=${PORTAGE_BZIP2_COMMAND:-$(type -P pbzip2 || type -P bzip2)} |
202 |
- local bzuncmd=${PORTAGE_BUNZIP2_COMMAND:-${bzcmd} -d} |
203 |
- : ${UNPACKER_BZ2:=${bzuncmd}} |
204 |
- comp="${UNPACKER_BZ2} -c" |
205 |
- ;; |
206 |
- *.z|*.gz|*.tgz) |
207 |
- comp="gzip -dc" ;; |
208 |
- *.lzma|*.xz|*.txz) |
209 |
- comp="xz -dc" ;; |
210 |
- *) comp="" ;; |
211 |
- esac |
212 |
+ comp=$(decompress_prog "${n}") |
213 |
|
214 |
# then figure out if there are any archiving aspects |
215 |
arch="" |