[dd21d69] | 1 | #!/bin/bash |
---|
| 2 | ############################################## |
---|
| 3 | # Add VMWare Network Bridged devices hot |
---|
| 4 | # |
---|
| 5 | # Revisions |
---|
| 6 | # J.Gargano - 2009-07-08 - 1.1 |
---|
| 7 | # |
---|
| 8 | ############################################# |
---|
| 9 | |
---|
| 10 | echo "Locating Existing Devices" |
---|
| 11 | for dev in $(ls /dev/vmnet*); |
---|
| 12 | do |
---|
[330685a] | 13 | echo " Found $dev" |
---|
[dd21d69] | 14 | done |
---|
| 15 | echo |
---|
| 16 | printf "Please enter a device number that does not exist in this list: " |
---|
| 17 | read num |
---|
| 18 | # Check if it exists |
---|
[013d010] | 19 | if [ -e /dev/vmnet$num ];then |
---|
[330685a] | 20 | echo "/dev/vmnet$num exists! Exiting." |
---|
| 21 | exit 1 |
---|
[dd21d69] | 22 | fi |
---|
| 23 | |
---|
| 24 | |
---|
| 25 | # Select an interface |
---|
| 26 | echo |
---|
| 27 | echo "Locating interfaces to bridge" |
---|
| 28 | for int in $(ifconfig |grep "^[a-z,A-Z]" |cut -d' ' -f1); |
---|
| 29 | do |
---|
[330685a] | 30 | echo $int |
---|
[dd21d69] | 31 | done |
---|
| 32 | printf "Please enter a interface: " |
---|
| 33 | read interface |
---|
| 34 | |
---|
| 35 | # Check if it exists |
---|
| 36 | ifconfig $interface >/dev/null 2>&1 |
---|
| 37 | ret=$? |
---|
| 38 | if [ $ret != 0 ];then |
---|
[013d010] | 39 | if [ "$1" != "-d" ]; then |
---|
| 40 | echo "Can't find interface. Exiting!" |
---|
| 41 | exit 1 |
---|
| 42 | else |
---|
| 43 | echo "Use dummy device: $interface" |
---|
| 44 | dummy="Dummy " |
---|
| 45 | fi |
---|
[dd21d69] | 46 | fi |
---|
| 47 | |
---|
| 48 | |
---|
| 49 | # Create device |
---|
| 50 | echo "Creating device /dev/vmnet$num" |
---|
[013d010] | 51 | mknod --mode=600 /dev/vmnet$num c 119 $num |
---|
[dd21d69] | 52 | |
---|
| 53 | # Add to vmware netmap configuration |
---|
| 54 | # open netmap.conf and get next number in list |
---|
| 55 | let nextnetnum=$(cat /etc/vmware/netmap.conf | tail -1 | cut -d'.' -f1 | sed -e s/network//)+1 |
---|
| 56 | |
---|
| 57 | echo "Adding network$nextnetnum to /etc/vmware/netmap.conf" |
---|
| 58 | |
---|
[013d010] | 59 | echo "network$nextnetnum.name = \"${dummy}Bridged to $interface\"">> /etc/vmware/netmap.conf |
---|
| 60 | echo "network$nextnetnum.device = \"vmnet$num\"">> /etc/vmware/netmap.conf |
---|
[dd21d69] | 61 | |
---|
[013d010] | 62 | # Add to vmware locations configuration |
---|
| 63 | echo "answer VNET_${num}_NAME ${dummy}Bridged to $interface" >> /etc/vmware/locations |
---|
| 64 | echo "answer VNET_${num}_INTERFACE $interface" >> /etc/vmware/locations |
---|
| 65 | echo "remove_file /dev/vmnet$num" >> /etc/vmware/locations |
---|
| 66 | echo "file /dev/vmnet$num" >> /etc/vmware/locations |
---|
[dd21d69] | 67 | |
---|
| 68 | # Start Service |
---|
[013d010] | 69 | `which vmnet-bridge` -d /var/run/vmnet-bridge-$num.pid -n $num -i $interface |
---|