-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkdbmacgen.sh
More file actions
executable file
·50 lines (41 loc) · 1.4 KB
/
kdbmacgen.sh
File metadata and controls
executable file
·50 lines (41 loc) · 1.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/bin/bash
# Generates kdb mac file: writes to $KDB_MAC_FILE lines like "sys_iface_eth0_mac=00:33:...".
# MAC-addresses are generated continuosly.
# Written by Kazantsev A.V., Sigrand, Novosibirsk, [email protected]
IFACE_TYPE1_NAME="eth"
IFACE_TYPE1_NUM="6"
IFACE_TYPE2_NAME="dsl"
IFACE_TYPE2_NUM="32"
IFACE_TYPE3_NAME="E1_"
IFACE_TYPE3_NUM="32"
MACCOUNTER=$1
KDB_MAC_FILE=$2
showerr()
{
echo $1
exit 1
}
[ -z $2 ] && echo "Usage: $0 maccounter_file kdb_mac_file" && exit 1
# check files permissions
[ -r $MACCOUNTER -a -w $MACCOUNTER ] || showerr "Unable to read or write mac counter file $MACCOUNTER"
[ -w `dirname $KDB_MAC_FILE` ] || showerr "Unable to write kdb mac file $KDB_MAC_FILE"
rm -f $KDB_MAC_FILE
# read current MAC counter
curmac=$(cat $MACCOUNTER)
# generate KDB records
for i in 1 2 3; do
unset iface_name iface_num
eval 'iface_name=$'IFACE_TYPE${i}_NAME
eval 'iface_num=$'IFACE_TYPE${i}_NUM
iface_idx=0
while [ $iface_idx -lt $iface_num ]; do
curmachex=$(printf "%.12x" $curmac)
# /bin/bash required due to line below:
mac_formatted=${curmachex:0:2}:${curmachex:2:2}:${curmachex:4:2}:${curmachex:6:2}:${curmachex:8:2}:${curmachex:10:2}
echo sys_iface_${iface_name}${iface_idx}_mac=$mac_formatted >>$KDB_MAC_FILE
curmac=$(($curmac + 1))
iface_idx=$(($iface_idx + 1))
done
done
# update mac counter
echo $curmac > $MACCOUNTER