The GeoIP service doesn't always return 4 decimal places - so just
check for its own 'success' state and don't try to validate the numbers
This commit is contained in:
@@ -8,14 +8,11 @@ echo "Beginning $0"
|
|||||||
birdnet_conf=$my_dir/birdnet.conf
|
birdnet_conf=$my_dir/birdnet.conf
|
||||||
|
|
||||||
# Retrieve latitude and longitude from web
|
# Retrieve latitude and longitude from web
|
||||||
LATITUDE=$(curl -s4 http://ip-api.com/json?fields=lat,lon | jq .lat)
|
json=$(curl -s4 http://ip-api.com/json)
|
||||||
LONGITUDE=$(curl -s4 http://ip-api.com/json?fields=lat,lon | jq .lon)
|
if [ "$(echo "$json" | jq -r .status)" = "success" ]; then
|
||||||
|
LATITUDE=$(echo "$json" | jq .lat)
|
||||||
# Define regular expression pattern
|
LONGITUDE=$(echo "$json" | jq .lon)
|
||||||
pattern='^[+-]?[0-9]{2}\.[0-9]{4}$'
|
else
|
||||||
|
|
||||||
# Check if latitude and longitude match the pattern
|
|
||||||
if ! [[ $LATITUDE =~ $pattern ]] || ! [[ $LONGITUDE =~ $pattern ]]; then
|
|
||||||
echo -e "\033[33mCouldn't set latitude and longitude automatically, you will need to do this manually from the web interface by navigating to Tools -> Settings -> Location.\033[0m"
|
echo -e "\033[33mCouldn't set latitude and longitude automatically, you will need to do this manually from the web interface by navigating to Tools -> Settings -> Location.\033[0m"
|
||||||
LATITUDE=0.0000
|
LATITUDE=0.0000
|
||||||
LONGITUDE=0.0000
|
LONGITUDE=0.0000
|
||||||
|
|||||||
Reference in New Issue
Block a user