forked from freifunk-franken/firmware
hood files: Use more meaningful and concise naming scheme
Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de> Reviewed-by: Fabian Bläse <fabian@blaese.de> Reviewed-by: Robert Langhammer <rlanghammer@web.de> Tested-by: Fabian Bläse <fabian@blaese.de> Reviewed-by: Tim Niemeyer <tim@tn-x.org>
This commit is contained in:
parent
d09df921e0
commit
845886d16a
|
@ -7,9 +7,10 @@
|
|||
. /lib/functions/fff/timeserver
|
||||
. /usr/lib/functions/fff/hoodfile
|
||||
|
||||
hoodlocal=/etc/hoodfile
|
||||
|
||||
rm -f "$hoodfile"
|
||||
hoodfilelocal=/etc/hoodfile
|
||||
|
||||
rm -f "$hoodfiletmp"
|
||||
|
||||
# Gatewaycheck function
|
||||
isGatewayAvailable() {
|
||||
|
@ -35,7 +36,7 @@ hasInternet() {
|
|||
|
||||
# Hidden AP check
|
||||
|
||||
if [ -s "$hoodfilecopy" ] && isGatewayAvailable ; then
|
||||
if [ -s "$hoodfilewww" ] && isGatewayAvailable ; then
|
||||
needwifi="0"
|
||||
for radio in $(uci show wireless | sed -n 's,.*\.\([a-z0-9]*\)=wifi-device,\1,p'); do
|
||||
freq="2"
|
||||
|
@ -67,13 +68,13 @@ if [ -s "$hoodfilecopy" ] && isGatewayAvailable ; then
|
|||
fi
|
||||
fi
|
||||
|
||||
if [ -s "$hoodlocal" ]; then
|
||||
hoodfile="$hoodlocal"
|
||||
if [ -s "$hoodfilelocal" ]; then
|
||||
hoodfiletmp="$hoodfilelocal"
|
||||
echo "Use local hood file"
|
||||
else
|
||||
# if we have Internet, we download the Hoodfile from the keyxchangev2
|
||||
if hasInternet ; then
|
||||
getKeyserverHoodfile "$hoodfile"
|
||||
getKeyserverHoodfile "$hoodfiletmp"
|
||||
|
||||
#if no Internet, we connect to the hidden AP and download the file from another Node in range
|
||||
else
|
||||
|
@ -82,7 +83,7 @@ else
|
|||
if ! isGatewayAvailable ; then
|
||||
#now we haven't a gateway in Range, we search for a hidden AP to get a keyxchangev2data file!
|
||||
#first we delete all wifi settings
|
||||
rm -f "$hoodfilecopy" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place
|
||||
rm -f "$hoodfilewww" # delete this, so interfaces are recreated if reconnect with unchanged hood file takes place
|
||||
|
||||
uci -q del "system.@system[0].hood"
|
||||
uci -q commit system
|
||||
|
@ -90,26 +91,26 @@ else
|
|||
|
||||
sleep 30 # Wait for the config AP, which may be created at the same time as this script has started
|
||||
|
||||
getEthernetHoodfile "$hoodfile" || getWirelessHoodfile "$hoodfile"
|
||||
getEthernetHoodfile "$hoodfiletmp" || getWirelessHoodfile "$hoodfiletmp"
|
||||
else
|
||||
echo "We have a Gateway in Range, we load the keyxchangev2data from fe80::1"
|
||||
getGatewayHoodfile "$hoodfile"
|
||||
getGatewayHoodfile "$hoodfiletmp"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ -s "$hoodfile" ]; then
|
||||
if [ -s "$hoodfiletmp" ]; then
|
||||
|
||||
# we get a json file in this format:
|
||||
# https://pw.freifunk-franken.de/patch/205/
|
||||
# but without signature, every hood file we get is valid!
|
||||
|
||||
catnew="$(cat "$hoodfile" | sed 's/"timestamp”: *"[0-9]*"/"timestamp":0/')"
|
||||
catold="$(cat "$hoodfilecopy" 2>/dev/null | sed 's/"timestamp”: *"[0-9]*"/"timestamp":0/')"
|
||||
catnew="$(cat "$hoodfiletmp" | sed 's/"timestamp”: *"[0-9]*"/"timestamp":0/')"
|
||||
catold="$(cat "$hoodfilewww" 2>/dev/null | sed 's/"timestamp”: *"[0-9]*"/"timestamp":0/')"
|
||||
sumnew=$(echo "$catnew" | sha256sum | cut -f1 -d " ")
|
||||
sumold=$(echo "$catold" | sha256sum | cut -f1 -d " ")
|
||||
|
||||
json_load "$(cat "$hoodfile")"
|
||||
json_load "$(cat "$hoodfiletmp")"
|
||||
|
||||
if [ "$sumnew" != "$sumold" ] ; then
|
||||
echo "New file detected, we reconfigure the Node";
|
||||
|
@ -184,7 +185,7 @@ if [ -s "$hoodfile" ]; then
|
|||
|
||||
# copy the file to webroot so that other mesh routers can download it;
|
||||
# copy only after all other steps so IF can be reentered if something goes wrong
|
||||
cp "$hoodfile" "$hoodfilecopy"
|
||||
cp "$hoodfiletmp" "$hoodfilewww"
|
||||
|
||||
# This is a workaround to enable alfred on devices which do not see a configap during initial setup
|
||||
/etc/init.d/alfred restart
|
||||
|
|
|
@ -4,15 +4,15 @@
|
|||
|
||||
. /usr/share/libubox/jshn.sh
|
||||
|
||||
hoodfile="/tmp/keyxchangev2data"
|
||||
hoodfilecopy="/www/hood/keyxchangev2data"
|
||||
hoodfiletmp="/tmp/hoodfile"
|
||||
hoodfilewww="/www/hood/keyxchangev2data"
|
||||
|
||||
getJsonPath() {
|
||||
jsonfile=""
|
||||
if [ -s "$hoodfilecopy" ] ; then
|
||||
jsonfile="$hoodfilecopy"
|
||||
elif [ -s "$hoodfile" ] ; then
|
||||
jsonfile="$hoodfile"
|
||||
if [ -s "$hoodfilewww" ] ; then
|
||||
jsonfile="$hoodfilewww"
|
||||
elif [ -s "$hoodfiletmp" ] ; then
|
||||
jsonfile="$hoodfiletmp"
|
||||
fi
|
||||
echo "$jsonfile"
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ make_config() {
|
|||
rm /tmp/fastd_fff_peers/*
|
||||
count=0
|
||||
Index=1
|
||||
json_load "$(cat "$hoodfile")"
|
||||
json_load "$(cat "$hoodfiletmp")"
|
||||
json_select vpn
|
||||
# get fastd peers
|
||||
while json_select "$Index" > /dev/null
|
||||
|
@ -54,7 +54,7 @@ json_select ".." # back to root
|
|||
# main
|
||||
|
||||
# Only do something when file is here and greater 0 byte
|
||||
if [ -s "$hoodfile" ]; then
|
||||
if [ -s "$hoodfiletmp" ]; then
|
||||
# set some vars
|
||||
hostname=$(cat /proc/sys/kernel/hostname)
|
||||
mac=$(awk '{ mac=toupper($1); gsub(":", "", mac); print mac }' /sys/class/net/br-mesh/address 2>/dev/null)
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
if [ "$REQUEST_METHOD" == "POST" ] ; then
|
||||
if [ "$POST_resethood" != "" ] ; then
|
||||
# reset hood
|
||||
rm "$hoodfilecopy" 2> /dev/null
|
||||
rm "$hoodfilewww" 2> /dev/null
|
||||
MSG='<span class="green">Hood-Daten werden innerhalb von 5 Minuten neu prozessiert.</span>'
|
||||
fi
|
||||
fi
|
||||
|
|
Loading…
Reference in New Issue