- Timestamp:
- Jul 5, 2020 9:25:42 PM (4 years ago)
- File:
-
- 1 copied
-
trunk/tools/darwin.amd64/bin/sdk-extractor.sh (copied) (copied from trunk/tools/darwin.x86/bin/xcode-4.1-extrator.sh ) (6 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/darwin.amd64/bin/sdk-extractor.sh
r85039 r85060 2 2 # $Id$ 3 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 Oracle Corporation 4 # Extracts the SDKs from a commandline tools DMG. 5 # 6 7 # 8 # Copyright (C) 2014-2020 Oracle Corporation 8 9 # 9 10 # This file is part of VirtualBox Open Source Edition (OSE), as … … 32 33 # Constants. 33 34 # 34 MY_PKGS="gcc4.2.pkg llvm-gcc4.2.pkg DeveloperToolsCLI.pkg xcrun.pkg JavaSDK.pkg MacOSX10.6.pkg MacOSX10.7.pkg"35 MY_LAST_PKG="MacOSX10.7.pkg"36 MY_PKGS="clang.pkg"37 MY_LAST_PKG="clang.pkg"38 declare -a MY_FULL_PKGS39 for i in $MY_PKGS;40 do41 MY_FULL_PKGS[$((${#MY_FULL_PKGS[*]}))]="./Applications/Install Xcode.app/Contents/Resources/Packages/${i}"42 done35 #MY_PKGS="gcc4.2.pkg llvm-gcc4.2.pkg DeveloperToolsCLI.pkg xcrun.pkg JavaSDK.pkg MacOSX10.6.pkg MacOSX10.7.pkg" 36 #MY_LAST_PKG="MacOSX10.7.pkg" 37 #MY_PKGS="clang.pkg" 38 #MY_LAST_PKG="clang.pkg" 39 #declare -a MY_FULL_PKGS 40 #for i in $MY_PKGS; 41 #do 42 # MY_FULL_PKGS[$((${#MY_FULL_PKGS[*]}))]="./Applications/Install Xcode.app/Contents/Resources/Packages/${i}" 43 #done 43 44 44 45 # 45 46 # Parse arguments. 46 47 # 47 MY_TMP_DIR=/var/tmp/xcode41extractor 48 MY_DST_DIR="${MY_DARWIN_DIR}/xcode/v41" 48 MY_TMP_DIR=/var/tmp/sdkextractor 49 MY_DST_DIR="${MY_DARWIN_DIR}/sdk/incoming" 50 MY_DMG_FILE= 49 51 MY_PKG_FILE= 52 MY_DRY_RUN= 50 53 51 54 my_usage() 52 55 { 53 echo "usage: $0 [--tmpdir|-t <tmpdir>] <--destination|-d> <dstdir> <--filename|-f> <dir/InstallXcodeLion.pkg>"; 56 echo "usage: $0 [--dry-run] [--tmpdir|-t <tmpdir>] <--destination|-d> <dstdir> <--filename|-f> <dir/Command_Line_Tools*.dmg|pkg>"; 57 echo "" 58 echo "Works for command lines tools for Xcode 8.2 and later." 59 echo "For older versions, the SDK must be extraced from Xcode itself, it seems." 54 60 exit $1; 55 61 } … … 84 90 exit 1; 85 91 fi 86 MY_PKG_FILE="$1"; 92 case "$1" in 93 *.[dD][mM][gG]) 94 MY_DMG_FILE="$1"; 95 MY_PKG_FILE=; 96 ;; 97 *.[pP][kK][gG]) 98 MY_PKG_FILE="$1"; 99 MY_DMG_FILE=; 100 ;; 101 *) 102 echo "error: filename does not end with .dmg or .pkg." 1>&2; 103 exit 1; 104 ;; 105 esac 87 106 shift; 107 ;; 108 109 --dry-run) 110 MY_DRY_RUN=1; 88 111 ;; 89 112 … … 93 116 done 94 117 95 # Check the package file.96 if [ -z "${MY_PKG_FILE}" ]; then97 echo "error: missing --filename <dir/ InstallXcodeLion.pkg>." 1>&2l118 # We must have something to work with. 119 if [ -z "${MY_PKG_FILE}" -a -z "${MY_DMG_FILE}" ]; then 120 echo "error: missing --filename <dir/Command_Line_Tools*.dmg|pkg>." 1>&2l 98 121 my_usage 1; 99 fi100 if ! xar -tf "${MY_PKG_FILE}" > /dev/null ; then101 echo "error: xar has trouble with '${MY_PKG_FILE}'." 1>&2;102 exit 1;103 122 fi 104 123 … … 118 137 my_usage 1; 119 138 fi 120 if ! mkdir -p "${MY_TMP_DIR}/x"; then 121 echo "error: error creating '${MY_TMP_DIR}/x'." 1>&2; 122 exit 1; 123 fi 124 125 # 126 # Extract the "Applications/Install Xcode.app" payload, calling it MainPayload.tar. 127 # 128 if [ ! -f "${MY_TMP_DIR}/x/MainPayload.tar" ]; then 129 echo "info: Extracting '${MY_PKG_FILE}'..." 130 if ! xar -xvf "${MY_PKG_FILE}" -C "${MY_TMP_DIR}/x"; then 131 echo "error: extraction error." 1>&2; 132 exit 1; 133 fi 134 if ! mv -f "${MY_TMP_DIR}/x/InstallXcodeLion.pkg/Payload" "${MY_TMP_DIR}/x/MainPayload.tar"; then 135 echo "error: Failed to move the package payload. Did you get the right package file?" 1>&2; 136 exit 1; 137 fi 138 fi 139 140 # 141 # Extract the sub-packages from MainPayload.tar. 142 # 143 if [ ! -f "${MY_TMP_DIR}/x/${MY_LAST_PKG}" ]; then 144 echo "info: Extracting packages from 'MainPayload.tar'..." 145 if ! tar xvf "${MY_TMP_DIR}/x/MainPayload.tar" -C "${MY_TMP_DIR}/x" "${MY_FULL_PKGS[@]}"; then 146 echo "error: Failure extracting sub-packages from MainPayload.tar (see above)." 1>&2; 147 exit 1; 148 fi 149 150 for i in $MY_PKGS; 139 MY_TMP_DIR_X="${MY_TMP_DIR}/x$$"; 140 if ! mkdir -p "${MY_TMP_DIR_X}"; then 141 echo "error: error creating '${MY_TMP_DIR_X}'." 1>&2; 142 exit 1; 143 fi 144 MY_TMP_DIR_Y="${MY_TMP_DIR}/y$$"; 145 if ! mkdir -p "${MY_TMP_DIR_Y}"; then 146 echo "error: error creating '${MY_TMP_DIR_Y}'." 1>&2; 147 exit 1; 148 fi 149 150 # Attach the DMG if one is given, then find the PKG file inside it. 151 MY_TMP_DIR_DMG="${MY_TMP_DIR}/dmg"; 152 rmdir -- "${MY_TMP_DIR_DMG}" 2>/dev/null; 153 if [ -d "${MY_TMP_DIR_DMG}" ]; then 154 echo "info: Unmount '${MY_TMP_DIR_DMG}'..."; 155 hdiutil detach -force "${MY_TMP_DIR_DMG}"; 156 if ! rmdir -- "${MY_TMP_DIR_DMG}"; then 157 echo "error: failed to detach DMG from previous run (mountpoint='${MY_TMP_DIR_DMG}')." 1>&2; 158 exit 1; 159 fi 160 fi 161 if [ -n "${MY_DMG_FILE}" ]; then 162 echo "info: Mounting '${MY_DMG_FILE}' at '${MY_TMP_DIR_DMG}'..."; 163 if ! mkdir -p -- "${MY_TMP_DIR_DMG}"; then 164 echo "error: error creating '${MY_TMP_DIR_DMG}'." 1>&2; 165 exit 1; 166 fi 167 168 if ! hdiutil attach -mountpoint "${MY_TMP_DIR_DMG}" -noautoopen -nobrowse -noverify "${MY_DMG_FILE}"; then 169 echo "error: hdiutil attach failed for '${MY_DMG_FILE}'" 1>&2; 170 exit 1; 171 fi 172 for x in "${MY_TMP_DIR_DMG}/"*.pkg; 151 173 do 152 if ! mv -f "${MY_TMP_DIR}/x/Applications/Install Xcode.app/Contents/Resources/Packages/${i}" "${MY_TMP_DIR}/x/${i}"; then 153 echo "error: Failed to move the package ${i}." 1>&2; 174 if [ -e "${x}" ]; then 175 MY_PKG_FILE=$x; 176 fi 177 done 178 if [ -z "${MY_PKG_FILE}" ]; then 179 echo "error: Found no .pkg file inside the DMG attached at '${MY_TMP_DIR_DMG}'." 1>&2; 180 exit 1; 181 fi 182 echo "info: MY_PKG_FILE=${MY_PKG_FILE}"; 183 fi 184 185 # Check the package file. 186 echo "info: Checking '${MY_PKG_FILE}'..."; 187 if ! xar -tf "${MY_PKG_FILE}" > /dev/null ; then 188 echo "error: xar has trouble with '${MY_PKG_FILE}'." 1>&2; 189 exit 1; 190 fi 191 192 # 193 # Find the SDK packages and extract them to the 'x' directory. 194 # 195 # Command_Line_Tools_macOS_10.11_for_Xcode_8.2.dmg contains two packages with SDK 196 # in the name: CLTools_SDK_OSX1012.pkg and DevSDK_OSX1011.pkg. The former ends up 197 # in /Library/Developer/ and the latter in root (/). So, only pick the first one. 198 # 199 MY_SDK_PKGS=$(xar -tf "${MY_PKG_FILE}" | grep "SDK.*\.pkg$" | grep -v DevSDK_ | tr '\n\r' ' ') 200 if [ -z "${MY_SDK_PKGS}" ]; then 201 echo "error: Found no SDK packages in '${MY_PKG_FILE}'." 1>&2; 202 xar -tf "${MY_PKG_FILE}" 1>&2 203 exit 1; 204 fi 205 echo "info: Extracking SDK packages: ${MY_SDK_PKGS}" 206 207 if ! xar -xf "${MY_PKG_FILE}" -C "${MY_TMP_DIR_X}" ${MY_SDK_PKGS}; then 208 echo "error: Failed to extract ${MY_SDK_PKGS} from '${MY_PKG_FILE}'." 1>&2; 209 exit 1; 210 fi 211 212 # 213 # Expand the unpacked packages into the Y directory. 214 # 215 for pkg in ${MY_SDK_PKGS}; 216 do 217 echo "info: Expanding '${MY_TMP_DIR_X}/${pkg}' using pbzx and cpio..."; 218 if ! pbzx "${MY_TMP_DIR_X}/${pkg}/Payload" > "${MY_TMP_DIR_X}/${pkg}/Payload.unpacked" ; then 219 echo "error: Failed to unpack '${MY_TMP_DIR_X}/${pkg}/Payload' using pbzx." 1>&2; 220 exit 1; 221 fi 222 223 MY_CWD=`pwd` 224 cd "${MY_TMP_DIR_Y}" || exit 1; 225 if ! cpio -i < "${MY_TMP_DIR_X}/${pkg}/Payload.unpacked"; then 226 echo "error: Failed to expand '${MY_TMP_DIR_X}/${pkg}/Payload.unpacked' using cpio." 1>&2; 227 exit 1; 228 fi 229 cd "${MY_CWD}" 230 done 231 232 # 233 # Now, pick the bits we want from the Y directory and move it over to the destination directory. 234 # 235 for sdk in "${MY_TMP_DIR_Y}/Library/Developer/CommandLineTools/SDKs/MacOSX10"*.sdk; 236 do 237 MY_BASENAME=`basename "${sdk}"` 238 echo "info: Moving '${sdk}/' to '${MY_DST_DIR}/${MY_BASENAME}'..."; 239 if [ -z "${MY_DRY_RUN}" ]; then 240 if ! mv "${sdk}/" "${MY_DST_DIR}/${MY_BASENAME}"; then 241 echo "error: Failed to move '${sdk}/' to '${MY_DST_DIR}/${MY_BASENAME}'." 1>&2; 154 242 exit 1; 155 243 fi 156 done157 fi158 159 #160 # Work the sub-packages, extracting their payload content into the destination directory.161 #162 for i in $MY_PKGS;163 do164 rm -f -- "${MY_TMP_DIR}/x/Payload";165 echo "info: Extracting payload of sub-package ${i}...";166 if ! xar -xvf "${MY_TMP_DIR}/x/${i}" -C "${MY_TMP_DIR}/x" Payload; then167 echo "error: Failed to extract the payload of sub-package ${i}." 1>&2;168 exit 1;169 fi170 if ! tar xvf "${MY_TMP_DIR}/x/Payload" -C "${MY_DST_DIR}"; then171 echo "error: Failed to extract the payload content of sub-package ${i}." 1>&2;172 exit 1;173 244 fi 174 245 done … … 178 249 # 179 250 echo "info: Successfully extracted. Cleaning up temporary files..." 180 rm -Rf -- "${MY_TMP_DIR}/x/" 251 if [ -d "${MY_TMP_DIR_DMG}" ]; then 252 hdiutil detach -force "${MY_TMP_DIR_DMG}"; 253 fi 254 rm -Rf -- "${MY_TMP_DIR_X}/" "${MY_TMP_DIR_Y}/" 255 rmdir -- "${MY_TMP_DIR_DMG}" 181 256 rmdir -- "${MY_TMP_DIR}" 182 257
Note:
See TracChangeset
for help on using the changeset viewer.

