From af850eb63c732cd271a9f7a13891c48a2fc54e50 Mon Sep 17 00:00:00 2001 From: Alex Oprea Date: Wed, 15 Feb 2017 12:43:56 +0100 Subject: [PATCH] iup: save user changes: wifi interface When applying a new config received through iup/provisionining, Save the changes that the user has made to the wifi interfaces. (For example SSID or password change.) --- iup/files/sbin/iup | 65 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/iup/files/sbin/iup b/iup/files/sbin/iup index 010b90399..0b8500f7c 100755 --- a/iup/files/sbin/iup +++ b/iup/files/sbin/iup @@ -14,6 +14,7 @@ export IUPMD5=/etc/configchecksums export CONFILESLURP='/tmp/iup/*.conf' export IUPTEMP="/tmp/iup" export IUPUSERCFG="/tmp/iupusercfg" +export IUPUSERCFG_WIFI="/tmp/iupusercfg_wifi" export INTERACTIVE=0 export VERBOSE=0 export CONF=1 @@ -60,8 +61,8 @@ reload () save_usercfg() { - rm -f $IUPUSERCFG - touch $IUPUSERCFG + rm -f $IUPUSERCFG $IUPUSERCFG_WIFI + touch $IUPUSERCFG $IUPUSERCFG_WIFI # save the firewall redirects/port forwarding uci show firewall | grep redirect >> $IUPUSERCFG @@ -91,14 +92,68 @@ save_usercfg() sed -i 's/\[.\?.\?.\?.\?\]/[-1]/' $IUPUSERCFG # commit at the end of the script - echo "commit" >> $IUPUSERCFG + [ -s $IUPUSERCFG ] && echo "commit" >> $IUPUSERCFG + + # save wireless interfaces + uci show wireless | grep "wifi-iface" > $IUPUSERCFG_WIFI } apply_usercfg() { - # run the uci batch script + local index ifname network + local newindex newifname newnetwork + + # loop through all the user wifi-ifaces + for index in $(seq 0 99) ; do + ifname=$(sed -n 's/.*wifi-iface\['$index'\]\.ifname='\''\(.*\)'\''/\1/p' $IUPUSERCFG_WIFI ) + [ "$ifname" ] || break + network=$(sed -n 's/.*wifi-iface\['$index'\]\.network='\''\(.*\)'\''/\1/p' $IUPUSERCFG_WIFI ) + + newindex="" + newifname="" + newnetwork="" + + # loop through all the newly configured wifi-ifaces + for newindex in $(seq 0 99) ; do + newifname=$( uci show wireless | grep wifi-iface | sed -n 's/.*wifi-iface\['$newindex'\]\.ifname='\''\(.*\)'\''/\1/p' ) + if [ -z "$newifname" ] ; then + # no newifname means that all the wifi-ifaces have already been parsed + newindex="-1" + break + fi + newnetwork=$(uci show wireless | grep wifi-iface | sed -n 's/.*wifi-iface\['$newindex'\]\.network='\''\(.*\)'\''/\1/p' ) + + # two wifi interfaces are the same if "ifname" and "network" are the same + if [ "$newifname" == "$ifname" ] && [ "$newnetwork" == "$network" ] ; then + break + fi + done + + # prepend "set" to each line NOT containing "]=" + # wireless.@wifi-iface[$index].