diff options
author | schmonz <schmonz@pkgsrc.org> | 2006-08-30 04:29:53 +0000 |
---|---|---|
committer | schmonz <schmonz@pkgsrc.org> | 2006-08-30 04:29:53 +0000 |
commit | 343f2433e11a02d50980e8c818fea09e28a5bb00 (patch) | |
tree | 1f91a7eb310480cd7c27aedaf08e7c8b64d11cd4 /bootstrap/darwindiskimage | |
parent | ab4b65ff04c5d077c4db5887309b5569df8fc456 (diff) | |
download | pkgsrc-343f2433e11a02d50980e8c818fea09e28a5bb00.tar.gz |
Rename "ufsdiskimage" to "darwindiskimage" in preparation for
creating case-sensitive HFS+ instead of UFS on Darwin 7.0 or newer.
Diffstat (limited to 'bootstrap/darwindiskimage')
-rwxr-xr-x | bootstrap/darwindiskimage | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/bootstrap/darwindiskimage b/bootstrap/darwindiskimage new file mode 100755 index 00000000000..2d052b4ea04 --- /dev/null +++ b/bootstrap/darwindiskimage @@ -0,0 +1,107 @@ +#!/bin/sh +# +# $NetBSD: darwindiskimage,v 1.1 2006/08/30 04:29:53 schmonz Exp $ + +_getdevice_and_halfway_mount() +{ + hdid -nomount "$1" | _getdevicebasename | tail -1 +} + +_getdevicebasename() +{ + awk '{print $1}' | sed -e 's|^/dev/||' +} + +_normalize_filename() +{ + echo "$1" | sed -e 's|\.dmg$||' -e 's|$|.dmg|' +} + +dmg_create() +{ + local file mountedname megabytes device + [ $# -eq 2 ] || die 1 "Usage: $0 create <file> <megabytes>" + + file="`_normalize_filename \"$1\"`" + mountedname="`basename \"${file}\" .dmg`" + megabytes=$2 + + # create + hdiutil create -quiet "${file}" -megabytes ${megabytes} \ + -partitionType Apple_UFS -layout SPUD + + # format + device=`_getdevice_and_halfway_mount "${file}"` + newfs ${device} + hdiutil eject -quiet "${device}" + + # rename + hdiutil mount "${file}" + disktool -n "${device}" "${mountedname}" + hdiutil eject -quiet "${device}" + # mountpoint="`hdiutil mount -verbose '${file}' | grep -A 1 '<key>mount-point</key>' | grep -v '<key>mount-point</key>' | sed -e 's|<string>||' -e 's|</string>||' | awk '{print $1}'`" + # mount | grep '^/dev/disk1' | awk '{print $3}' | sed -e 's|^/Volumes/||' +} + +dmg_mount() +{ + local file device exitcode + [ $# -eq 1 ] || die 1 "Usage: $0 mount <file>" + + file="`_normalize_filename \"$1\"`" + + hdiutil mount ${file} +} + + +dmg_umount() +{ + local mountpoint device + [ $# -eq 1 ] || die 1 "Usage: $0 umount <mount-point>" + + mountpoint="$1" + device=`mount | grep "${mountpoint} (local" | _getdevicebasename` + + [ "${device}" ] || die 1 "error: no device mounted at ${mountpoint}" + + hdiutil eject -quiet "${device}" +} + +die() +{ + local exitcode + exitcode=$1; shift + warn "$@" + exit ${exitcode} +} + +warn() +{ + echo >&2 "$@" +} + +try() +{ + exitcode=$1; shift + action=$1; shift + error=`"${action}" "$@" 2>&1` || die ${exitcode} "${error}" +} + +main() +{ + [ $# -eq 0 ] && die 1 "Usage: $0 <create|mount|umount>" + ACTION="$1"; shift + case ${ACTION} in + create|mount|umount) + try 1 "dmg_${ACTION}" "$@" + return 0 + ;; + *) + die 1 "Usage: $0 <create|mount|umount>" + ;; + esac +} + +PATH=${PATH}:/sbin:/usr/sbin +main "$@" +exit $? |