blob: 42b20b28b832b5e3e5916064d557ed282501dffc [file] [log] [blame]
# How long to wait before giving up waiting for the mount to fininsh
# If mnt already exists, then the previous run may not have cleaned up
# properly. We should try to umount and remove the mnt directory.
if [ -d mnt ]; then
echo "mnt already exists, trying to clean up"
hdiutil detach mnt -force
rm -rdf mnt
# Install an on-exit handler that will unmount and remove the 'mnt' directory
trap "{ if [ -d mnt ]; then hdiutil detach mnt -force; rm -rdfv mnt; fi; }" EXIT
mkdir -p mnt
hdiutil attach -noautoopen -mountpoint ./mnt "$1"
# Wait for files to show up
# hdiutil uses a helper process, diskimages-helper, which isn't always done its
# work by the time hdiutil exits. So we wait until something shows up in the
# mnt directory.
while [ "$(echo mnt/*)" == "mnt/*" ]; do
if [ $i -gt $TIMEOUT ]; then
echo "No files found, exiting"
exit 1
sleep 1
i=$(expr $i + 1)
# Now we can copy everything out of the mnt directory into the current directory
rsync -a ./mnt/* .
hdiutil detach mnt
rm -rdf mnt
# Sleep for a bit to let messages from diskimage-helper go away
sleep 5