1 | #!/bin/bash
|
---|
2 | # innotek VirtualBox
|
---|
3 | # Copyright (C) 2007 innotek GmbH
|
---|
4 | #
|
---|
5 | # VirtualBox VNIC setup script for Solaris hosts with Crossbow.
|
---|
6 | #
|
---|
7 |
|
---|
8 | if [ -z "$1" ]; then
|
---|
9 | echo "Missing MAC address."
|
---|
10 | echo
|
---|
11 | echo "Usage: $0 macaddress [vnicname]"
|
---|
12 | echo " A new VNIC is created if no vnicname is provided."
|
---|
13 | exit 1
|
---|
14 | fi
|
---|
15 |
|
---|
16 | # Try obtain a physical NIC that is currently active
|
---|
17 | phys_nic=`/usr/sbin/dladm show-dev | /usr/bin/awk 'NF==7 && $3=="up" { print $1 }'`
|
---|
18 | if [ -z "$phys_nic" ]; then
|
---|
19 | # Failed to get a currently active NIC, get the first available NIC.
|
---|
20 | phys_nic=`/usr/sbin/dladm show-link | /usr/bin/nawk '/legacy/ {next} {print $1; exit}'`
|
---|
21 | if [ -z "$phys_nic" ]; then
|
---|
22 | # Failed to get any NICs!
|
---|
23 | echo "Failed to get a physical NIC to bind to."
|
---|
24 | exit 1
|
---|
25 | fi
|
---|
26 | fi
|
---|
27 | vnic_id=0
|
---|
28 | vnic_name=""
|
---|
29 | mac=$1
|
---|
30 |
|
---|
31 | # Create the VNIC if required
|
---|
32 | if [ -z "$2" ]; then
|
---|
33 | # To use a specific physical NIC, replace $phys_nic with the name of the NIC.
|
---|
34 | vnic_id=`/usr/lib/vna $phys_nic $mac`
|
---|
35 | if [ $? != 0 ]; then
|
---|
36 | exit 1
|
---|
37 | fi
|
---|
38 | vnic_name=vnic${vnic_id}
|
---|
39 | else
|
---|
40 | vnic_name=$2
|
---|
41 | vnic_id=${vnic_name##*[a-z]}
|
---|
42 | fi
|
---|
43 |
|
---|
44 | if [ ${vnic_id} -lt 10 ]; then
|
---|
45 | host_ip="192.168.1.10${vnic_id}"
|
---|
46 | guest_ip="192.168.1.20${vnic_id}"
|
---|
47 | elif [ ${vnic_id} -lt 256 ]; then
|
---|
48 | host_ip="192.168.1.${vnic_id}"
|
---|
49 | guest_ip="192.168.2.${vnic_id}"
|
---|
50 | elif [ ${vnic_id} -gt 899 ]; then
|
---|
51 | let "temp_id = $vnic_id % 900"
|
---|
52 | host_ip="192.168.1.10${temp_id}"
|
---|
53 | guest_ip="192.168.1.20${temp_id}"
|
---|
54 | else
|
---|
55 | # VNIC ID is probably off the scale!
|
---|
56 | host_ip="192.168.1.10"
|
---|
57 | guest_ip="192.168.1.20"
|
---|
58 | fi
|
---|
59 |
|
---|
60 | netmask="255.255.255.0"
|
---|
61 |
|
---|
62 | if [ -z "$2" ]; then
|
---|
63 | /sbin/ifconfig $vnic_name plumb
|
---|
64 | /sbin/ifconfig $vnic_name $host_ip destination $guest_ip netmask $netmask up
|
---|
65 | #else
|
---|
66 | # Do existing VNIC configuration here if needed...
|
---|
67 | fi
|
---|
68 |
|
---|
69 | echo "$vnic_name"
|
---|
70 | exit $?
|
---|
71 |
|
---|