Skip to content

Instantly share code, notes, and snippets.

@szampardi
Created January 2, 2023 10:32
Show Gist options
  • Save szampardi/e66a11a87d54c9c7e03912dae9fed4aa to your computer and use it in GitHub Desktop.
Save szampardi/e66a11a87d54c9c7e03912dae9fed4aa to your computer and use it in GitHub Desktop.
Nextcloud PhoneTrack gpsd curl
#!/bin/bash
PHONETRACK_URL="https://cloud.example.com/apps/phonetrack/logGet"
PHONETRACK_SESSION=
PHONETRACK_DEVICE=
MINIMUM_SPEED=0
while getopts ":m:" opt; do
case "${opt}" in
m) MINIMUM_SPEED="${OPTARG}" ;;
esac
done
shift $((OPTIND - 1))
_get_data() { gpspipe -x 10 -n 10 -w | grep -m 1 -E 'TPV|lat'; }
_send_data() {
local lat lon alt speed _url
_url="${PHONETRACK_URL}/${PHONETRACK_SESSION}/${PHONETRACK_DEVICE}"
lat="${1}"
lon="${2}"
if [[ -n ${lat} ]] && [[ -n ${lon} ]]; then
_url+="?lat=${lat}&lon=${lon}"
else
return 1
fi
alt="${3}"
if [[ -n ${alt} ]]; then
_url+="&alt=${alt}"
fi
speed="${4}"
if [[ -n ${speed} ]]; then
_url+="&speed=${speed}"
fi
_url+="&timestamp=$(date '+%s')"
curl "${_url}"
}
_data="$(_get_data)"
if [[ -n ${_data} ]]; then
speed=$(jq -r '.speed' <<<"${_data}")
if awk -v m="${MINIMUM_SPEED}" '{if ($1 > m) print $1; else exit 1}' <<<${speed}; then
lat=$(jq -r '.lat' <<<"${_data}")
lon=$(jq -r '.lon' <<<"${_data}")
alt=$(jq -r '.alt' <<<"${_data}")
_send_data "${lat}" "${lon}" "${alt}" "${speed}"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment