head	1.3;
access;
symbols;
locks; strict;
comment	@# @;


1.3
date	2004.03.12.13.05.14;	author grant;	state dead;
branches;
next	1.2;

1.2
date	2002.07.26.21.26.18;	author schmonz;	state Exp;
branches;
next	1.1;

1.1
date	2002.07.24.09.06.31;	author agc;	state Exp;
branches;
next	;


desc
@@


1.3
log
@remove; bootstrap-pkgsrc has been moved to pkgsrc/bootstrap/ now.
@
text
@#!/bin/sh
#
# $NetBSD: ufsdiskimage,v 1.2 2002/07/26 21:26:18 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
}

main "$@@"
exit $?
@


1.2
log
@Create and handle disk images with a partition map. (This is what
Disk Copy does.)
@
text
@d3 1
a3 1
# $NetBSD$
@


1.1
log
@Additions and modifications from Amitai Schlair (schmonz@@netbsd.org) which
collectively make the bootstrap-pkgsrc kit into the released 18th May 2002
one (20020518).

+ add a short README file explaining the process through which a UFS
can be created.

+ add a shell script to create the UFS disk image

+ rework the bootstrap kit

+ Replace g++ with c++ in Darwin.sys.mk
@
text
@d2 2
d7 1
a7 1
	hdid -nomount "$1" | _getdevicebasename
d31 1
a31 1
		-partitionType Apple_UFS -layout NONE
@

