Location and Address Automatically
Introduction:
Often when the Nodegrid comes up. it would be great if the NG knows where it is automatically. currently, the user would have to enter the address and the coordinates manually in the System::Preferences.
Requirement:

The Nodegrid needs to be plugged into an ethernet IP network with internet accessible
Steps:
This script will automatically run when the Nodegrid boots up.
1. In the Nodegrid console log in as root "shell sudo su -"
2. Copy the attached script "getNGLoc.sh" to the Nodegrid /etc/init.d folder
3. Go to /etc/init.d folder and change script to be executable "chmod +x getNGLoc.sh"
4. Go to /etc/rc5.d folder
5. Set a soft link to the script "ln -s /etc/init.d/getNGLoc.sh S99getNGLoc.sh"
The system will now run this script when the Nodegrid boots up to update the System::Preference address and coordinates
getNGLoc.sh
- #!/bin/bash
- # wait for the system to comes up first before execution sleep 60 Seconds
- sleep 60
- myLocData=$(curl http://ip-api.com/json?fields=lat,lon)
- longitude=$(echo "$myLocData" | jq -r .lon)
- latitude=$(echo "$myLocData" | jq -r .lat)
- coord="$latitude,$longitude"
- # Fetch geolocation data using ipinfo.io
- location_data=$(curl -s ipinfo.io)
- # Extract city and region (state) from the JSON response
- city=$(echo $location_data | jq -r '.city')
- state=$(echo $location_data | jq -r '.region')
- address="$city,$state"
- tmpFile="/home/admin/outLoc.cli"
- echo "cd /settings/system_preferences/" > $tmpFile
- echo "set address_location=$address" >> $tmpFile
- echo "set coordinates=$coord" >> $tmpFile
- echo "commit" >> $tmpFile
- su - admin -c "cli -f $tmpFile"
- rm $tmpFile