vnicinit_solaris.sh revision 052395512a7cc6c1799aa823e996eb63c02891f4
42576743851c3c956ad7e867e74df1084c30d434vboxsync#!/bin/bash
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsync# VirtualBox VNIC setup script for Solaris hosts with Crossbow.
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsyncif [ -z "$1" ]; then
42576743851c3c956ad7e867e74df1084c30d434vboxsync echo "Missing MAC address."
42576743851c3c956ad7e867e74df1084c30d434vboxsync echo
42576743851c3c956ad7e867e74df1084c30d434vboxsync echo "Usage: $0 macaddress [vnicname]"
42576743851c3c956ad7e867e74df1084c30d434vboxsync echo " A new VNIC is created if no vnicname is provided."
42576743851c3c956ad7e867e74df1084c30d434vboxsync exit 1
42576743851c3c956ad7e867e74df1084c30d434vboxsyncfi
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsyncvnic_id=0
42576743851c3c956ad7e867e74df1084c30d434vboxsyncvnic_name=""
42576743851c3c956ad7e867e74df1084c30d434vboxsyncmac=$1
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsync# Create the VNIC if required
42576743851c3c956ad7e867e74df1084c30d434vboxsyncif [ -z "$2" ]; then
42576743851c3c956ad7e867e74df1084c30d434vboxsync vnic_id=`/usr/lib/vna iprb0 $mac`
42576743851c3c956ad7e867e74df1084c30d434vboxsync if [ $? != 0 ]; then
42576743851c3c956ad7e867e74df1084c30d434vboxsync exit 1
42576743851c3c956ad7e867e74df1084c30d434vboxsync fi
42576743851c3c956ad7e867e74df1084c30d434vboxsync vnic_name=vnic${vnic_id}
42576743851c3c956ad7e867e74df1084c30d434vboxsyncelse
42576743851c3c956ad7e867e74df1084c30d434vboxsync vnic_name=$2
42576743851c3c956ad7e867e74df1084c30d434vboxsync vnic_id=${vnic_name##*[a-z]}
42576743851c3c956ad7e867e74df1084c30d434vboxsyncfi
42576743851c3c956ad7e867e74df1084c30d434vboxsync
42576743851c3c956ad7e867e74df1084c30d434vboxsyncif [ ${vnic_id} -lt 10 ]; then
42576743851c3c956ad7e867e74df1084c30d434vboxsync host_ip="192.168.1.10${vnic_id}"
42576743851c3c956ad7e867e74df1084c30d434vboxsync guest_ip="192.168.1.20${vnic_id}"
42576743851c3c956ad7e867e74df1084c30d434vboxsyncelif [ ${vnic_id} -lt 256 ]; then
42576743851c3c956ad7e867e74df1084c30d434vboxsync host_ip="192.168.1.${vnic_id}"
42576743851c3c956ad7e867e74df1084c30d434vboxsync guest_ip="192.168.2.${vnic_id}"
6998b7cea7c904f33047cd17b05bea760a5839a9vboxsyncelif [ ${vnic_id} -gt 899 ]; then
02f73b88a6e96b7f1b8ab0bbb98cfb798b566fbdvboxsync let "temp_id = $vnic_id % 900"
42576743851c3c956ad7e867e74df1084c30d434vboxsync host_ip="192.168.1.10${temp_id}"
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync guest_ip="192.168.1.20${temp_id}"
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsyncelse
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsync # VNIC ID is probably off the scale!
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync host_ip="192.168.1.10"
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync guest_ip="192.168.1.20"
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsyncfi
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync
cdcfac625bb49f1d4b67aaf8fb8b1cdb69fe49c2vboxsyncnetmask="255.255.255.0"
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsync
82e3a4017d20f44c30ff909e6b825ff78139cbbbvboxsyncif [ -z "$2" ]; then
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsync /sbin/ifconfig $vnic_name plumb
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsync /sbin/ifconfig $vnic_name $host_ip destination $guest_ip netmask $netmask up
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsync#else
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsync# Do existing VNIC configuration here if needed...
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsyncfi
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsync
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsyncecho "$vnic_name"
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsyncexit $?
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsync
c6b3d55ef646614cc689faa1fa4ddc961712b6ffvboxsync