Add new meshwizard (WIP)
[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.wifi0 on madwifi and wireless.radio0 on mac80211
4
5 posIB=-1
6
7 IBwifis="$(uci show meshwizard.netconfig | grep -v 'netconfig=netconfig' | sed 's/meshwizard.netconfig\.\(IB_wifi.*\)_.*/\1/' |uniq)"
8
9 for w in $IBwifis; do
10         posIB=$(( $posIB + 1 ))
11         export IB_wifi$posIB="$w"
12 done
13
14 pos=0
15 syswifis="$(uci show wireless |grep wifi-device | sed 's/wireless\.\(.*\)=.*/\1/' |uniq)"
16
17 for s in $syswifis; do
18         export syswifi$pos="$s"
19         pos=$(( $pos + 1 ))
20 done
21
22 for i in `seq 0 $posIB`; do
23         IBwifi=$(eval echo \$IB_wifi$i)
24         syswifi=$(eval echo \$syswifi$i)
25
26         if [ -n "$syswifi" ]; then
27                 case $IBwifi in
28                 IB_wifi* )
29                         # replace IB_wifi_* with actual wifi interface names, delete old ones first
30                         uci show meshwizard.netconfig | grep $IBwifi | while read line; do
31                                 oldline=$(echo $line | cut -d "=" -f 1)
32                                 uci set $oldline=""
33                                 newline=$(echo $line |sed "s/$IBwifi/$syswifi/g")
34                                 uci set $newline
35                         done
36                 ;;
37                 esac
38                 unset IBwifi
39                 unset syswifi
40         fi
41 done
42
43 uci commit