#!/bin/sh

K=/usr/src/sys/arch/amd64/compile/GENERIC
O=/usr/obj/amd64-x86_64/media
set -e
I=$O/images/NetBSD-8.99.12-amd64.iso
B=$O/amd64/installation/cdrom/boot-com.iso,media=cdrom \
I=NetBSD-8.0_BETA-amd64.iso
B=$I,media=cdrom

case $1 in
install)
	echo -n "are you sure?"
	read y
	case $y in
	[yY]*) break;;
	*)	echo "bye"; exit 0;;
	esac
	dd if=/dev/zero of=install.img seek=10m count=1
	dd if=/dev/zero of=test.img seek=10m count=1
	cat << EOF
Install on the whole disk, com console, bios baud, minimal sets
EOF
	qemu-system-x86_64 \
	    -nographic \
	    -drive file=install.img,media=disk,snapshot=off,format=raw \
	    -drive file=$B -drive file=$I -boot d
	;;
build)
	(cd $K && make)
	vnconfig -c vnd0 install.img
	mount /dev/vnd0a /mnt
	cp $K/netbsd /mnt
	umount /mnt
	vnconfig -u vnd0
	;;
run)
	qemu-system-x86_64 \
	    -m 1024 \
	    -k en-us \
	    -drive file=install.img,media=disk,snapshot=off,format=raw \
	    -device virtio-scsi-pci,id=scsi \
	    -device scsi-hd,drive=hd \
	    -drive if=none,id=hd,file=test.img,format=raw \
	    -net nic,macaddr=ba:be:00:fa:ce:01,model=virtio \
	    -net user,hostfwd=tcp::2003-:22 \
	    -boot c
	;;
*)
	cat << EOF 1>&2
Usage: $0 [install|build|run]
EOF
	;;
esac
	    -nographic \
