enhancement: migrate location info to uci (#168)

* add uci migration script

* removed debug lines

* added newline to end

* include gridsquare values

* migrate lat/lon/gridsquare to uci format

* remove from sysupgrade kept files list
This commit is contained in:
dman776 2021-11-09 17:03:20 -06:00 committed by GitHub
parent 8ea58e4949
commit f0c62fc2a7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 47 additions and 65 deletions

View File

@ -18,8 +18,6 @@
/etc/firewall.user
/etc/group
/etc/hosts
/etc/gridsquare
/etc/latlon
/etc/local/services
/etc/local/uci/hsmmmesh
/etc/passwd

View File

@ -0,0 +1,25 @@
#! /bin/sh
if [ "$(/sbin/uci -q get aredn.\@location[0])" = "" ]; then
/sbin/uci -q add aredn location
fi
# read /etc/latlon
if [ -f /etc/latlon ]
then
LAT=$(head -1 /etc/latlon)
LON=$(tail -1 /etc/latlon)
fi
if [ -f /etc/gridsquare ]
then
GRIDSQUARE=$(head -1 /etc/gridsquare)
fi
/sbin/uci -q set aredn.@location[0].lat="$LAT"
/sbin/uci -q set aredn.@location[0].lon="$LON"
/sbin/uci -q set aredn.@location[0].gridsquare="$GRIDSQUARE"
/sbin/uci -q commit aredn
# remove the /etc/latlon and gridsquare files
rm -f /etc/latlon
rm -f /etc/gridsquare

View File

@ -109,34 +109,16 @@ end
-- Returns array [Latitude, Longitude]
-------------------------------------
function model.getLatLon()
local llfname="/etc/latlon"
local lat=""
local lon=""
if file_exists(llfname) then
llfile=io.open(llfname,"r")
if llfile~=nil then
lat=llfile:read()
lon=llfile:read()
llfile:close()
end
end
return lat,lon
loc=aredn_uci.getUciConfType("aredn", "location")
return loc[1]['lat'], loc[1]['lon']
end
-------------------------------------
-- Returns Grid Square of Node
-------------------------------------
function model.getGridSquare()
local gsfname="/etc/gridsquare"
local grid=""
if file_exists(gsfname) then
gsfile=io.open(gsfname,"r")
if gsfile~=nil then
grid=gsfile:read()
gsfile:close()
end
end
return grid
loc=aredn_uci.getUciConfType("aredn", "location")
return loc[1]['gridsquare']
end
-------------------------------------

View File

@ -44,7 +44,7 @@ require("nixio")
local json = require("luci.jsonc")
require("iwinfo")
local API_VERSION="1.3"
local API_VERSION="1.4"
-- Function extensions
os.capture = capture

View File

@ -218,18 +218,17 @@ if($parms{button_updatelocation})
# validate values
if($parms{gridsquare} =~ /^[A-Z][A-Z]\d\d[a-z][a-z]$/)
{
# delete/define file
unlink("/etc/gridsquare") if(-f "/etc/gridsquare");
my $rcgood=open(my $gs, ">", "/etc/gridsquare");
push @errors, "Cannot open gridsquare file" unless $rcgood;
print $gs "$parms{gridsquare}\n";
close($gs);
# set values/commit
$rc=&uci_set_indexed_option("aredn","location",0,"gridsquare", $parms{gridsquare});
$rc=&uci_commit("aredn");
push @errors, "Cannot save gridsquare in uci" if $rc ne "0";
push @output, "Gridsquare updated.\n";
} else {
push @errors, "ERROR: Gridsquare format is: 2-uppercase letters, 2-digits, 2-lowercase letters. (AB12cd)\n";
}
} else {
unlink("/etc/gridsquare") if(-f "/etc/gridsquare");
$rc=&uci_set_indexed_option("aredn","location",0,"gridsquare", "");
$rc=&uci_commit("aredn");
push @output, "Gridsquare purged.\n";
}
@ -239,13 +238,11 @@ if($parms{button_updatelocation})
# validate values
if($parms{latitude} =~ /^([-+]?\d{1,2}([.]\d+)?)$/ and $parms{longitude} =~ /^([-+]?\d{1,3}([.]\d+)?)$/) {
if($parms{latitude} >= -90 and $parms{latitude} <= 90 and $parms{longitude} >= -180 and $parms{longitude} <= 180) {
# delete/define file
unlink("/etc/latlon") if(-f "/etc/latlon");
$rcgood=open(my $ll, ">", "/etc/latlon");
push @errors, "Cannot open lat/lon file" unless $rcgood;
print $ll "$parms{latitude}\n";
print $ll "$parms{longitude}\n";
close($ll);
# set values/commit
$rc=&uci_set_indexed_option("aredn","location",0,"lat", $parms{latitude});
$rc=&uci_set_indexed_option("aredn","location",0,"lon", $parms{longitude});
$rc=&uci_commit("aredn");
push @errors, "Cannot save latitude/longitude in uci" if $rc ne "0";
push @output, "Lat/lon updated.\n";
} else {
push @errors, "ERROR: Lat/lon values must be between -90/90 and -180/180, respectively.\n";
@ -254,7 +251,9 @@ if($parms{button_updatelocation})
push @errors, "ERROR: Lat/lon format is decimal: (ex. 30.121456 or -95.911154)\n";
}
} else {
unlink("/etc/latlon") if(-f "/etc/latlon");
$rc=&uci_set_indexed_option("aredn","location",0,"lat", "");
$rc=&uci_set_indexed_option("aredn","location",0,"lon", "");
$rc=&uci_commit("aredn");
push @output, "Lat/lon purged.\n";
}
}
@ -262,31 +261,9 @@ if($parms{button_updatelocation})
#
# retrieve location data
#
if(-f "/etc/latlon")
{
$rcgood=open(FILE, "/etc/latlon");
push @errors, "ERROR: reading lat/lon data\n" unless $rcgood;
while(<FILE>){
chomp;
push @lines,$_;
}
close(FILE);
$lat=$lines[0];
$lon=$lines[1];
}
@lines=();
if(-f "/etc/gridsquare")
{
$rcgood=open(FILE, "/etc/gridsquare");
push @errors, "ERROR: reading gridsquare data\n" unless $rcgood;
while(<FILE>){
chomp;
push @lines,$_;
}
close(FILE);
$gridsquare=$lines[0];
}
$lat=&uci_get_indexed_option("aredn","location",0,"lat");
$lon=&uci_get_indexed_option("aredn","location",0,"lon");
$gridsquare=&uci_get_indexed_option("aredn","location",0,"gridsquare");
# validate and save configuration