Merge pull request #992 from srd424/upst-latlong-fix

Fix GeoIP data validation
This commit is contained in:
ehpersonal38
2023-08-12 13:22:47 -04:00
committed by GitHub
+5 -8
View File
@@ -8,14 +8,11 @@ echo "Beginning $0"
birdnet_conf=$my_dir/birdnet.conf
# Retrieve latitude and longitude from web
LATITUDE=$(curl -s4 http://ip-api.com/json?fields=lat,lon | jq .lat)
LONGITUDE=$(curl -s4 http://ip-api.com/json?fields=lat,lon | jq .lon)
# Define regular expression pattern
pattern='^[+-]?[0-9]{2}\.[0-9]{4}$'
# Check if latitude and longitude match the pattern
if ! [[ $LATITUDE =~ $pattern ]] || ! [[ $LONGITUDE =~ $pattern ]]; then
json=$(curl -s4 http://ip-api.com/json)
if [ "$(echo "$json" | jq -r .status)" = "success" ]; then
LATITUDE=$(echo "$json" | jq .lat)
LONGITUDE=$(echo "$json" | jq .lon)
else
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
LONGITUDE=0.0000