usermode revision 1.1
11.1Sagc#! /bin/sh
21.1Sagc
31.1Sagc# $NetBSD: usermode,v 1.1 2012/01/15 02:01:02 agc Exp $
41.1Sagc
51.1Sagc# Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
61.1Sagc# All rights reserved.
71.1Sagc#
81.1Sagc# Redistribution and use in source and binary forms, with or without
91.1Sagc# modification, are permitted provided that the following conditions
101.1Sagc# are met:
111.1Sagc# 1. Redistributions of source code must retain the above copyright
121.1Sagc#    notice, this list of conditions and the following disclaimer.
131.1Sagc# 2. Redistributions in binary form must reproduce the above copyright
141.1Sagc#    notice, this list of conditions and the following disclaimer in the
151.1Sagc#    documentation and/or other materials provided with the distribution.
161.1Sagc#
171.1Sagc# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
181.1Sagc# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
191.1Sagc# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
201.1Sagc# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
211.1Sagc# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
221.1Sagc# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
231.1Sagc# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
241.1Sagc# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
251.1Sagc# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
261.1Sagc# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
271.1Sagc#
281.1Sagc
291.1Sagcimage=usermode.img
301.1Sagcpkgs=pkgs.img
311.1Sagc
321.1Sagcwhile [ $# -gt 0 ]; do
331.1Sagc	case "$1" in
341.1Sagc	-v)	set -x ;;
351.1Sagc	*)	break ;;
361.1Sagc	esac
371.1Sagc	shift
381.1Sagcdone
391.1Sagc
401.1Sagcif [ $# -gt 0 ]; then
411.1Sagc	image=$1
421.1Sagcfi
431.1Sagc
441.1Sagc# check bridging is set up
451.1Sagcbridging=$(ifconfig tap0 | awk '$1 == "inet" { print $2 }')
461.1Sagccase "${bridging}" in
471.1Sagc*.*.*.*)	echo "bridging is already up on ${bridging}" ;;
481.1Sagc*)		interface=$(ifconfig -l | awk '{print $1}')
491.1Sagc		sudo ifconfig tap0 create up
501.1Sagc		sudo ifconfig bridge0 create
511.1Sagc		sudo brconfig bridge0 add tap0 add ${interface} up
521.1Sagc		sudo chmod 664 /dev/tap*
531.1Sagc		;;
541.1Sagcesac
551.1Sagc
561.1Sagc# check syscall emulation module is loaded
571.1Sagcmod=$(modstat syscallemu | awk '$1 == "syscallemu" { print; exit }')
581.1Sagccase "${mod}" in
591.1Sagcsyscallemu*)	echo "Host syscall emulation module loaded" ;;
601.1Sagc*)		sudo modload syscallemu ;;
611.1Sagcesac
621.1Sagc
631.1Sagc./netbsd disk=${image} disk=${pkgs} net=tap0,00:00:de:ad:be:ef 
641.1Sagc
651.1Sagcexit 0
66