1 | #!/bin/bash
|
---|
2 | # $Id: xcode-4.1-extrator.sh 96416 2022-08-22 20:36:29Z vboxsync $
|
---|
3 | ## @file
|
---|
4 | # Extracts the necessary bits from the Xcode 4.1 lion package (inside installercode_41_lion.dmg).
|
---|
5 |
|
---|
6 | #
|
---|
7 | # Copyright (C) 2014-2022 Oracle and/or its affiliates.
|
---|
8 | #
|
---|
9 | # This file is part of VirtualBox base platform packages, as
|
---|
10 | # available from https://www.virtualbox.org.
|
---|
11 | #
|
---|
12 | # This program is free software; you can redistribute it and/or
|
---|
13 | # modify it under the terms of the GNU General Public License
|
---|
14 | # as published by the Free Software Foundation, in version 3 of the
|
---|
15 | # License.
|
---|
16 | #
|
---|
17 | # This program is distributed in the hope that it will be useful, but
|
---|
18 | # WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | # General Public License for more details.
|
---|
21 | #
|
---|
22 | # You should have received a copy of the GNU General Public License
|
---|
23 | # along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | #
|
---|
25 | # SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | #
|
---|
27 |
|
---|
28 | #
|
---|
29 | # Make sure we're talking the same language.
|
---|
30 | #
|
---|
31 | LC_ALL=C
|
---|
32 | export LC_ALL
|
---|
33 |
|
---|
34 | #
|
---|
35 | # Figure the tools/darwin.x86 location.
|
---|
36 | #
|
---|
37 | MY_DARWIN_DIR=`dirname "$0"`
|
---|
38 | MY_DARWIN_DIR=`(cd "${MY_DARWIN_DIR}" ; pwd)`
|
---|
39 | MY_DARWIN_DIR=`dirname "${MY_DARWIN_DIR}"`
|
---|
40 |
|
---|
41 | #
|
---|
42 | # Constants.
|
---|
43 | #
|
---|
44 | MY_PKGS="gcc4.2.pkg llvm-gcc4.2.pkg DeveloperToolsCLI.pkg xcrun.pkg JavaSDK.pkg MacOSX10.6.pkg MacOSX10.7.pkg"
|
---|
45 | MY_LAST_PKG="MacOSX10.7.pkg"
|
---|
46 | MY_PKGS="clang.pkg"
|
---|
47 | MY_LAST_PKG="clang.pkg"
|
---|
48 | declare -a MY_FULL_PKGS
|
---|
49 | for i in $MY_PKGS;
|
---|
50 | do
|
---|
51 | MY_FULL_PKGS[$((${#MY_FULL_PKGS[*]}))]="./Applications/Install Xcode.app/Contents/Resources/Packages/${i}"
|
---|
52 | done
|
---|
53 |
|
---|
54 | #
|
---|
55 | # Parse arguments.
|
---|
56 | #
|
---|
57 | MY_TMP_DIR=/var/tmp/xcode41extractor
|
---|
58 | MY_DST_DIR="${MY_DARWIN_DIR}/xcode/v41"
|
---|
59 | MY_PKG_FILE=
|
---|
60 |
|
---|
61 | my_usage()
|
---|
62 | {
|
---|
63 | echo "usage: $0 [--tmpdir|-t <tmpdir>] <--destination|-d> <dstdir> <--filename|-f> <dir/InstallXcodeLion.pkg>";
|
---|
64 | exit $1;
|
---|
65 | }
|
---|
66 |
|
---|
67 | while test $# -ge 1;
|
---|
68 | do
|
---|
69 | ARG=$1;
|
---|
70 | shift;
|
---|
71 | case "$ARG" in
|
---|
72 |
|
---|
73 | --tmpdir|-t)
|
---|
74 | if test $# -eq 0; then
|
---|
75 | echo "error: missing --tmpdir argument." 1>&2;
|
---|
76 | exit 1;
|
---|
77 | fi
|
---|
78 | MY_TMP_DIR="$1";
|
---|
79 | shift;
|
---|
80 | ;;
|
---|
81 |
|
---|
82 | --destination|-d)
|
---|
83 | if test $# -eq 0; then
|
---|
84 | echo "error: missing --tmpdir argument." 1>&2;
|
---|
85 | exit 1;
|
---|
86 | fi
|
---|
87 | MY_DST_DIR="$1";
|
---|
88 | shift;
|
---|
89 | ;;
|
---|
90 |
|
---|
91 | --filename|-f)
|
---|
92 | if test $# -eq 0; then
|
---|
93 | echo "error: missing --filename argument." 1>&2;
|
---|
94 | exit 1;
|
---|
95 | fi
|
---|
96 | MY_PKG_FILE="$1";
|
---|
97 | shift;
|
---|
98 | ;;
|
---|
99 |
|
---|
100 | --h*|-h*|-?|--?)
|
---|
101 | my_usage 0;
|
---|
102 | esac
|
---|
103 | done
|
---|
104 |
|
---|
105 | # Check the package file.
|
---|
106 | if [ -z "${MY_PKG_FILE}" ]; then
|
---|
107 | echo "error: missing --filename <dir/InstallXcodeLion.pkg>." 1>&2l
|
---|
108 | my_usage 1;
|
---|
109 | fi
|
---|
110 | if ! xar -tf "${MY_PKG_FILE}" > /dev/null ; then
|
---|
111 | echo "error: xar has trouble with '${MY_PKG_FILE}'." 1>&2;
|
---|
112 | exit 1;
|
---|
113 | fi
|
---|
114 |
|
---|
115 | # Check the destination directory.
|
---|
116 | if [ -z "${MY_DST_DIR}" ]; then
|
---|
117 | echo "error: missing --destination <dstdir>." 1>&2;
|
---|
118 | my_usage 1;
|
---|
119 | fi
|
---|
120 | if ! mkdir -p "${MY_DST_DIR}"; then
|
---|
121 | echo "error: error creating '${MY_DST_DIR}'." 1>&2;
|
---|
122 | exit 1;
|
---|
123 | fi
|
---|
124 |
|
---|
125 | # Check the temporary directory.
|
---|
126 | if [ -z "${MY_TMP_DIR}" ]; then
|
---|
127 | echo "error: empty --tmpdir <tmpdir>." 1>&2;
|
---|
128 | my_usage 1;
|
---|
129 | fi
|
---|
130 | if ! mkdir -p "${MY_TMP_DIR}/x"; then
|
---|
131 | echo "error: error creating '${MY_TMP_DIR}/x'." 1>&2;
|
---|
132 | exit 1;
|
---|
133 | fi
|
---|
134 |
|
---|
135 | #
|
---|
136 | # Extract the "Applications/Install Xcode.app" payload, calling it MainPayload.tar.
|
---|
137 | #
|
---|
138 | if [ ! -f "${MY_TMP_DIR}/x/MainPayload.tar" ]; then
|
---|
139 | echo "info: Extracting '${MY_PKG_FILE}'..."
|
---|
140 | if ! xar -xvf "${MY_PKG_FILE}" -C "${MY_TMP_DIR}/x"; then
|
---|
141 | echo "error: extraction error." 1>&2;
|
---|
142 | exit 1;
|
---|
143 | fi
|
---|
144 | if ! mv -f "${MY_TMP_DIR}/x/InstallXcodeLion.pkg/Payload" "${MY_TMP_DIR}/x/MainPayload.tar"; then
|
---|
145 | echo "error: Failed to move the package payload. Did you get the right package file?" 1>&2;
|
---|
146 | exit 1;
|
---|
147 | fi
|
---|
148 | fi
|
---|
149 |
|
---|
150 | #
|
---|
151 | # Extract the sub-packages from MainPayload.tar.
|
---|
152 | #
|
---|
153 | if [ ! -f "${MY_TMP_DIR}/x/${MY_LAST_PKG}" ]; then
|
---|
154 | echo "info: Extracting packages from 'MainPayload.tar'..."
|
---|
155 | if ! tar xvf "${MY_TMP_DIR}/x/MainPayload.tar" -C "${MY_TMP_DIR}/x" "${MY_FULL_PKGS[@]}"; then
|
---|
156 | echo "error: Failure extracting sub-packages from MainPayload.tar (see above)." 1>&2;
|
---|
157 | exit 1;
|
---|
158 | fi
|
---|
159 |
|
---|
160 | for i in $MY_PKGS;
|
---|
161 | do
|
---|
162 | if ! mv -f "${MY_TMP_DIR}/x/Applications/Install Xcode.app/Contents/Resources/Packages/${i}" "${MY_TMP_DIR}/x/${i}"; then
|
---|
163 | echo "error: Failed to move the package ${i}." 1>&2;
|
---|
164 | exit 1;
|
---|
165 | fi
|
---|
166 | done
|
---|
167 | fi
|
---|
168 |
|
---|
169 | #
|
---|
170 | # Work the sub-packages, extracting their payload content into the destination directory.
|
---|
171 | #
|
---|
172 | for i in $MY_PKGS;
|
---|
173 | do
|
---|
174 | rm -f -- "${MY_TMP_DIR}/x/Payload";
|
---|
175 | echo "info: Extracting payload of sub-package ${i}...";
|
---|
176 | if ! xar -xvf "${MY_TMP_DIR}/x/${i}" -C "${MY_TMP_DIR}/x" Payload; then
|
---|
177 | echo "error: Failed to extract the payload of sub-package ${i}." 1>&2;
|
---|
178 | exit 1;
|
---|
179 | fi
|
---|
180 | if ! tar xvf "${MY_TMP_DIR}/x/Payload" -C "${MY_DST_DIR}"; then
|
---|
181 | echo "error: Failed to extract the payload content of sub-package ${i}." 1>&2;
|
---|
182 | exit 1;
|
---|
183 | fi
|
---|
184 | done
|
---|
185 |
|
---|
186 | #
|
---|
187 | # Clean up.
|
---|
188 | #
|
---|
189 | echo "info: Successfully extracted. Cleaning up temporary files..."
|
---|
190 | rm -Rf -- "${MY_TMP_DIR}/x/"
|
---|
191 | rmdir -- "${MY_TMP_DIR}"
|
---|
192 |
|
---|