Skip to content

Instantly share code, notes, and snippets.

@jtuz
Created February 21, 2026 01:26
Show Gist options
  • Select an option

  • Save jtuz/83c527befb940b8c560c3dc3c92333d7 to your computer and use it in GitHub Desktop.

Select an option

Save jtuz/83c527befb940b8c560c3dc3c92333d7 to your computer and use it in GitHub Desktop.
Get current location with Mozilla
#!/bin/bash
# This script fetches lat and long information from Mozilla's geolocation service. It then passes
# lat and long to redshift-gtk. If geolocation service is not available (e.g. no internet
# connection, service down) it sleeps and retries.
# URL taken from geoclue2. It returns JSON document with LAT and LONG.
URL="https://location.services.mozilla.com/v1/geolocate?key=16674381-f021-49de-8622-3021c5942aff"
# LAT and LONG numbers in the following format: "LAT:LON"
COORDS=""
function get_geolocation() {
exit_status=1
retry_times=30
sleep_time=15
while [ $exit_status -ne 0 ] && [ $retry_times -gt 0 ]; do
sleep $sleep_time
echo "Trying to fetch geolocation coordinates from $URL"
json_coords=$(curl -s $URL)
exit_status=$?
retry_times=$((retry_times - 1))
done
echo "Received: $json_coords"
COORDS=$(jq -c -r '[.location.lat, .location.lng] | @csv' <<< $json_coords | sed 's/,/:/')
}
get_geolocation
if [ -z "$COORDS" ]; then
echo "Unknown Error: LAT and LONG not set. Is JSON response malformed or has a different schema?"
exit 1
fi
redshift-gtk -l $COORDS
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment