2
# ***** BEGIN LICENSE BLOCK *****
3
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
5
# The contents of this file are subject to the Mozilla Public License Version
6
# 1.1 (the "License"); you may not use this file except in compliance with
7
# the License. You may obtain a copy of the License at
8
# http://www.mozilla.org/MPL/
10
# Software distributed under the License is distributed on an "AS IS" basis,
11
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12
# for the specific language governing rights and limitations under the
15
# The Original Code is the installdmg.sh script from taols utilities
17
# The Initial Developer of the Original Code is
18
# Mozilla Corporation.
19
# Portions created by the Initial Developer are Copyright (C) 2009
20
# the Initial Developer. All Rights Reserved.
23
# Chris AtLee <catlee@mozilla.com>
24
# Robert Kaiser <kairo@kairo.at>
26
# Alternatively, the contents of this file may be used under the terms of
27
# either the GNU General Public License Version 2 or later (the "GPL"), or
28
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29
# in which case the provisions of the GPL or the LGPL are applicable instead
30
# of those above. If you wish to allow use of your version of this file only
31
# under the terms of either the GPL or the LGPL, and not to allow others to
32
# use your version of this file under the terms of the MPL, indicate your
33
# decision by deleting the provisions above and replace them with the notice
34
# and other provisions required by the GPL or the LGPL. If you do not delete
35
# the provisions above, a recipient may use your version of this file under
36
# the terms of any one of the MPL, the GPL or the LGPL.
38
# ***** END LICENSE BLOCK *****
40
# Unpack a disk image to a specified target folder
42
# Usage: unpack-diskimage <image_file>
50
# How long to wait before giving up waiting for the mount to finish (seconds)
53
# If mnt already exists, then the previous run may not have cleaned up
54
# properly. We should try to umount and remove the mnt directory.
55
if [ -d $MOUNTPOINT ]; then
56
echo "mnt already exists, trying to clean up"
57
hdiutil detach $MOUNTPOINT -force
61
# Install an on-exit handler that will unmount and remove the '$MOUNTPOINT' directory
62
trap "{ if [ -d $MOUNTPOINT ]; then hdiutil detach $MOUNTPOINT -force; rm -rdfv $MOUNTPOINT; fi; }" EXIT
66
hdiutil attach -verbose -noautoopen -mountpoint $MOUNTPOINT "$DMG_PATH"
67
# Wait for files to show up
68
# hdiutil uses a helper process, diskimages-helper, which isn't always done its
69
# work by the time hdiutil exits. So we wait until something shows up in the
70
# mnt directory. Due to the async nature of diskimages-helper, the best thing
71
# we can do is to make sure the glob() rsync is making can find files.
73
while [ "$(echo $MOUNTPOINT/*)" == "$MOUNTPOINT/*" ]; do
74
if [ $i -gt $TIMEOUT ]; then
75
echo "No files found, exiting"
81
# Now we can copy everything out of the $MOUNTPOINT directory into the target directory
82
rsync -av $MOUNTPOINT/* $MOUNTPOINT/.DS_Store $MOUNTPOINT/.background $MOUNTPOINT/.VolumeIcon.icns $TARGETPATH/.
83
hdiutil detach $MOUNTPOINT
85
# diskimage-helper prints messages to stdout asynchronously as well, sleep
86
# for a bit to ensure they don't disturb following commands in a script that
87
# might parse stdout messages