Gentoo Archives: gentoo-commits

From: Mike Gilbert <floppym@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/vmware:master commit in: eclass/
Date: Sun, 31 Dec 2017 00:05:10
Message-Id: 1514678658.d4db7e3a20002a37bce47c79e16634757fc287ae.floppym@gentoo
1 commit: d4db7e3a20002a37bce47c79e16634757fc287ae
2 Author: Mike Gilbert <floppym <AT> gentoo <DOT> org>
3 AuthorDate: Sun Dec 31 00:04:18 2017 +0000
4 Commit: Mike Gilbert <floppym <AT> gentoo <DOT> org>
5 CommitDate: Sun Dec 31 00:04:18 2017 +0000
6 URL: https://gitweb.gentoo.org/proj/vmware.git/commit/?id=d4db7e3a
7
8 vmware-bundle.eclass: copy from gentoo
9
10 Bug: https://bugs.gentoo.org/642710
11
12 eclass/vmware-bundle.eclass | 86 +++++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 86 insertions(+)
14
15 diff --git a/eclass/vmware-bundle.eclass b/eclass/vmware-bundle.eclass
16 new file mode 100644
17 index 0000000..6f72028
18 --- /dev/null
19 +++ b/eclass/vmware-bundle.eclass
20 @@ -0,0 +1,86 @@
21 +# Copyright 1999-2011 Gentoo Foundation
22 +# Distributed under the terms of the GNU General Public License v2
23 +
24 +# @ECLASS: vmware-bundle.eclass
25 +# @MAINTAINER:
26 +# vmware@g.o
27 +# @AUTHOR:
28 +# Matt Whitlock <matt@××××××××.name>
29 +# @BLURB: Provides extract functionality for vmware products bundles
30 +
31 +DEPEND="dev-libs/libxslt"
32 +
33 +vmware-bundle_extract-bundle-component() {
34 + local bundle=${1:?} component=${2:?} dest=${3:-${2}}
35 + cat > "${T}"/list-bundle-components.xsl <<-EOF
36 + <?xml version="1.0" encoding="ISO-8859-1"?>
37 + <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
38 + <xsl:output omit-xml-declaration="yes"/>
39 + <xsl:template match="text()"/>
40 + <xsl:template match="/bundle/components/component">
41 + <xsl:value-of select="@offset"/>
42 + <xsl:text> </xsl:text>
43 + <xsl:value-of select="@size"/>
44 + <xsl:text> </xsl:text>
45 + <xsl:value-of select="@name"/>
46 + <xsl:text>&#10;</xsl:text>
47 + </xsl:template>
48 + </xsl:stylesheet>
49 + EOF
50 + local -i bundle_size=$(stat -L -c'%s' "${bundle}")
51 + local -i bundle_manifestOffset=$(od -An -j$((bundle_size-36)) -N4 -tu4 "${bundle}")
52 + local -i bundle_manifestSize=$(od -An -j$((bundle_size-40)) -N4 -tu4 "${bundle}")
53 + local -i bundle_dataOffset=$(od -An -j$((bundle_size-44)) -N4 -tu4 "${bundle}")
54 + local -i bundle_dataSize=$(od -An -j$((bundle_size-52)) -N8 -tu8 "${bundle}")
55 + tail -c+$((bundle_manifestOffset+1)) "${bundle}" 2> /dev/null | head -c$((bundle_manifestSize)) |
56 + xsltproc "${T}"/list-bundle-components.xsl - |
57 + while read -r component_offset component_size component_name ; do
58 + if [[ ${component_name} == ${component} ]] ; then
59 + ebegin "Extracting '${component_name}' component from '$(basename "${bundle}")'"
60 + vmware-bundle_extract-component "${bundle}" "${dest}" $((bundle_dataOffset+component_offset))
61 + eend
62 + fi
63 + done
64 +}
65 +
66 +vmware-bundle_extract-component() {
67 + local component=${1:?} dest=${2:-.}
68 + local -i offset=${3}
69 + cat > "${T}"/list-component-files.xsl <<-EOF
70 + <?xml version="1.0" encoding="ISO-8859-1"?>
71 + <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
72 + <xsl:output omit-xml-declaration="yes"/>
73 + <xsl:template match="text()"/>
74 + <xsl:template match="/component/fileset/file">
75 + <xsl:value-of select="@offset"/>
76 + <xsl:text> </xsl:text>
77 + <xsl:value-of select="@compressedSize"/>
78 + <xsl:text> </xsl:text>
79 + <xsl:value-of select="@uncompressedSize"/>
80 + <xsl:text> </xsl:text>
81 + <xsl:value-of select="@path"/>
82 + <xsl:text>&#10;</xsl:text>
83 + </xsl:template>
84 + </xsl:stylesheet>
85 + EOF
86 + local -i component_manifestOffset=$(od -An -j$((offset+9)) -N4 -tu4 "${component}")
87 + local -i component_manifestSize=$(od -An -j$((offset+13)) -N4 -tu4 "${component}")
88 + local -i component_dataOffset=$(od -An -j$((offset+17)) -N4 -tu4 "${component}")
89 + local -i component_dataSize=$(od -An -j$((offset+21)) -N8 -tu8 "${component}")
90 + tail -c+$((offset+component_manifestOffset+1)) "${component}" 2> /dev/null |
91 + head -c$((component_manifestSize)) | xsltproc "${T}"/list-component-files.xsl - |
92 + while read -r file_offset file_compressedSize file_uncompressedSize file_path ; do
93 + if [[ ${file_path} ]] ; then
94 + file_path="${dest}/${file_path}"
95 + mkdir -p "$(dirname "${file_path}")" || die
96 + if [[ ${file_compressedSize} -gt 0 ]] ; then
97 + echo -n '.'
98 + tail -c+$((offset+component_dataOffset+file_offset+1)) "${component}" 2> /dev/null |
99 + head -c$((file_compressedSize)) | gzip -cd > "${file_path}" || die
100 + else
101 + echo -n 'x'
102 + fi
103 + fi
104 + done
105 + echo
106 +}