xref: /netbsd-src/distrib/utils/embedded/usermode (revision 00c311bc00e73005c3a50a553af66391b3e647bb)
1*00c311bcSagc#! /bin/sh
2*00c311bcSagc
3*00c311bcSagc# $NetBSD: usermode,v 1.1 2012/01/15 02:01:02 agc Exp $
4*00c311bcSagc
5*00c311bcSagc# Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
6*00c311bcSagc# All rights reserved.
7*00c311bcSagc#
8*00c311bcSagc# Redistribution and use in source and binary forms, with or without
9*00c311bcSagc# modification, are permitted provided that the following conditions
10*00c311bcSagc# are met:
11*00c311bcSagc# 1. Redistributions of source code must retain the above copyright
12*00c311bcSagc#    notice, this list of conditions and the following disclaimer.
13*00c311bcSagc# 2. Redistributions in binary form must reproduce the above copyright
14*00c311bcSagc#    notice, this list of conditions and the following disclaimer in the
15*00c311bcSagc#    documentation and/or other materials provided with the distribution.
16*00c311bcSagc#
17*00c311bcSagc# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18*00c311bcSagc# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19*00c311bcSagc# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20*00c311bcSagc# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21*00c311bcSagc# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22*00c311bcSagc# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23*00c311bcSagc# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24*00c311bcSagc# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25*00c311bcSagc# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26*00c311bcSagc# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27*00c311bcSagc#
28*00c311bcSagc
29*00c311bcSagcimage=usermode.img
30*00c311bcSagcpkgs=pkgs.img
31*00c311bcSagc
32*00c311bcSagcwhile [ $# -gt 0 ]; do
33*00c311bcSagc	case "$1" in
34*00c311bcSagc	-v)	set -x ;;
35*00c311bcSagc	*)	break ;;
36*00c311bcSagc	esac
37*00c311bcSagc	shift
38*00c311bcSagcdone
39*00c311bcSagc
40*00c311bcSagcif [ $# -gt 0 ]; then
41*00c311bcSagc	image=$1
42*00c311bcSagcfi
43*00c311bcSagc
44*00c311bcSagc# check bridging is set up
45*00c311bcSagcbridging=$(ifconfig tap0 | awk '$1 == "inet" { print $2 }')
46*00c311bcSagccase "${bridging}" in
47*00c311bcSagc*.*.*.*)	echo "bridging is already up on ${bridging}" ;;
48*00c311bcSagc*)		interface=$(ifconfig -l | awk '{print $1}')
49*00c311bcSagc		sudo ifconfig tap0 create up
50*00c311bcSagc		sudo ifconfig bridge0 create
51*00c311bcSagc		sudo brconfig bridge0 add tap0 add ${interface} up
52*00c311bcSagc		sudo chmod 664 /dev/tap*
53*00c311bcSagc		;;
54*00c311bcSagcesac
55*00c311bcSagc
56*00c311bcSagc# check syscall emulation module is loaded
57*00c311bcSagcmod=$(modstat syscallemu | awk '$1 == "syscallemu" { print; exit }')
58*00c311bcSagccase "${mod}" in
59*00c311bcSagcsyscallemu*)	echo "Host syscall emulation module loaded" ;;
60*00c311bcSagc*)		sudo modload syscallemu ;;
61*00c311bcSagcesac
62*00c311bcSagc
63*00c311bcSagc./netbsd disk=${image} disk=${pkgs} net=tap0,00:00:de:ad:be:ef
64*00c311bcSagc
65*00c311bcSagcexit 0
66