1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/build/package/mac_osx/unpack-diskimage Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,54 @@ 1.4 +#!/bin/bash 1.5 +# This Source Code Form is subject to the terms of the Mozilla Public 1.6 +# License, v. 2.0. If a copy of the MPL was not distributed with this 1.7 +# file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.8 + 1.9 +# Unpack a disk image to a specified target folder 1.10 +# 1.11 +# Usage: unpack-diskimage <image_file> 1.12 +# <mountpoint> 1.13 +# <target_path> 1.14 + 1.15 +DMG_PATH=$1 1.16 +MOUNTPOINT=$2 1.17 +TARGETPATH=$3 1.18 + 1.19 +# How long to wait before giving up waiting for the mount to finish (seconds) 1.20 +TIMEOUT=90 1.21 + 1.22 +# If mnt already exists, then the previous run may not have cleaned up 1.23 +# properly. We should try to umount and remove the mnt directory. 1.24 +if [ -d $MOUNTPOINT ]; then 1.25 + echo "mnt already exists, trying to clean up" 1.26 + hdiutil detach $MOUNTPOINT -force 1.27 + rm -rdfv $MOUNTPOINT 1.28 +fi 1.29 + 1.30 +# Install an on-exit handler that will unmount and remove the '$MOUNTPOINT' directory 1.31 +trap "{ if [ -d $MOUNTPOINT ]; then hdiutil detach $MOUNTPOINT -force; rm -rdfv $MOUNTPOINT; fi; }" EXIT 1.32 + 1.33 +mkdir -p $MOUNTPOINT 1.34 + 1.35 +hdiutil attach -verbose -noautoopen -mountpoint $MOUNTPOINT "$DMG_PATH" 1.36 +# Wait for files to show up 1.37 +# hdiutil uses a helper process, diskimages-helper, which isn't always done its 1.38 +# work by the time hdiutil exits. So we wait until something shows up in the 1.39 +# mnt directory. Due to the async nature of diskimages-helper, the best thing 1.40 +# we can do is to make sure the glob() rsync is making can find files. 1.41 +i=0 1.42 +while [ "$(echo $MOUNTPOINT/*)" == "$MOUNTPOINT/*" ]; do 1.43 + if [ $i -gt $TIMEOUT ]; then 1.44 + echo "No files found, exiting" 1.45 + exit 1 1.46 + fi 1.47 + sleep 1 1.48 + i=$(expr $i + 1) 1.49 +done 1.50 +# Now we can copy everything out of the $MOUNTPOINT directory into the target directory 1.51 +rsync -av $MOUNTPOINT/* $MOUNTPOINT/.DS_Store $MOUNTPOINT/.background $MOUNTPOINT/.VolumeIcon.icns $TARGETPATH/. 1.52 +hdiutil detach $MOUNTPOINT 1.53 +rm -rdf $MOUNTPOINT 1.54 +# diskimage-helper prints messages to stdout asynchronously as well, sleep 1.55 +# for a bit to ensure they don't disturb following commands in a script that 1.56 +# might parse stdout messages 1.57 +sleep 5