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 |
---|
13 | echo " Found $dev" |
---|
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 |
---|
19 | if [ -f /dev/vmnet$num ];then |
---|
20 | echo "/dev/vmnet$num exists! Exiting." |
---|
21 | exit 1 |
---|
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 |
---|
30 | echo $int |
---|
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 |
---|
39 | echo "Can't find interface. Exiting!" |
---|
40 | exit 1 |
---|
41 | fi |
---|
42 | |
---|
43 | |
---|
44 | # Create device |
---|
45 | echo "Creating device /dev/vmnet$num" |
---|
46 | mknod /dev/vmnet$num c 119 $num |
---|
47 | |
---|
48 | # Add to vmware netmap configuration |
---|
49 | # open netmap.conf and get next number in list |
---|
50 | let nextnetnum=$(cat /etc/vmware/netmap.conf | tail -1 | cut -d'.' -f1 | sed -e s/network//)+1 |
---|
51 | |
---|
52 | echo "Adding network$nextnetnum to /etc/vmware/netmap.conf" |
---|
53 | |
---|
54 | echo "network$nextnetnum.name=\"$interface\"">> /etc/vmware/netmap.conf |
---|
55 | echo "network$nextnetnum.device=\"vmnet$num\"">> /etc/vmware/netmap.conf |
---|
56 | |
---|
57 | |
---|
58 | # Start Service |
---|
59 | vmnet-bridge -d /var/run/vmnet-bridge-$num.pid -n $num -i $interface |
---|