d9aa51989a7af4d41dcb32fcec3a635146d89836
[openwrt.git] / target / linux / ar71xx / base-files / etc / uci-defaults / 03_network-switchX-migration
1 #!/bin/sh
2 #
3 # Copyright (C) 2013 OpenWrt.org
4 #
5
6 SWITCH_NAME_CHANGED=
7
8 do_change_switch_name() {
9         local config="$1"
10         local option=$2
11         local oldname=$3
12         local newname=$4
13         local val
14
15         config_get val "$config" $option
16         [ "$val" != "$oldname" ] && return 0
17
18         uci_set network "$config" $option $newname
19         SWITCH_NAME_CHANGED=1
20
21         return 0
22 }
23
24 migrate_switch_name() {
25         local oldname=$1
26         local newname=$2
27
28         . /lib/functions.sh
29
30         config_load network
31
32         logger -t migrate-switchX "Updating switch names in network configuration"
33
34         config_foreach do_change_switch_name switch name $oldname $newname
35         config_foreach do_change_switch_name switch_vlan device $oldname $newname
36
37         [ "$SWITCH_NAME_CHANGED" = "1" ] && {
38                 logger -t migrate-switchX "Switch names updated, saving network configuration"
39                 uci commit network
40         }
41 }
42
43 . /lib/ar71xx.sh
44
45 board=$(ar71xx_board_name)
46
47 case "$board" in
48 dir-825-c1|\
49 wzr-hp-g300nh2|\
50 pb92|\
51 ap113|\
52 tl-wdr4300|\
53 tl-wr1041n-v2|\
54 wrt160nl|\
55 ap121|\
56 ap121-mini|\
57 ap96|\
58 airrouter|\
59 dir-600-a1|\
60 dir-615-c1|\
61 dir-615-e1|\
62 dir-615-e4|\
63 ja76pf|\
64 rb-750|\
65 rb-751|\
66 tew-632brp|\
67 tew-712br|\
68 tl-mr3220|\
69 tl-mr3220-v2 |\
70 tl-mr3420|\
71 tl-wr741nd|\
72 tl-wr741nd-v4|\
73 tl-wr841n-v7|\
74 whr-g301n|\
75 whr-hp-g300n|\
76 whr-hp-gn|\
77 wzr-hp-ag300h|\
78 wzr-hp-g450h|\
79 ew-dorin|\
80 ew-dorin-router)
81         migrate_switch_name "eth0" "switch0"
82         ;;
83
84 el-m150|\
85 rb-450)
86         migrate_switch_name "eth1" "switch0"
87         ;;
88
89 db120 |\
90 rb-2011l | \
91 rb-2011uas-2hnd)
92         migrate_switch_name "eth0" "switch0"
93         migrate_switch_name "eth1" "switch1"
94         ;;
95
96 dir-825-b1|\
97 tew-673gru|\
98 nbg460n_550n_550nh)
99         migrate_switch_name "rtl8366s" "switch0"
100         ;;
101
102 tl-wr1043nd)
103         migrate_switch_name "rtl8366rb" "switch0"
104         ;;
105
106 esac
107
108 exit 0