meshwizard: cleanup references to madwifi
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / rename-wifi.sh
1 #!/bin/sh
2 # This script renames IB_wifi_ interface names into real interface names used on this system.
3 # E.g. wireless.IB_wifi0 would become wireless.radio0 on mac80211
4
5 . $dir/functions.sh
6
7 posIB=-1
8
9 IBwifis="$(uci show meshwizard.netconfig | grep 'IB_' | sed 's/meshwizard.netconfig\.\(IB_wifi.*\)_.*/\1/' |uniq)"
10 [ -z "$(echo $IBwifis |grep IB_wifi)" ] && exit
11
12 for w in $IBwifis; do
13         posIB=$(( $posIB + 1 ))
14         export IB_wifi$posIB="$w"
15 done
16
17 pos=0
18 syswifis="$(uci show wireless |grep wifi-device | sed 's/wireless\.\(.*\)=.*/\1/' |uniq)"
19
20 for s in $syswifis; do
21         export syswifi$pos="$s"
22         pos=$(( $pos + 1 ))
23 done
24
25 for i in `seq 0 $posIB`; do
26         IBwifi=$(eval echo \$IB_wifi$i)
27         syswifi=$(eval echo \$syswifi$i)
28
29         if [ -n "$syswifi" ]; then
30                 case $IBwifi in
31                 IB_wifi* )
32                         # replace IB_wifi_* with actual wifi interface names, delete old ones first
33                         uci show meshwizard.netconfig | grep $IBwifi | while read line; do
34                                 oldline=$(echo $line | cut -d "=" -f 1)
35                                 uci set $oldline=""
36                                 newline=$(echo $line |sed -e "s/$IBwifi/$syswifi/g" -e "s/'//g")
37                                 uci set $newline
38                         done
39                 ;;
40                 esac
41                 unset IBwifi
42                 unset syswifi
43         fi
44 done
45
46 uci_commitverbose "Renaming wifi-devices in /etc/config/meshwizard" meshwizard