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