NetBSD/distrib/utils/embedded/usermode

66 lines
2.1 KiB
Bash
Executable File

#! /bin/sh
# $NetBSD: usermode,v 1.1 2012/01/15 02:01:02 agc Exp $
# Copyright (c) 2012 Alistair Crooks <agc@NetBSD.org>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
image=usermode.img
pkgs=pkgs.img
while [ $# -gt 0 ]; do
case "$1" in
-v) set -x ;;
*) break ;;
esac
shift
done
if [ $# -gt 0 ]; then
image=$1
fi
# check bridging is set up
bridging=$(ifconfig tap0 | awk '$1 == "inet" { print $2 }')
case "${bridging}" in
*.*.*.*) echo "bridging is already up on ${bridging}" ;;
*) interface=$(ifconfig -l | awk '{print $1}')
sudo ifconfig tap0 create up
sudo ifconfig bridge0 create
sudo brconfig bridge0 add tap0 add ${interface} up
sudo chmod 664 /dev/tap*
;;
esac
# check syscall emulation module is loaded
mod=$(modstat syscallemu | awk '$1 == "syscallemu" { print; exit }')
case "${mod}" in
syscallemu*) echo "Host syscall emulation module loaded" ;;
*) sudo modload syscallemu ;;
esac
./netbsd disk=${image} disk=${pkgs} net=tap0,00:00:de:ad:be:ef
exit 0