Skip to content

Instantly share code, notes, and snippets.

@spoetnik
Last active May 19, 2023 17:44
Show Gist options
  • Save spoetnik/ebeb9b6a62601643e5f25bc351fb47f7 to your computer and use it in GitHub Desktop.
Save spoetnik/ebeb9b6a62601643e5f25bc351fb47f7 to your computer and use it in GitHub Desktop.
#!/bin/bash
function jwt_decode(){
jq -R 'split(".") | .[1] | @base64d | fromjson' <<< "$1"
}
function remove_quotes(){
sed -e 's/^"//' -e 's/"$//' <<<"$1"
}
# get the token from the Dahsboard Loginpage
token=$(curl 'https://dashboard.hammerhead.io/v1/auth/token' \
-s \
-H 'Accept: application/json; charset=UTF-8 ' \
-H 'Content-Type: application/json' \
--data-raw '{"grant_type": "password", "username": "<YOUR_USERNAME>", "password": "<YOUR_PASSWORD>"}' | jq '.access_token')
# get the userid from the jwt token
userid=$(jwt_decode $token | jq '.sub')
#to remove the double quotes from the token string
token=$(remove_quotes $token)
#to remove the double quotes from the userid string
userid=$(remove_quotes $userid)
#Refresh the routes
curl "https://dashboard.hammerhead.io/v1/users/$userid/routes/sync" \
-s \
-H 'Accept: */*' \
-H 'Accept-Language: en-US,en;q=0.9,nl;q=0.8' \
-H "Authorization: Bearer $token" \
-H 'Connection: keep-alive' \
-H 'Content-Type: application/json' \
-H 'Origin: https://dashboard.hammerhead.io' \
-H 'Referer: https://dashboard.hammerhead.io/routes' \
--data-raw 'null' \
--compressed
@spoetnik
Copy link
Author

Replace <YOUR_USERNAME> and <YOUR_PASSWORD> with your hammerhead dashboard credentials.

This script refreshes your Komoot, Strava or other routes with the hammerhead dashboard, and thus your Hammerhead Karoo device

@spoetnik
Copy link
Author

Use this script in a cron, or integrate it in your Home Automation when your Karoo connects to your WiFi

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment