summaryrefslogtreecommitdiff
path: root/recipes-core/udev/eudev/mtcdt/mtcdt_eth_rename.sh
blob: 4273d309d1d5a6862d0c36bd412de72055208b60 (plain)
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
#!/bin/bash

I2C_DIR="/sys/bus/i2c/devices"

AP1_EEPROM="$I2C_DIR/1-0050/eeprom"
AP2_EEPROM="$I2C_DIR/1-0052/eeprom"
hw_version1=''
hw_version2=''

if [[ -f $AP1_EEPROM ]] ; then
    hw_version1=$(mts-id-eeprom --accessory-card --in-file "$AP1_EEPROM" 2>/dev/null | grep '^hw-version:')
fi
if [[ -f $AP2_EEPROM ]] ; then
    hw_version2=$(mts-id-eeprom --accessory-card --in-file "$AP2_EEPROM" 2>/dev/null | grep '^hw-version:')
fi

AP1=0
AP2=0

if [[ $hw_version1 =~ ^hw-version:[[:space:]]*\"MTAC-ETH ]] ; then
    AP1=1
fi

if [[ $hw_version2 =~ ^hw-version:[[:space:]]*\"MTAC-ETH ]] ; then
    AP2=1
fi

if ((AP1 == 0)) && ((AP2 == 1)) ; then
    if ip addr show eth1 >/dev/null 2>&1  && ! ip addr show eth2 >/dev/null 2>&1 ; then
        ip link set eth1 name eth2
    fi
fi

# Handle the case where we are coming out of reset.
# udev will assign eth# where # is the first open slot starting from zero.
# We assing by AP slot here.
if ((AP1 == 1)) && ((AP2 == 1)) ; then
    if (($(mts-io-sysfs show ap2/reset) == 0)) ; then
        :
        # Nothing to do if ap2 is in reset.
    elif (($(mts-io-sysfs show ap1/reset) == 0)) ; then
        if ip addr show eth1 >/dev/null 2>&1  && ! ip addr show eth2 >/dev/null 2>&1 ; then
            ip link set eth1 name eth2
        fi
    fi
fi