source: npl/kernel/initrd_scripts/root/etc/if-assign.boot @ 1bce4e1

Last change on this file since 1bce4e1 was c5c522c, checked in by Edwin Eefting <edwin@datux.nl>, 8 years ago

initial commit, transferred from cleaned syn3 svn tree

  • Property mode set to 100755
File size: 1.6 KB
Line 
1#!/bin/bash
2#Syn-3 Interface assign script.
3
4#path to configfile
5#<MAC>\t<INTERFACE>
6CONFIG_FILE=/mnt/if-assign.conf;
7
8
9#shut all interfaces down and move them out of the way
10for NET in /sys/class/net/eth*/address; do
11        INTERFACE="`echo $NET|cut -f5 -d/`";
12        if [ "`cat /sys/class/net/$INTERFACE/type`" == "1" ]; then
13                MAC="`cat $NET`";
14                ifconfig "$INTERFACE" down
15                nameif "tmp_$INTERFACE" "$MAC"
16        fi
17done
18
19#first, if we have a config, rename interfaces that have an explicit mac assignment
20if [ -e $CONFIG_FILE ]; then
21        for NET in /sys/class/net/tmp_eth*/address; do
22                INTERFACE="`echo $NET|cut -f5 -d/`";
23                if [ "`cat /sys/class/net/$INTERFACE/type`" == "1" ]; then
24                        MAC="`cat $NET`";
25                        NEW_INTERFACE="`grep -i "^$MAC" $CONFIG_FILE |head -1|cut -f2`"  2>/dev/null
26                        if [ "$NEW_INTERFACE" ]; then
27                                echo "Assigning known adaptor $MAC to interface $NEW_INTERFACE."
28                                nameif "$NEW_INTERFACE" "$MAC"
29                        fi
30                fi
31        done
32fi
33
34#now rename the unknown adapters in ORDER of macadres.
35#this will guarantee consistency. in some complex setups, interfaces seem to be assigned at random/detection speed.
36#after booting this assignment will be stored permanently and can be changed by the user.
37IF_COUNTER=0
38for MAC in `cat /sys/class/net/tmp_eth*/address 2>/dev/null|sort`; do
39        NET=`grep -l $MAC /sys/class/net/tmp_eth*/address 2>/dev/null`
40        INTERFACE="`echo $NET|cut -f5 -d/`";
41
42        #determine next available eth number
43        while true; do
44                NEW_INTERFACE=eth$IF_COUNTER
45                if ! [ -e /sys/class/net/$NEW_INTERFACE ]; then
46                        echo "Assigning new adaptor $MAC to interface $NEW_INTERFACE"
47                        nameif "$NEW_INTERFACE" "$MAC"
48                        break;
49                fi
50                IF_COUNTER=$(( IF_COUNTER+1 ))
51        done
52done
Note: See TracBrowser for help on using the repository browser.