Message ID | 20180611175827.7548-1-fabian@blaese.de |
---|---|
State | Superseded |
Headers | show |
diff --git a/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile new file mode 100644 index 0000000..306535e --- /dev/null +++ b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile @@ -0,0 +1,86 @@ +. /usr/share/libubox/jshn.sh +. /lib/functions/fff/wireless + +getWirelessHoodfile() { + if [ $# != 1 ]; then + echo "Usage: getWirelessHoodfile <target-file>" + return 1 + fi + file=$1 + + echo "Trying to get hoodfile from wireless neighbor..." + echo "All wireless interfaces will be disabled temporarily!" + + # only change temporarily + + if ! wifiDelIface; then + echo "Can't delete current wifi setup" + exit 1 + fi + #now we look for phy and add this + for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do + radio="$(wifiAddPhyCond "$phy" "2" "auto")" + radio5="$(wifiAddPhyCond "$phy" "5" "auto5")" + if [ -n "$radio5" ] ; then + radio="$radio5" + staiface="w5sta" + else + staiface="w2sta" + fi + + #and here we add the station + if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then + echo "Can't add Sta interface on $radio." + exit 1 + else + uci -q set network.configSta=interface + uci -q set network.configSta.proto='static' + uci -q commit network + reload_config + fi + done + + wifi + # wait a moment to start the interface + sleep 10; + + if wget -T15 -t5 -O "$file" "http://[fe80::1%w2sta]:2342/keyxchangev2data"; then + return 0 + elif wget -T15 -t5 -O "$file" "http://[fe80::1%w5sta]:2342/keyxchangev2data"; then + return 0 + else + return 1 + fi +} + +getGatewayHoodfile() { + if [ $# != 1 ]; then + echo "Usage: getGatewayHoodfile <target-file>" + return 1 + fi + t file=$1 + + echo "Trying to get hoodfile from gateway..." + + if wget -T15 -t5 -O "$file" "http://[fe80::1%br-mesh]:2342/keyxchangev2data"; then + return 0 + else + return 1 + fi +} + +getKeyserverHoodfile() { + if [ $# != 1 ]; then + echo "Usage: getKeyserverHoodfile <target-file>" + return 1 + fi + file=$1 + + echo "Getting hoodfile from Keyserver" + + if wget -T15 -t5 -O "$file" "http://keyserver.freifunk-franken.de/v2/?lat=$lat&long=$long"; then + return 0 + else + return 1 + fi +} diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood index e2c1fab..aee20e5 100755 --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood @@ -5,6 +5,7 @@ . /lib/functions/fff/network . /lib/functions/fff/wireless . /lib/functions/fff/timeserver +. /usr/lib/functions/fff/hoodfile sectorlocal=/etc/sectorfile sectortmp=/tmp/sectorfile @@ -78,7 +79,8 @@ if [ -s "$hoodlocal" ]; then else # if we have Internet, we download the Hoodfile from the keyxchangev2 if hasInternet ; then - wget -T15 -t5 "http://keyserver.freifunk-franken.de/v2/?lat=$lat&long=$long" -O "$hoodfile" + getKeyserverHoodfile "$hoodfile" + rm -f "$sectortmp" [ -s "$sectorlocal" ] || rm -f "$sectorcopy" # If internet present, no custom config should be distributed, except when local file is present #UPLINK: No uplink download if internet present @@ -99,45 +101,15 @@ else sleep 30 # Wait for the config AP, which may be created at the same time as this script has started - if ! wifiDelIface; then - echo "Can't delete current wifi setup" - exit 1 - fi - #now we look for phy and add this - for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do - radio="$(wifiAddPhyCond "$phy" "2" "auto")" - radio5="$(wifiAddPhyCond "$phy" "5" "auto5")" - if [ -n "$radio5" ] ; then - radio="$radio5" - staiface="w5sta" - else - staiface="w2sta" - fi + getWirelessHoodfile "$hoodfile" - #and here we add the station - if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then - echo "Can't add Sta interface on $radio." - exit 1 - else - uci -q set network.configSta=interface - uci -q set network.configSta.proto='static' - uci -q commit network - reload_config - fi - done - - wifi - # wait a moment to start the interface - sleep 10; - # and here we can download the Hoodfile from the other node - wget -T15 -t5 "http://[fe80::1%w2sta]:2342/keyxchangev2data" -O "$hoodfile" || wget -T15 -t5 "http://[fe80::1%w5sta]:2342/keyxchangev2data" -O "$hoodfile" #UPLINK: Set up uplink data on first contact: if [ -s /tmp/keyxchangev2data ]; then wget -T15 -t5 "http://[fe80::1%w2sta]:2342/sectorfile" -O "$sectortmp" || wget -T15 -t5 "http://[fe80::1%w5sta]:2342/sectorfile" -O "$sectortmp" fi else echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1" - wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O "$hoodfile" + getGatewayHoodfile "$hoodfile" #UPLINK: Do nothing fi fi
Hi Schaut gut aus. Reviewed-by: Tim Niemeyer <tim@tn-x.org> Tim PS: Damit Jan's aus seinem Forward dabei is: Reviewed-by: Jan Kraus <mayosemmel@gmail.com> Am Montag, den 11.06.2018, 19:58 +0200 schrieb Fabian Bläse: > Signed-off-by: Fabian Bläse <fabian@blaese.de> > --- > Apply after MacKnocker patchset! > > Changes in v2: > - Fix indentation > - Remove shebang > - Improve usage message > - Add failure return value to getKeyserverHoodfile if no file was > received > > Changes in v3: > - Fix messed up v2 > --- > .../fff-hoods/files/usr/lib/functions/fff/hoodfile | 86 > ++++++++++++++++++++++ > .../fff/fff-hoods/files/usr/sbin/configurehood | 38 ++-------- > 2 files changed, 91 insertions(+), 33 deletions(-) > create mode 100644 src/packages/fff/fff- > hoods/files/usr/lib/functions/fff/hoodfile > > diff --git a/src/packages/fff/fff- > hoods/files/usr/lib/functions/fff/hoodfile b/src/packages/fff/fff- > hoods/files/usr/lib/functions/fff/hoodfile > new file mode 100644 > index 0000000..306535e > --- /dev/null > +++ b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile > @@ -0,0 +1,86 @@ > +. /usr/share/libubox/jshn.sh > +. /lib/functions/fff/wireless > + > +getWirelessHoodfile() { > + if [ $# != 1 ]; then > + echo "Usage: getWirelessHoodfile <target-file>" > + return 1 > + fi > + file=$1 > + > + echo "Trying to get hoodfile from wireless neighbor..." > + echo "All wireless interfaces will be disabled temporarily!" > + > + # only change temporarily > + > + if ! wifiDelIface; then > + echo "Can't delete current wifi setup" > + exit 1 > + fi > + #now we look for phy and add this > + for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do > + radio="$(wifiAddPhyCond "$phy" "2" "auto")" > + radio5="$(wifiAddPhyCond "$phy" "5" "auto5")" > + if [ -n "$radio5" ] ; then > + radio="$radio5" > + staiface="w5sta" > + else > + staiface="w2sta" > + fi > + > + #and here we add the station > + if ! wifiAddSta "$radio" > "config.franken.freifunk.net" "configSta" "$staiface" ; then > + echo "Can't add Sta interface on $radio." > + exit 1 > + else > + uci -q set network.configSta=interface > + uci -q set network.configSta.proto='static' > + uci -q commit network > + reload_config > + fi > + done > + > + wifi > + # wait a moment to start the interface > + sleep 10; > + > + if wget -T15 -t5 -O "$file" "http://[fe80::1%w2sta]:2342/key > xchangev2data"; then > + return 0 > + elif wget -T15 -t5 -O "$file" "http://[fe80::1%w5sta]:2342/k > eyxchangev2data"; then > + return 0 > + else > + return 1 > + fi > +} > + > +getGatewayHoodfile() { > + if [ $# != 1 ]; then > + echo "Usage: getGatewayHoodfile <target-file>" > + return 1 > + fi > + t file=$1 > + > + echo "Trying to get hoodfile from gateway..." > + > + if wget -T15 -t5 -O "$file" "http://[fe80::1%br-mesh]:2342/k > eyxchangev2data"; then > + return 0 > + else > + return 1 > + fi > +} > + > +getKeyserverHoodfile() { > + if [ $# != 1 ]; then > + echo "Usage: getKeyserverHoodfile <target-file>" > + return 1 > + fi > + file=$1 > + > + echo "Getting hoodfile from Keyserver" > + > + if wget -T15 -t5 -O "$file" "http://keyserver.freifunk-frank > en.de/v2/?lat=$lat&long=$long"; then > + return 0 > + else > + return 1 > + fi > +} > diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood > b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood > index e2c1fab..aee20e5 100755 > --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood > +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood > @@ -5,6 +5,7 @@ > . /lib/functions/fff/network > . /lib/functions/fff/wireless > . /lib/functions/fff/timeserver > +. /usr/lib/functions/fff/hoodfile > > sectorlocal=/etc/sectorfile > sectortmp=/tmp/sectorfile > @@ -78,7 +79,8 @@ if [ -s "$hoodlocal" ]; then > else > # if we have Internet, we download the Hoodfile from the > keyxchangev2 > if hasInternet ; then > - wget -T15 -t5 "http://keyserver.freifunk-franken.de/ > v2/?lat=$lat&long=$long" -O "$hoodfile" > + getKeyserverHoodfile "$hoodfile" > + > rm -f "$sectortmp" > [ -s "$sectorlocal" ] || rm -f "$sectorcopy" # If > internet present, no custom config should be distributed, except when > local file is present > #UPLINK: No uplink download if internet present > @@ -99,45 +101,15 @@ else > > sleep 30 # Wait for the config AP, which may > be created at the same time as this script has started > > - if ! wifiDelIface; then > - echo "Can't delete current wifi > setup" > - exit 1 > - fi > - #now we look for phy and add this > - for phy in $(iw phy | awk '/^Wiphy/{ print > $2 }'); do > - radio="$(wifiAddPhyCond "$phy" "2" > "auto")" > - radio5="$(wifiAddPhyCond "$phy" "5" > "auto5")" > - if [ -n "$radio5" ] ; then > - radio="$radio5" > - staiface="w5sta" > - else > - staiface="w2sta" > - fi > + getWirelessHoodfile "$hoodfile" > > - #and here we add the station > - if ! wifiAddSta "$radio" > "config.franken.freifunk.net" "configSta" "$staiface" ; then > - echo "Can't add Sta > interface on $radio." > - exit 1 > - else > - uci -q set > network.configSta=interface > - uci -q set > network.configSta.proto='static' > - uci -q commit network > - reload_config > - fi > - done > - > - wifi > - # wait a moment to start the interface > - sleep 10; > - # and here we can download the Hoodfile from > the other node > - wget -T15 -t5 "http://[fe80::1%w2sta]:2342/k > eyxchangev2data" -O "$hoodfile" || wget -T15 -t5 > "http://[fe80::1%w5sta]:2342/keyxchangev2data" -O "$hoodfile" > #UPLINK: Set up uplink data on first > contact: > if [ -s /tmp/keyxchangev2data ]; then > wget -T15 -t5 "http://[fe80::1%w2sta > ]:2342/sectorfile" -O "$sectortmp" || wget -T15 -t5 > "http://[fe80::1%w5sta]:2342/sectorfile" -O "$sectortmp" > fi > else > echo "We have a Gateway in Range, we load > the keyxchangev2data from fe80::1" > - wget -T15 -t5 "http://[fe80::1%br-mesh]:2342 > /keyxchangev2data" -O "$hoodfile" > + getGatewayHoodfile "$hoodfile" > #UPLINK: Do nothing > fi > fi
Hi Ich muss mein Review leider zurückziehen.. Hab doch noch zwei Sachen gefunden. :( Am Montag, den 11.06.2018, 19:58 +0200 schrieb Fabian Bläse: > > Signed-off-by: Fabian Bläse <fabian@blaese.de> > --- > Apply after MacKnocker patchset! > > Changes in v2: > - Fix indentation > - Remove shebang > - Improve usage message > - Add failure return value to getKeyserverHoodfile if no file was received > > Changes in v3: > - Fix messed up v2 > --- > .../fff-hoods/files/usr/lib/functions/fff/hoodfile | 86 ++++++++++++++++++++++ > .../fff/fff-hoods/files/usr/sbin/configurehood | 38 ++-------- > 2 files changed, 91 insertions(+), 33 deletions(-) > create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile > > diff --git a/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile > new file mode 100644 > index 0000000..306535e > --- /dev/null > +++ b/src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile > @@ -0,0 +1,86 @@ > +. /usr/share/libubox/jshn.sh > +. /lib/functions/fff/wireless > + > +getWirelessHoodfile() { > > + if [ $# != 1 ]; then > > + echo "Usage: getWirelessHoodfile <target-file>" > > + return 1 > > + fi > > + file=$1 > + > > + echo "Trying to get hoodfile from wireless neighbor..." > > + echo "All wireless interfaces will be disabled temporarily!" > + > > + # only change temporarily > + > > + if ! wifiDelIface; then > > + echo "Can't delete current wifi setup" > > + exit 1 > > + fi > > + #now we look for phy and add this > > + for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do > > + radio="$(wifiAddPhyCond "$phy" "2" "auto")" > > + radio5="$(wifiAddPhyCond "$phy" "5" "auto5")" > > + if [ -n "$radio5" ] ; then > > + radio="$radio5" > > + staiface="w5sta" > > + else > > + staiface="w2sta" > > + fi > + > > + #and here we add the station > > + if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then > > + echo "Can't add Sta interface on $radio." > > + exit 1 > > + else > > + uci -q set network.configSta=interface > > + uci -q set network.configSta.proto='static' > > + uci -q commit network > > + reload_config > > + fi > > + done > + > > + wifi > > + # wait a moment to start the interface > > + sleep 10; > + > > + if wget -T15 -t5 -O "$file" "http://[fe80::1%w2sta]:2342/keyxchangev2data"; then > > + return 0 > > + elif wget -T15 -t5 -O "$file" "http://[fe80::1%w5sta]:2342/keyxchangev2data"; then > > + return 0 > > + else > > + return 1 > > + fi > +} > + > +getGatewayHoodfile() { > > + if [ $# != 1 ]; then > > + echo "Usage: getGatewayHoodfile <target-file>" > > + return 1 > > + fi > + t file=$1 Was ist t? > + > > + echo "Trying to get hoodfile from gateway..." > + > > + if wget -T15 -t5 -O "$file" "http://[fe80::1%br-mesh]:2342/keyxchangev2data"; then > > + return 0 > > + else > > + return 1 > > + fi > +} > + > +getKeyserverHoodfile() { > > + if [ $# != 1 ]; then > > + echo "Usage: getKeyserverHoodfile <target-file>" > > + return 1 > > + fi > > + file=$1 > + > > + echo "Getting hoodfile from Keyserver" > + > + if wget -T15 -t5 -O "$file" "http://keyserver.freifunk-franken.de/v2/?lat=$lat&long=$long"; then Mir gefällt nicht, dass auf die globale Variable $lat und $long verwiesen wird. Das kann ein Caller nicht wissen. Tim > + return 0 > > + else > > + return 1 > > + fi > +} > diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood > index e2c1fab..aee20e5 100755 > --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood > +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood > @@ -5,6 +5,7 @@ > . /lib/functions/fff/network > . /lib/functions/fff/wireless > . /lib/functions/fff/timeserver > +. /usr/lib/functions/fff/hoodfile > > sectorlocal=/etc/sectorfile > sectortmp=/tmp/sectorfile > @@ -78,7 +79,8 @@ if [ -s "$hoodlocal" ]; then > else > > # if we have Internet, we download the Hoodfile from the keyxchangev2 > > if hasInternet ; then > > - wget -T15 -t5 "http://keyserver.freifunk-franken.de/v2/?lat=$lat&long=$long" -O "$hoodfile" > > + getKeyserverHoodfile "$hoodfile" > + > > rm -f "$sectortmp" > > [ -s "$sectorlocal" ] || rm -f "$sectorcopy" # If internet present, no custom config should be distributed, except when local file is present > > #UPLINK: No uplink download if internet present > @@ -99,45 +101,15 @@ else > > > sleep 30 # Wait for the config AP, which may be created at the same time as this script has started > > > - if ! wifiDelIface; then > > - echo "Can't delete current wifi setup" > > - exit 1 > > - fi > > - #now we look for phy and add this > > - for phy in $(iw phy | awk '/^Wiphy/{ print $2 }'); do > > - radio="$(wifiAddPhyCond "$phy" "2" "auto")" > > - radio5="$(wifiAddPhyCond "$phy" "5" "auto5")" > > - if [ -n "$radio5" ] ; then > > - radio="$radio5" > > - staiface="w5sta" > > - else > > - staiface="w2sta" > > - fi > > + getWirelessHoodfile "$hoodfile" > > > - #and here we add the station > > - if ! wifiAddSta "$radio" "config.franken.freifunk.net" "configSta" "$staiface" ; then > > - echo "Can't add Sta interface on $radio." > > - exit 1 > > - else > > - uci -q set network.configSta=interface > > - uci -q set network.configSta.proto='static' > > - uci -q commit network > > - reload_config > > - fi > > - done > - > > - wifi > > - # wait a moment to start the interface > > - sleep 10; > > - # and here we can download the Hoodfile from the other node > > - wget -T15 -t5 "http://[fe80::1%w2sta]:2342/keyxchangev2data" -O "$hoodfile" || wget -T15 -t5 "http://[fe80::1%w5sta]:2342/keyxchangev2data" -O "$hoodfile" > > #UPLINK: Set up uplink data on first contact: > > if [ -s /tmp/keyxchangev2data ]; then > > wget -T15 -t5 "http://[fe80::1%w2sta]:2342/sectorfile" -O "$sectortmp" || wget -T15 -t5 "http://[fe80::1%w5sta]:2342/sectorfile" -O "$sectortmp" > > fi > > else > > echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1" > > - wget -T15 -t5 "http://[fe80::1%br-mesh]:2342/keyxchangev2data" -O "$hoodfile" > > + getGatewayHoodfile "$hoodfile" > > #UPLINK: Do nothing > > fi > > fi
Hallo Tim > On 11. Jun 2018, at 20:55, Tim Niemeyer <tim@tn-x.org> wrote: > > Was ist t? Gnaaa. Ich schick nie wieder Patches während einem Treffen.. :-D -> morgen v4 :-( > Mir gefällt nicht, dass auf die globale Variable $lat und $long > verwiesen wird. Das kann ein Caller nicht wissen. Da ist was dran. War ich wohl etwas zu schnell beim copy & paste. Ich werds als Funktionsparameter aufnehmen. -> v4 Gruß Fabian
Stimme Tims Kommentaren zu (sort –u kenne ich nicht…) und reviewe dann beide Patches in v4.
Vielen Dank und Grüße
Adrian
From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf Of Fabian Bläse
Sent: Montag, 11. Juni 2018 23:10
To: Tim Niemeyer <tim@tn-x.org>
Cc: franken-dev <franken-dev@freifunk.net>
Subject: Re: [PATCH v3 1/2] Move hoodfile acquisition into function
Hallo Tim
On 11. Jun 2018, at 20:55, Tim Niemeyer <tim@tn-x.org <mailto:tim@tn-x.org> > wrote:
Was ist t?
Gnaaa. Ich schick nie wieder Patches während einem Treffen.. :-D
-> morgen v4 :-(
Mir gefällt nicht, dass auf die globale Variable $lat und $long
verwiesen wird. Das kann ein Caller nicht wissen.
Da ist was dran. War ich wohl etwas zu schnell beim copy & paste. Ich werds als Funktionsparameter aufnehmen.
-> v4
Gruß
Fabian
Signed-off-by: Fabian Bläse <fabian@blaese.de> --- Apply after MacKnocker patchset! Changes in v2: - Fix indentation - Remove shebang - Improve usage message - Add failure return value to getKeyserverHoodfile if no file was received Changes in v3: - Fix messed up v2 --- .../fff-hoods/files/usr/lib/functions/fff/hoodfile | 86 ++++++++++++++++++++++ .../fff/fff-hoods/files/usr/sbin/configurehood | 38 ++-------- 2 files changed, 91 insertions(+), 33 deletions(-) create mode 100644 src/packages/fff/fff-hoods/files/usr/lib/functions/fff/hoodfile