Last active
February 3, 2022 11:51
-
-
Save wivaku/67fa501d6f5c6fe3cba379b066f97a24 to your computer and use it in GitHub Desktop.
script to download the Concept2 firmware files similar to what Concept2 Utility does
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# UNOFFICIAL script to download the Concept2 firmwares for PM3/4/5 monitors for rower/skierg/bike | |
# similar to what the Concept2 Utility does: first retrieve list of available firmwares and then download them | |
# optional parameters | |
# -d <folder> e.g. /Volumes/MYCONCEPT2USB/Concept2/Firmware (default: $HOME/Downloads/Concept2/Firmware) | |
# -s [public | beta] (default: "public") | |
# -------------------------------------------------------------------------------------- | |
# Concept2 Utility uses basic auth to get the list of latest firmwares | |
# to find the token use e.g. https://mitmproxy.org/ or ProxyMan and run Concept2 Utility | |
# look for request to https://tech.concept2.com/api/firmware/latest | |
# you can store the token in .env or put it in this script | |
# -------------------------------------------------------------------------------------- | |
[[ -f ".env" ]] && source .env | |
[[ -z $TOKEN ]] && TOKEN="Authorization: Basic Y...U=" # <<< CHANGE HERE OR IN .env FILE | |
# -------------------------------------------------------------------------------------- | |
UNZIP="/usr/local/bin/7z" | |
JQ="/usr/local/bin/jq" | |
DESTINATION=$HOME/Downloads/Concept2/Firmware | |
STATUS="public" | |
# parse the parameters | |
while getopts ":d:s:" opt; do | |
case $opt in | |
d) DESTINATION="$OPTARG" | |
;; | |
s) STATUS="$OPTARG" | |
;; | |
:) | |
echo "Option -$OPTARG requires an argument." >&2 | |
exit 1 | |
;; | |
esac | |
done | |
# helper function to print text in green | |
log () { echo -e "\033[0;32m${*}\033[0m"; } | |
mkdir -p $DESTINATION | |
log "*all* available firmware versions + files (note: a version can have multiple files)" | |
curl -s "https://tech.concept2.com/api/firmware/latest" -H "$TOKEN" | $JQ -r '.data | sort_by(.release_date) | .[] | [.status, .machine, .release_date, .short_description, .files[].name] | @tsv' | |
echo | |
read -p "Do you want to download the ${STATUS} files to ${DESTINATION}? " -n 1 -r | |
echo | |
# if not: exit | |
[[ ! $REPLY =~ ^[Yy]$ ]] && exit 0 | |
# create comma separated string of the filenames | |
FILES=$(curl -s "https://tech.concept2.com/api/firmware/latest" -H "$TOKEN" | $JQ -r ".data | map(select(.status == \"$STATUS\")) | map(.files[].name) | join(\",\")") | |
BASEURL=https://firmware.concept2.com/files | |
# get those files (and keep original creation timestamp) | |
log "downloading the ${STATUS} firmware files to ${DESTINATION}" | |
(cd $DESTINATION && curl -s -O -R "$BASEURL/{$FILES}") | |
# unzip them | |
log "unzipping the files in ${DESTINATION}" | |
(cd $DESTINATION && $UNZIP e -y "*.7z" > /dev/null) | |
log "these firmwares are available:" | |
(cd $DESTINATION && ls -trl *.7z) | |
echo | |
log "make sure these files end up in folder 'Concept2/Firmware' on your USB stick" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment