Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / tools / update-verify / release / common / unpack-diskimage.sh
blob7e34fd2a8b8b5e4c08e233522d6f4cc34908ea2f
1 #!/bin/bash
2 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 # The contents of this file are subject to the Mozilla Public License Version
5 # 1.1 (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 # http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS IS" basis,
10 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
11 # for the specific language governing rights and limitations under the
12 # License.
14 # The Original Code is the installdmg.sh script from taols utilities
16 # The Initial Developer of the Original Code is
17 # Mozilla Corporation.
18 # Portions created by the Initial Developer are Copyright (C) 2009
19 # the Initial Developer. All Rights Reserved.
21 # Contributor(s):
22 # Chris AtLee <catlee@mozilla.com>
23 # Robert Kaiser <kairo@kairo.at>
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
38 # Unpack a disk image to a specified target folder
40 # Usage: unpack-diskimage <image_file>
41 # <mountpoint>
42 # <target_path>
44 DMG_PATH=$1
45 MOUNTPOINT=$2
46 TARGETPATH=$3
47 LOGFILE=unpack.output
49 # How long to wait before giving up waiting for the mount to fininsh
50 TIMEOUT=90
52 # If the mount point already exists, then the previous run may not have cleaned
53 # up properly. We should try to umount and remove the its directory.
54 if [ -d "$MOUNTPOINT" ]; then
55 echo "$MOUNTPOINT already exists, trying to clean up"
56 hdiutil detach "$MOUNTPOINT" -force
57 rm -rdfv "$MOUNTPOINT"
60 # Install an on-exit handler that will unmount and remove the '$MOUNTPOINT' directory
61 trap '{ if [ -d $MOUNTPOINT ]; then hdiutil detach $MOUNTPOINT -force; rm -rdfv $MOUNTPOINT; fi; }' EXIT
63 mkdir -p "$MOUNTPOINT"
65 hdiutil attach -verbose -noautoopen -mountpoint "$MOUNTPOINT" "$DMG_PATH" &> $LOGFILE
66 # Wait for files to show up
67 # hdiutil uses a helper process, diskimages-helper, which isn't always done its
68 # work by the time hdiutil exits. So we wait until something shows up in the
69 # mount point directory.
70 i=0
71 while [ "$(echo "$MOUNTPOINT"/*)" == "$MOUNTPOINT/*" ]; do
72 if [ "$i" -gt $TIMEOUT ]; then
73 echo "No files found, exiting"
74 exit 1
76 sleep 1
77 i=$((i+1))
78 done
79 # Now we can copy everything out of the $MOUNTPOINT directory into the target directory
80 rsync -av "$MOUNTPOINT"/* "$MOUNTPOINT"/.DS_Store "$MOUNTPOINT"/.background "$MOUNTPOINT"/.VolumeIcon.icns "$TARGETPATH"/ > $LOGFILE
81 # sometimes hdiutil fails with "Resource busy"
82 hdiutil detach "$MOUNTPOINT" || { sleep 10; \
83 if [ -d "$MOUNTPOINT" ]; then hdiutil detach "$MOUNTPOINT" -force; fi; }
84 i=0
85 while [ "$(echo "$MOUNTPOINT"/*)" != "$MOUNTPOINT/*" ]; do
86 if [ "$i" -gt $TIMEOUT ]; then
87 echo "Cannot umount, exiting"
88 exit 1
90 sleep 1
91 i=$((i+1))
92 done
93 rm -rdf "$MOUNTPOINT"