Magellan Linux

Annotation of /trunk/vmware-workstation/unbundle.sh

Parent Directory Parent Directory | Revision Log Revision Log


Revision 852 - (hide annotations) (download) (as text)
Mon Jun 15 21:54:19 2009 UTC (14 years, 11 months ago) by niro
File MIME type: application/x-sh
File size: 1828 byte(s)
-files for vmware

1 niro 852 #!/bin/bash
2    
3     ORIGFILE="$1"
4    
5     is_relative() {
6     local path="$1"
7     shift
8    
9     [ "${path:0:1}" != "/" ]
10     return
11     }
12    
13     set_offsets() {
14     # This won't work with non-GNU stat.
15     FILE_SIZE=`stat -L --format "%s" "$1"`
16     local offset=$(($FILE_SIZE - 4))
17    
18     MAGIC_OFFSET=$offset
19     offset=$(($offset - 4))
20    
21     CHECKSUM_OFFSET=$offset
22     offset=$(($offset - 4))
23    
24     VERSION_OFFSET=$offset
25     offset=$(($offset - 4))
26    
27     PREPAYLOAD_OFFSET=$offset
28     offset=$(($offset - 4))
29    
30     PREPAYLOAD_SIZE_OFFSET=$offset
31     offset=$(($offset - 4))
32    
33     LAUNCHER_SIZE_OFFSET=$offset
34     offset=$(($offset - 4))
35    
36     PAYLOAD_OFFSET=$offset
37     offset=$(($offset - 4))
38    
39     PAYLOAD_SIZE_OFFSET=$offset
40     offset=$(($offset - 4))
41     }
42    
43     set_lengths() {
44     local file="$1"
45     if [ ! -s "$file" ]; then
46     echo "$file does not exist"
47     exit 1
48     fi
49    
50     # XXX: put extraction in its own function
51     MAGIC_NUMBER=`od -An -t u4 -N 4 -j $MAGIC_OFFSET "$file" | tr -d ' '`
52    
53     if [ "$MAGIC_NUMBER" != "907380241" ]; then
54     echo "magic number does not match"
55     exit 1
56     fi
57    
58     LAUNCHER_SIZE=`od -An -t u4 -N 4 -j $LAUNCHER_SIZE_OFFSET "$file" | tr -d ' '`
59     PAYLOAD_SIZE=`od -An -t u4 -N 4 -j $PAYLOAD_SIZE_OFFSET "$file" | tr -d ' '`
60     PREPAYLOAD_SIZE=`od -An -t u4 -N 4 -j $PREPAYLOAD_SIZE_OFFSET "$file" | tr -d ' '`
61    
62     SKIP_BYTES=$(($PREPAYLOAD_SIZE + $LAUNCHER_SIZE))
63    
64     return 0
65     }
66    
67     if is_relative "${ORIGFILE}"; then
68     ORIGFILE="`pwd`/${ORIGFILE}"
69     fi
70    
71    
72     set_offsets ${ORIGFILE}
73     set_lengths ${ORIGFILE}
74    
75     echo "Unbundling" ${ORIGFILE}
76    
77     PREPAYLOAD="prepayload"
78     PAYLOAD="payload"
79    
80     # Unpack the pre-payload file
81     mkdir ${PREPAYLOAD}
82     cd ${PREPAYLOAD}
83     dd if="${ORIGFILE}" ibs=$LAUNCHER_SIZE obs=1024 skip=1 | tar -xzf - 2> /dev/null
84     cd ..
85    
86     # Unpack the main file
87     mkdir ${PAYLOAD}
88     cd ${PAYLOAD}
89     dd if="${ORIGFILE}" ibs=$SKIP_BYTES obs=1024 skip=1 | tar -xzf - 2> /dev/null
90     cd ..
91