summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (show whitespace changes)
-rwxr-xr-xbin/NS2SetMac.sh16
1 files changed, 14 insertions, 2 deletions
diff --git a/bin/NS2SetMac.sh b/bin/NS2SetMac.sh
index 51810ae..e6111c7 100755
--- a/bin/NS2SetMac.sh
+++ b/bin/NS2SetMac.sh
@@ -1,4 +1,8 @@
1# store/set MAC address for given interface 1# this script is part of networksettings2 package
2# purpose : set fixed MAC address for network devices that
3# have random addresses (like usb)
4#
5
2NS2MacStore=/etc/NS2 6NS2MacStore=/etc/NS2
3 7
4[ ! -d ${NS2MacStore} ] && mkdir ${NS2MacStore} 8[ ! -d ${NS2MacStore} ] && mkdir ${NS2MacStore}
@@ -11,12 +15,20 @@ fi
11if [ -f ${NS2MacStore}/$1.mac ] 15if [ -f ${NS2MacStore}/$1.mac ]
12then 16then
13 # set this mac 17 # set this mac
14 /sbin/ifconfig $1 hw ether `cat ${NS2MacStore}/$1.mac` 18 X=`cat ${NS2MacStore}/$1.mac`
19 if [ ! -z "$X" ]
20 then
21 /sbin/ifconfig $1 hw ether $X
22 fi
15else 23else
16 # remember current mac for all times 24 # remember current mac for all times
17 X=`/sbin/ifconfig $1 | grep HWaddr` 25 X=`/sbin/ifconfig $1 | grep HWaddr`
18 X=${X#*HWaddr } # strip till HWaddr 26 X=${X#*HWaddr } # strip till HWaddr
19 X=${X%% *} # remove trailing spaces 27 X=${X%% *} # remove trailing spaces
28 if [ ! -z "$X" ]
29 then
30 # valid mac address
20 echo ${X} > ${NS2MacStore}/$1.mac 31 echo ${X} > ${NS2MacStore}/$1.mac
21fi 32fi
33fi
22exit 0 34exit 0