Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | #!/bin/bash |
michael@0 | 2 | # This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | # License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 5 | |
michael@0 | 6 | # Unpack a disk image to a specified target folder |
michael@0 | 7 | # |
michael@0 | 8 | # Usage: unpack-diskimage <image_file> |
michael@0 | 9 | # <mountpoint> |
michael@0 | 10 | # <target_path> |
michael@0 | 11 | |
michael@0 | 12 | DMG_PATH=$1 |
michael@0 | 13 | MOUNTPOINT=$2 |
michael@0 | 14 | TARGETPATH=$3 |
michael@0 | 15 | |
michael@0 | 16 | # How long to wait before giving up waiting for the mount to finish (seconds) |
michael@0 | 17 | TIMEOUT=90 |
michael@0 | 18 | |
michael@0 | 19 | # If mnt already exists, then the previous run may not have cleaned up |
michael@0 | 20 | # properly. We should try to umount and remove the mnt directory. |
michael@0 | 21 | if [ -d $MOUNTPOINT ]; then |
michael@0 | 22 | echo "mnt already exists, trying to clean up" |
michael@0 | 23 | hdiutil detach $MOUNTPOINT -force |
michael@0 | 24 | rm -rdfv $MOUNTPOINT |
michael@0 | 25 | fi |
michael@0 | 26 | |
michael@0 | 27 | # Install an on-exit handler that will unmount and remove the '$MOUNTPOINT' directory |
michael@0 | 28 | trap "{ if [ -d $MOUNTPOINT ]; then hdiutil detach $MOUNTPOINT -force; rm -rdfv $MOUNTPOINT; fi; }" EXIT |
michael@0 | 29 | |
michael@0 | 30 | mkdir -p $MOUNTPOINT |
michael@0 | 31 | |
michael@0 | 32 | hdiutil attach -verbose -noautoopen -mountpoint $MOUNTPOINT "$DMG_PATH" |
michael@0 | 33 | # Wait for files to show up |
michael@0 | 34 | # hdiutil uses a helper process, diskimages-helper, which isn't always done its |
michael@0 | 35 | # work by the time hdiutil exits. So we wait until something shows up in the |
michael@0 | 36 | # mnt directory. Due to the async nature of diskimages-helper, the best thing |
michael@0 | 37 | # we can do is to make sure the glob() rsync is making can find files. |
michael@0 | 38 | i=0 |
michael@0 | 39 | while [ "$(echo $MOUNTPOINT/*)" == "$MOUNTPOINT/*" ]; do |
michael@0 | 40 | if [ $i -gt $TIMEOUT ]; then |
michael@0 | 41 | echo "No files found, exiting" |
michael@0 | 42 | exit 1 |
michael@0 | 43 | fi |
michael@0 | 44 | sleep 1 |
michael@0 | 45 | i=$(expr $i + 1) |
michael@0 | 46 | done |
michael@0 | 47 | # Now we can copy everything out of the $MOUNTPOINT directory into the target directory |
michael@0 | 48 | rsync -av $MOUNTPOINT/* $MOUNTPOINT/.DS_Store $MOUNTPOINT/.background $MOUNTPOINT/.VolumeIcon.icns $TARGETPATH/. |
michael@0 | 49 | hdiutil detach $MOUNTPOINT |
michael@0 | 50 | rm -rdf $MOUNTPOINT |
michael@0 | 51 | # diskimage-helper prints messages to stdout asynchronously as well, sleep |
michael@0 | 52 | # for a bit to ensure they don't disturb following commands in a script that |
michael@0 | 53 | # might parse stdout messages |
michael@0 | 54 | sleep 5 |