[PATCH 1/4] hood/sector files: Use more meaningful and concise naming scheme

mail at adrianschmutzler.de mail at adrianschmutzler.de
So Jun 24 14:13:09 CEST 2018


Als wir das sectorfile eingebaut haben, wollte jemand, dass im hoodutils nur die Sachen stehen, die an mehreren Stellen benutzt werden (Ich habe nämlich zunächst auch alles in das File wo die Functions stehen).

Was im configurehood steht, wird auch nur dort verwendet. Mir ist es im Prinzip wurscht, deshalb hab ichs damals dann so gemacht.

> -----Original Message-----
> From: Fabian Bläse [mailto:fabian at blaese.de]
> Sent: Sonntag, 24. Juni 2018 11:24
> To: Adrian Schmutzler <freifunk at adrianschmutzler.de>
> Cc: franken-dev <franken-dev at freifunk.net>
> Subject: Re: [PATCH 1/4] hood/sector files: Use more meaningful and concise
> naming scheme
> 
> Warum stehen die sector-Variablen und hoodlocal eigentlich im
> configurehood?
> Vielleicht sollte man das mal bei Gelegenheit auch mal ins hoodutils stecken..
> Hat aber mit diesem Patch direkt nichts zu tun..
> 
> Reviewed-by: Fabian Bläse <fabian at blaese.de>
> 
> Fabian
> 
> > On 13. Jun 2018, at 16:36, Adrian Schmutzler
> <freifunk at adrianschmutzler.de> wrote:
> >
> > Signed-off-by: Adrian Schmutzler <freifunk at adrianschmutzler.de>
> > ---
> > .../fff/fff-hoods/files/usr/sbin/configurehood     | 53 +++++++++++---------
> --
> > .../files/lib/functions/fff/keyxchange             | 12 ++---
> > .../fff/fff-vpn-select/files/usr/sbin/vpn-select   |  4 +-
> > .../fff/fff-web/files/www/ssl/cgi-bin/home.html    |  2 +-
> > 4 files changed, 36 insertions(+), 35 deletions(-)
> >
> > diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > index 1399e11..b0c43ed 100755
> > --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> > @@ -7,12 +7,13 @@
> > . /lib/functions/fff/timeserver
> > . /usr/lib/functions/fff/hoodfile
> >
> > -sectorlocal=/etc/sectorfile
> > -sectortmp=/tmp/sectorfile
> > -sectorcopy=/www/hood/sectorfile
> > -hoodlocal=/etc/hoodfile
> > +sectorfilelocal=/etc/sectorfile
> > +sectorfiletmp=/tmp/sectorfile
> > +sectorfilewww=/www/hood/sectorfile
> >
> > -rm -f "$hoodfile"
> > +hoodfilelocal=/etc/hoodfile
> > +
> > +rm -f "$hoodfiletmp"
> >
> > # Gatewaycheck function
> > isGatewayAvailable() {
> > @@ -38,7 +39,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"
> > @@ -70,16 +71,16 @@ 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"
> >
> > -		rm -f "$sectortmp"
> > -		[ -s "$sectorlocal" ] || rm -f "$sectorcopy" # If internet
> present, no custom config should be distributed, except when local file is
> present
> > +		rm -f "$sectorfiletmp"
> > +		[ -s "$sectorfilelocal" ] || rm -f "$sectorfilewww" # If internet
> > +present, no custom config should be distributed, except when local
> > +file is present
> > 		#UPLINK: No uplink download if internet present
> > 		#if no Internet, we connect to the hidden AP and download
> the file from another Node in range
> > 	else
> > @@ -88,9 +89,9 @@ 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 "$sectorcopy" # always delete: no broadcast for
> isolated device
> > -			rm -f "$sectortmp"
> > +			rm -f "$hoodfilewww" # delete this, so interfaces are
> recreated if reconnect with unchanged hood file takes place
> > +			rm -f "$sectorfilewww" # always delete: no broadcast
> for isolated device
> > +			rm -f "$sectorfiletmp"
> >
> > 			uci -q del "system. at system[0].hood"
> > 			uci -q commit system
> > @@ -98,29 +99,29 @@ 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"
> >
> > 			#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"
> > +				wget -T15 -t5
> "http://[fe80::1%w2sta]:2342/sectorfile" -O "$sectorfiletmp" || wget -T15 -t5
> "http://[fe80::1%w5sta]:2342/sectorfile" -O "$sectorfiletmp"
> > 			fi
> > 		else
> > 			echo "We have a Gateway in Range, we load the
> keyxchangev2data from fe80::1"
> > -			getGatewayHoodfile "$hoodfile"
> > +			getGatewayHoodfile "$hoodfiletmp"
> > 			#UPLINK: Do nothing
> > 		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!
> >
> > -	[ -s "$sectorlocal" ] && sectortmp="$sectorlocal" # Use local file if
> present (configuration set by user)
> > -	if [ -s "$sectortmp" ] ; then
> > -		json_load "$(cat "$sectortmp")"
> > +	[ -s "$sectorfilelocal" ] && sectorfiletmp="$sectorfilelocal" # Use local
> file if present (configuration set by user)
> > +	if [ -s "$sectorfiletmp" ] ; then
> > +		json_load "$(cat "$sectorfiletmp")"
> > 		json_select hood
> > 		json_get_var mesh_id mesh_id
> > 		json_get_var mesh_bssid mesh_bssid
> > @@ -132,12 +133,12 @@ if [ -s "$hoodfile" ]; then
> > 		json_get_var mesh_type5 mesh_type5
> > 	fi
> >
> > -	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"; @@ -
> 212,8 +213,8
> > @@ 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"
> > -		[ -s "$sectortmp" ] && cp "$sectortmp" "$sectorcopy"
> > +		cp "$hoodfiletmp" "$hoodfilewww"
> > +		[ -s "$sectorfiletmp" ] && cp "$sectorfiletmp"
> "$sectorfilewww"
> >
> > 		# This is a workaround to enable alfred on devices which do
> not see a configap during initial setup
> > 		/etc/init.d/alfred restart
> > diff --git
> > a/src/packages/fff/fff-hoodutils/files/lib/functions/fff/keyxchange
> > b/src/packages/fff/fff-hoodutils/files/lib/functions/fff/keyxchange
> > index 30963ae..4d624a1 100644
> > ---
> > a/src/packages/fff/fff-hoodutils/files/lib/functions/fff/keyxchange
> > +++ b/src/packages/fff/fff-hoodutils/files/lib/functions/fff/keyxchang
> > +++ e
> > @@ -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"
> > }
> > diff --git a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
> > b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
> > index 85930a8..135c063 100755
> > --- a/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
> > +++ b/src/packages/fff/fff-vpn-select/files/usr/sbin/vpn-select
> > @@ -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) diff --git
> > a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > index 21bd4e7..ef71eb4 100755
> > --- a/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > +++ b/src/packages/fff/fff-web/files/www/ssl/cgi-bin/home.html
> > @@ -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
> > --
> > 2.7.4
> >




Mehr Informationen über die Mailingliste franken-dev