xcode-4.1-extrator.sh revision 820f20ee627f0685aea131b9cebe105d0b3e554d
# $Id$
## @file
# Extracts the necessary bits from the Xcode 4.1 lion package (inside installercode_41_lion.dmg).
#
# Copyright (C) 2014 Oracle Corporation
#
# This file is part of VirtualBox Open Source Edition (OSE), as
# available from http://www.virtualbox.org. This file is free software;
# General Public License (GPL) as published by the Free Software
# Foundation, in version 2 as it comes in the "COPYING" file of the
# VirtualBox OSE distribution. VirtualBox OSE is distributed in the
# hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
#
#
# Make sure we're talking the same language.
#
LC_ALL=C
export LC_ALL
#
# Figure the tools/darwin.x86 location.
#
#
# Constants.
#
MY_PKGS="gcc4.2.pkg llvm-gcc4.2.pkg DeveloperToolsCLI.pkg xcrun.pkg JavaSDK.pkg MacOSX10.6.pkg MacOSX10.7.pkg"
do
MY_FULL_PKGS[$((${#MY_FULL_PKGS[*]}))]="./Applications/Install Xcode.app/Contents/Resources/Packages/${i}"
done
#
# Parse arguments.
#
MY_DST_DIR="${MY_DARWIN_DIR}/xcode/v41"
my_usage()
{
echo "usage: $0 [--tmpdir|-t <tmpdir>] <--destination|-d> <dstdir> <--filename|-f> <dir/InstallXcodeLion.pkg>";
exit $1;
}
while test $# -ge 1;
do
ARG=$1;
shift;
--tmpdir|-t)
if test $# -eq 0; then
echo "error: missing --tmpdir argument." 1>&2;
exit 1;
fi
shift;
;;
--destination|-d)
if test $# -eq 0; then
echo "error: missing --tmpdir argument." 1>&2;
exit 1;
fi
MY_DST_DIR="$1";
shift;
;;
--filename|-f)
if test $# -eq 0; then
echo "error: missing --filename argument." 1>&2;
exit 1;
fi
MY_PKG_FILE="$1";
shift;
;;
--h*|-h*|-?|--?)
my_usage 0;
esac
done
# Check the package file.
if [ -z "${MY_PKG_FILE}" ]; then
my_usage 1;
fi
echo "error: xar has trouble with '${MY_PKG_FILE}'." 1>&2;
exit 1;
fi
# Check the destination directory.
if [ -z "${MY_DST_DIR}" ]; then
echo "error: missing --destination <dstdir>." 1>&2;
my_usage 1;
fi
if ! mkdir -p "${MY_DST_DIR}"; then
echo "error: error creating '${MY_DST_DIR}'." 1>&2;
exit 1;
fi
# Check the temporary directory.
if [ -z "${MY_TMP_DIR}" ]; then
echo "error: empty --tmpdir <tmpdir>." 1>&2;
my_usage 1;
fi
if ! mkdir -p "${MY_TMP_DIR}/x"; then
echo "error: error creating '${MY_TMP_DIR}/x'." 1>&2;
exit 1;
fi
#
# Extract the "Applications/Install Xcode.app" payload, calling it MainPayload.tar.
#
if [ ! -f "${MY_TMP_DIR}/x/MainPayload.tar" ]; then
echo "info: Extracting '${MY_PKG_FILE}'..."
echo "error: extraction error." 1>&2;
exit 1;
fi
if ! mv -f "${MY_TMP_DIR}/x/InstallXcodeLion.pkg/Payload" "${MY_TMP_DIR}/x/MainPayload.tar"; then
echo "error: Failed to move the package payload. Did you get the right package file?" 1>&2;
exit 1;
fi
fi
#
# Extract the sub-packages from MainPayload.tar.
#
if [ ! -f "${MY_TMP_DIR}/x/${MY_LAST_PKG}" ]; then
echo "info: Extracting packages from 'MainPayload.tar'..."
exit 1;
fi
do
if ! mv -f "${MY_TMP_DIR}/x/Applications/Install Xcode.app/Contents/Resources/Packages/${i}" "${MY_TMP_DIR}/x/${i}"; then
echo "error: Failed to move the package ${i}." 1>&2;
exit 1;
fi
done
fi
#
# Work the sub-packages, extracting their payload content into the destination directory.
#
do
echo "info: Extracting payload of sub-package ${i}...";
echo "error: Failed to extract the payload of sub-package ${i}." 1>&2;
exit 1;
fi
echo "error: Failed to extract the payload content of sub-package ${i}." 1>&2;
exit 1;
fi
done
#
# Clean up.
#
echo "info: Successfully extracted. Cleaning up temporary files..."
rmdir -- "${MY_TMP_DIR}"