treewide: drop shebang from non-executable target files
[openwrt/openwrt.git] / target / linux / gemini / base-files / lib / preinit / 05_set_ether_mac_gemini
1 . /lib/functions.sh
2 . /lib/functions/system.sh
3
4 set_ether_mac() {
5 local part
6 local DEVID
7 local MAC1
8 local MAC2
9
10 case "$(board_name)" in
11 dlink,dns-313)
12 # The DNS-313 has a special field in its RedBoot
13 # binary that we need to check
14 part="$(find_mtd_part RedBoot)"
15 if [ -n "$part" ]; then
16 DEVID="$(dd if=$part bs=1 skip=119508 count=7 2>/dev/null)"
17 if [ "$DEVID" = "dns-313" ]; then
18 MAC1="$(mtd_get_mac_binary RedBoot 0x1d2f4)"
19 ip link set eth0 address "$MAC1" 2>/dev/null
20 return 0
21 fi
22 fi
23 ;;
24 dlink,dir-685)
25 # The DIR-685 has a special field in its RedBoot
26 # binary that we need to check
27 part=$(find_mtd_part RedBoot)
28 if [ -n "$part" ] ; then
29 DEVID="$(dd if=$part bs=1 skip=81516 count=7 2>/dev/null)"
30 if [ "$DEVID" = "ILI9322" ] ; then
31 MAC1=$(mtd_get_mac_binary RedBoot 0x17340)
32 MAC2=$(mtd_get_mac_binary RedBoot 0x17346)
33 ip link set eth0 address "$MAC1" 2>/dev/null
34 ip link set eth1 address "$MAC2" 2>/dev/null
35 return 0
36 fi
37 fi
38 ;;
39 esac
40
41 # Most devices have a standard "VCTL" partition
42 part="$(find_mtd_part VCTL)"
43 if [ -n "$part" ]; then
44 MAC1="$(strings $part |grep MAC|cut -d: -f2|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
45 MAC2="$(strings $part |grep MAC|cut -d: -f8|cut -c3-14|sed -e 's,\(..\),:\1,g' -e 's,^:,,')"
46
47 ip link set eth0 address "$MAC1" 2>/dev/null
48 ip link set eth1 address "$MAC2" 2>/dev/null
49 return 0
50 fi
51 }
52
53 boot_hook_add preinit_main set_ether_mac