Skip to content

Commit

Permalink
Tidy up, unpack dmg fixes and use curl on Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
Ray Donnelly committed Feb 16, 2012
1 parent c104907 commit b6b2dde
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 52 deletions.
22 changes: 22 additions & 0 deletions bash-tools.sh
Expand Up @@ -47,6 +47,28 @@ uname-bt() {
echo $_UNAME
}

download() {
local _LFNAME=$2
if [[ -z $_LFNAME ]] ; then
_LFNAME=$(basename $1)
fi
if [[ ! -f $_LFNAME ]] ; then
if [[ "$(uname-bt)" == "Darwin" ]] ; then
curl -S -L -O $1 -o $_LFNAME
else
wget -c $1 -O $2
fi
fi
}

downloadStdout() {
if [[ "$(uname-bt)" == "Darwin" ]] ; then
curl -S -L $1
else
wget -c $1 -O -
fi
}

# Beautified echo commands
cecho() {
if [[ "$(uname-bt)" == "Windows" ]] ; then
Expand Down
17 changes: 11 additions & 6 deletions dmg-pkg-tools-wapper.sh → dmg-pkg-tools-wrapper.sh
Expand Up @@ -2,6 +2,10 @@

# Wrapper for command-line access to dmg-pkg-tools.sh

# Sample usages:
# ./dmg-pkg-tools-wrapper.sh --extract ../cross-mac/xcode_3.2.6_and_ios_sdk_4.3.dmg files/pkgs MacOSX10.5.pkg iPhoneSDK4_3.pkg
# ./dmg-pkg-tools-wrapper.sh --extract xcode_4.2.1_for_lion.dmg files files/pkgs InstallXcodeLion.pkg

. $(dirname "$0")/dmg-pkg-tools.sh

_OPERATION=$1
Expand All @@ -15,6 +19,7 @@ if [[ "$_OPERATION" == "--help" ]] || [[ -z $1 ]] ; then
fi
shift
TMPDIR=$PWD/tmp
MNTDIR=$PWD/mnt
INSTDIR=$PWD/install
mkdir -p $TMPDIR
build_tools_dmg $TMPDIR $INSTDIR
Expand All @@ -38,18 +43,18 @@ if [[ "$_OPERATION" = "--cache" ]] || [[ "$_OPERATION" = "--extract" ]] ; then
fi
DEST=$1
shift
if [[ "$_OPERATION" == "--extract" ]] ; then
# For --extract, XDEST is where the package's contents get written (e.g. files/sdks)
XDEST=$1
shift
fi
DEST=${DEST%/*}
if [[ ! -d $DEST ]] ; then
message "Created $DEST folder"
mkdir -p $DEST
fi
if [[ "$_OPERATION" == "--extract" ]] ; then
# For --extract, XDEST is where the package's contents get written (e.g. files/sdks)
XDEST=$1
shift
fi
FILES=("$@")
CACHED_PACKAGES=( $(cache_packages $DMGFILE $DEST $KEEP_MOUNTED $KEY "${FILES[@]}") )
CACHED_PACKAGES=( $(cache_packages $DMGFILE $DEST $KEEP_MOUNTED $KEY $TMPDIR $MNTDIR "${FILES[@]}") )
echo "Cached packages ${CACHED_PACKAGES[@]}"
if [[ "$_OPERATION" == "--extract" ]] ; then
extract_packages_cached $XDEST ${CACHED_PACKAGES[@]}
Expand Down
44 changes: 22 additions & 22 deletions dmg-pkg-tools.sh
@@ -1,16 +1,14 @@
#!/bin/bash

# Another reference, this time cctools version 809 from gentoo:
# http://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/sys-devel/binutils-apple/binutils-apple-4.2.ebuild?revision=1.2
# It seems that 7z can handle both dmg and pkg files so, for Windows (at least)
# we should use this (although I've made all of the tools compile on Windows,
# we can't mount img files so this script can't be used on that platform)

# Keeps a cache of the mounted DMG file in $(dirname $0)/.dmgtools.mounted
# Keeps a cache of the loop device in $(dirname $0)/.dmgtools.loopdev
# to avoid re-mount un-necessarily.
# Keeps a cache of copied-from-dmg files to avoid mounting un-necessarily.

# Sample usages:
# ./dmg-pkg-tools.sh --extract ../cross-mac/xcode_3.2.6_and_ios_sdk_4.3.dmg files/pkgs MacOSX10.5.pkg iPhoneSDK4_3.pkg

. ./bash-tools.sh

patch_mingw_types_h() {
Expand Down Expand Up @@ -55,10 +53,8 @@ patch_mingw_types_h() {
}

downloadUntar() {
download "$1"
local _FNAME=$(basename $1)
if [[ ! -f $_FNAME ]] ; then
wget -c $1
fi
tar -zxf $_FNAME
}

Expand Down Expand Up @@ -381,7 +377,7 @@ umount_dmg() {
if [[ -f $_MNT_LOOPDEV ]] ; then
local _MNT_DIR=( $(cat $_MNT_DIRCACHE) )

if [[ $UNAME == "Darwin" ]] ; then
if [[ "$(uname-bt)" == "Darwin" ]] ; then
$SUDO hdiutil detach $_MNT_DIR
else
# shouldn't we have a DEBUG var and only
Expand Down Expand Up @@ -440,7 +436,7 @@ mount_dmg() {
fi
fi
[[ -d $_MNT_DIR ]] || mkdir -p $_MNT_DIR
if [[ "$UNAME" == "Darwin" ]] ; then
if [[ "$(uname-bt)" == "Darwin" ]] ; then
# echo "In order to extract `basename $1`, I am going to mount it."
# echo "This needs to be done as root."
sudo hdiutil attach -noverify -mountpoint $_MNT_DIR $_DMG
Expand Down Expand Up @@ -487,6 +483,10 @@ cache_packages() {
shift
local _KEY=$1
shift
local _TMPDIR=$1
shift
local _MNTDIR=$1
shift
local _PKGS=("$@")
shift

Expand All @@ -504,23 +504,21 @@ cache_packages() {
mkdir -p $_DST

if [[ ${_ALL_PKGS_FOUND} = 0 ]] ; then
mount_dmg $TMP_DIR $_DMG $MNT_DIR $_KEY
mount_dmg $_TMPDIR $_DMG $_MNTDIR $_KEY
_MOUNTED=1
for i in "${_PKGS[@]}"
do
local _EXT="${i##*.}"
local _CACHE_FILE=${_DST}/$(basename ${_DMG} ".dmg")##$(basename "${i}" ${_EXT})${_EXT}
if [[ ! -f ${_CACHE_FILE} ]] && [[ -f ${MNT_DIR}/$i ]] ; then
cp "${MNT_DIR}/$i" "${_CACHE_FILE}"
if [[ ! -f ${_CACHE_FILE} ]] && [[ -f ${_MNTDIR}/$i ]] ; then
cp "${_MNTDIR}/$i" "${_CACHE_FILE}"
echo "${_CACHE_FILE}"
fi
# if [[ ! -r ${MNT_DIR}/$i ]] ; then
# error "I tried to cache ${MNT_DIR}/$i but I couldn't find it!"
# echo $(ls ${MNT_DIR}/Packages)
# exit 1
# fi
# else
# fi
if [[ ! -r ${_MNTDIR}/$i ]] ; then
error "I tried to cache ${_MNTDIR}/$i but I couldn't find it!"
echo $(ls ${_MNTDIR}/Packages)
exit 1
fi
done
else
for i in "${_PKGS[@]}"
Expand Down Expand Up @@ -553,13 +551,15 @@ extract_packages_cached() {
cat Payload | zcat | cpio -id
rm Payload
popd
# else
# error "Failed to extract $_CACHE_FILE"
else
error "Failed to extract $_CACHE_FILE"
fi
done
}

extract_packages() {
echo "wtf"
echo "wtf"
message_status "in extract_packages"
local _OUTDIR=$1; shift
local _PKGSDIR=$1; shift
Expand Down
45 changes: 21 additions & 24 deletions toolchain.sh
Expand Up @@ -33,12 +33,11 @@

# What version of the toolchain are we building?
TOOLCHAIN_VERSION="4.3"
#TOOLCHAIN_VERSION="3.1.2"
OSXVER="10.6"
MACOSX="MacOSX${OSXVER}"

# Uses -m32 to force 32bit build of everything. 64bit is broken atm
# and my reference darwin-native-compiler is built as 32bit too.
# and the reference darwin-native-compiler is built as 32bit too.
FORCE_32BIT=1

# what device are we building for?
Expand Down Expand Up @@ -73,8 +72,6 @@ TOOLCHAIN="${IPHONEDEV_DIR}"
[ -z $SYS_DIR ] && SYS_DIR="${TOOLCHAIN}/sys"
[ -z $PKG_DIR ] && PKG_DIR="${TOOLCHAIN}/pkgs"



# Usage
# ======================
#
Expand Down Expand Up @@ -151,46 +148,47 @@ TOOLCHAIN="${IPHONEDEV_DIR}"
# Runs classdump on a selected iPhone over SSH in order to generate useable
# Objective-C headers for (mostly) private frameworks.

# Error reporting, coloured printing.
# Error reporting, coloured printing, downloading.
. bash-tools.sh

# function for building tools (xar, dmg2img, cpio, nano and all the libs they depend on)
. dmg-pkg-tools.sh

UNAME=$(uname-bt)
if [[ "$UNAME" == "Windows" ]] ; then
EXEEXT=".exe"
LN=lns.exe
LN=lns.exe # Nokia's tool, patched and built by dmg-pkg-tools.sh.
fi

FILES_DIR="${IPHONEDEV_DIR}/files"
SDKS_DIR="${IPHONEDEV_DIR}/sdks"
TMP_DIR="${IPHONEDEV_DIR}/tmp"
MNT_DIR="${FILES_DIR}/mnt"
FW_DIR="${FILES_DIR}/firmware"
HOST_DIR="${IPHONEDEV_DIR}/host-install"

#IPHONE_SDK="iphone_sdk_*.dmg"
#IPHONE_SDK="*sdk_${TOOLCHAIN_VERSION}_final.dmg"
#IPHONE_SDK="/usr/src/cross-mac/xcode_3.2.6_and_ios_sdk_4.3.dmg"
#IPHONE_SDK="/usr/src/cross-mac/iphone_sdk_3.1.3_with_xcode_3.1.4__leopard__9m2809a.dmg"
#[[ ! -f $IPHONE_SDK_DMG ]] && IPHONE_SDK_DMG="${FILES_DIR}/${IPHONE_SDK}"
#echo IPHONE_SDK $IPHONE_SDK IPHONE_SDK $IPHONE_SDK
IPHONE_SDK_DMG="$PWD/../xcode_3.2.6_and_ios_sdk_4.3.dmg"
#IPHONE_SDK_DMG="$PWD/../iphone_sdk_3.1.3_with_xcode_3.1.4__leopard__9m2809a.dmg"
IPHONE_SDK_DMG="$PWD/../dmgs/xcode_3.2.6_and_ios_sdk_4.3.dmg"
#IPHONE_SDK_DMG="$PWD/../dmgs/iphone_sdk_3.1.3_with_xcode_3.1.4__leopard__9m2809a.dmg"
# The layout of xcode_4.2.1_for_lion.dmg is significantly different from earlier dmgs
# so this doesn't currently work.
#IPHONE_SDK_DMG="$PWD/../dmgs/xcode_4.2.1_for_lion.dmg"

# URLS
IPHONEWIKI_KEY_URL="http://www.theiphonewiki.com/wiki/index.php?title=Firmware"
DARWIN_SOURCES_DIR="$FILES_DIR/darwin_sources"

SUDO=sudo
GAWK=gawk
URLDL=wget
if [[ "$(uname-bt)" == "Windows" ]] ; then
SUDO=
fi
if [[ "$(uname-bt)" == "Darwin" ]] ; then
GAWK=awk
URLDL=curl
fi

NEEDED_COMMANDS="gcc make mount $SUDO zcat tar wget unzip $GAWK bison flex patch"
NEEDED_COMMANDS="gcc make mount $SUDO zcat tar $URLDL unzip $GAWK bison flex patch"

HERE=`pwd`

Expand Down Expand Up @@ -222,19 +220,18 @@ ln_s() {
fi
}

# Builds dmg2img decryption tools and vfdecrypt, which we will use later to convert dmgs to
# Builds lns (Windows), dmg2img decryption tools and vfdecrypt, which we will use later to convert dmgs to
# images, so that we can mount them.
build_tools() {

build_tools_dmg $PWD/tmp $HOST_DIR $PREFIX

# Urgh, no thanks - will find a better way to do this.
# if [[ `strings /usr/bin/as | grep as_driver | wc -w` < 1 ]]; then
# cp /usr/bin/as /usr/bin/i386-redhat-linux-as
# message_status "Rename /usr/bin/as in /usr/bin/i386-redhat-linux-as"
# cp as_driver/as_driver /usr/bin/as
# fi
# message_status "as_driver installed in /usr/bin/as"

}

toolchain_extract_headers() {
Expand Down Expand Up @@ -286,8 +283,8 @@ toolchain_extract_headers() {

PLIST="${MPKG_NAME}.mpkg/Contents/version.plist"
message_status "cache_packages for $PLIST"
CACHED_PLIST=( $(cache_packages $IPHONE_SDK_DMG $PKG_DIR 0 0 "$PLIST") )
message_status "cache_packages done for $PLIST"
CACHED_PLIST=( $(cache_packages $IPHONE_SDK_DMG $PKG_DIR 0 0 $TMP_DIR $MNT_DIR "$PLIST") )
message_status "cache_packages done for $PLIST, result is $CACHED_PLIST"
CACHED_PLIST_FILE=${CACHED_PLIST[0]}
SDK_VERSION=$(plist_key CFBundleShortVersionString "/" "${CACHED_PLIST_FILE}" | awk '
BEGIN { FS="." }
Expand Down Expand Up @@ -328,7 +325,7 @@ toolchain_extract_headers() {
PACKAGES[${#PACKAGES[*]}]="Packages/MacOSX10.6.pkg"

message_status "Caching packages ${PACKAGES[@]}"
CACHED_PACKAGES=( $(cache_packages $IPHONE_SDK_DMG $PKG_DIR 0 0 "${PACKAGES[@]}") )
CACHED_PACKAGES=( $(cache_packages $IPHONE_SDK_DMG $PKG_DIR 0 0 $TMP_DIR $MNT_DIR "${PACKAGES[@]}") )

message_status "Extracting ${CACHED_PACKAGES[@]}"
extract_packages_cached ${TMP_SDKS_DIR} "${CACHED_PACKAGES[@]}"
Expand Down Expand Up @@ -375,7 +372,7 @@ toolchain_extract_firmware_old() {
else
message_status "Downloading: $FW_FILE"
cd $TMP_DIR
wget -nc -c $APPLE_DL_URL
download $APPLE_DL_URL
mv $FW_FILE $FW_DIR
FW_FILE=$FW_DIR/$FW_FILE
fi
Expand Down Expand Up @@ -454,15 +451,15 @@ toolchain_extract_firmware_old() {
echo "I'm going to try to fetch it from $IPHONEWIKI_KEY_URL...."
echo "Checking $DEVICE and $FIRMWARE_VERSION"

IPHONEWIKI_KEY_URL=$( wget --quiet -O - $IPHONEWIKI_KEY_URL | awk '
IPHONEWIKI_KEY_URL=$( $(downloadStdout $IPHONEWIKI_KEY_URL) | awk '
BEGIN { IGNORECASE = 1; }
/name="'${DEVICE}'/ { found_phone=1; }
/.*'${FIRMWARE_VERSION}'.*/ && found_phone { found_firmware=1; }
/.*href=.*/ && found_firmware { while(sub(/href=|"/,"", $3));; print $3; exit;}
')

echo "Finding intermediate URL : http://www.theiphonewiki.com$IPHONEWIKI_KEY_URL"
DECRYPTION_KEY_SYSTEM=`wget --quiet -O - "http://www.theiphonewiki.com"$IPHONEWIKI_KEY_URL | awk '
DECRYPTION_KEY_SYSTEM=`$(downloadStdout http://www.theiphonewiki.com$IPHONEWIKI_KEY_URL) | awk '
BEGIN { IGNORECASE = 1; }
/.*VFDecrypt<\/a>.*/ { print $5;}
'`
Expand Down

0 comments on commit b6b2dde

Please sign in to comment.