f64458526f0906f34b15707dc065a8c98960200c
[openwrt/openwrt.git] / target / linux / mediatek / mt7623 / base-files / lib / preinit / 07_set_iface_mac
1 # Copyright (C) 2018 OpenWrt.org
2
3 RECOVERY_PART=/dev/mmcblk0p1
4
5 preinit_set_mac_address() {
6 local mac
7
8 . /lib/functions.sh
9 . /lib/functions/system.sh
10
11 case $(board_name) in
12 unielec,u7623-02-emmc-512m)
13 if [ -b $RECOVERY_PART ]; then
14 insmod nls_cp437
15 insmod nls_iso8859-1
16 insmod fat
17 insmod vfat
18 mkdir -p /tmp/recovery
19 mount -o rw,noatime $RECOVERY_PART /tmp/recovery
20
21 if [ -f "/tmp/recovery/mac_addr" ];
22 then
23 mac=$(cat /tmp/recovery/mac_addr)
24 else
25 mac=$(cat /sys/class/net/eth0/address)
26 echo "$mac" > /tmp/recovery/mac_addr
27 fi
28
29 sync
30 umount /tmp/recovery
31 rm -rf /tmp/recovery
32 fi
33
34 ip link set dev wan address $mac 2> /dev/null
35
36 mac=$(macaddr_add $mac 1)
37
38 ip link set dev lan0 address $mac 2>/dev/null
39 ip link set dev lan1 address $mac 2>/dev/null
40 ip link set dev lan2 address $mac 2>/dev/null
41 ip link set dev lan3 address $mac 2>/dev/null
42 ;;
43 esac
44 }
45
46 boot_hook_add preinit_main preinit_set_mac_address