Add new meshwizard (WIP)
[project/luci.git] / contrib / package / meshwizard / files / usr / bin / meshwizard / helpers / rename-wifi.sh
diff --git a/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh b/contrib/package/meshwizard/files/usr/bin/meshwizard/helpers/rename-wifi.sh
new file mode 100755 (executable)
index 0000000..aee15f5
--- /dev/null
@@ -0,0 +1,43 @@
+#!/bin/sh
+# This script renames IB_wifi_ interface names into real interface names used on this system.
+# E.g. wireless.IB_wifi0 would become wireless.wifi0 on madwifi and wireless.radio0 on mac80211
+
+posIB=-1
+
+IBwifis="$(uci show meshwizard.netconfig | grep -v 'netconfig=netconfig' | sed 's/meshwizard.netconfig\.\(IB_wifi.*\)_.*/\1/' |uniq)"
+
+for w in $IBwifis; do
+       posIB=$(( $posIB + 1 ))
+       export IB_wifi$posIB="$w"
+done
+
+pos=0
+syswifis="$(uci show wireless |grep wifi-device | sed 's/wireless\.\(.*\)=.*/\1/' |uniq)"
+
+for s in $syswifis; do
+       export syswifi$pos="$s"
+       pos=$(( $pos + 1 ))
+done
+
+for i in `seq 0 $posIB`; do
+       IBwifi=$(eval echo \$IB_wifi$i)
+       syswifi=$(eval echo \$syswifi$i)
+
+       if [ -n "$syswifi" ]; then
+               case $IBwifi in
+               IB_wifi* )
+                       # replace IB_wifi_* with actual wifi interface names, delete old ones first
+                       uci show meshwizard.netconfig | grep $IBwifi | while read line; do
+                               oldline=$(echo $line | cut -d "=" -f 1)
+                               uci set $oldline=""
+                               newline=$(echo $line |sed "s/$IBwifi/$syswifi/g")
+                               uci set $newline
+                       done
+               ;;
+               esac
+               unset IBwifi
+               unset syswifi
+       fi
+done
+
+uci commit