Last active
April 16, 2023 21:06
-
-
Save hhromic/ddadf70f80aae7b861e4d593ac84cf52 to your computer and use it in GitHub Desktop.
Show information about IKEA Tradfri devices firmware from the official IKEA servers in Linux
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
#!/usr/bin/env bash | |
# Show information about IKEA Tradfri devices firmware from the official IKEA servers | |
# script by github.com/hhromic | |
# optional filter | |
declare -r FILTER=$1 | |
# URLs for firmware channels | |
declare -r -A CHANNEL_URLS=( | |
[CURRENT]=http://fw.ota.homesmart.ikea.net/feed/version_info.json | |
[TESTING]=http://fw.test.ota.homesmart.ikea.net/feed/version_info.json | |
) | |
# terminal color settings | |
declare -r GRN=$(tput setaf 2 2>/dev/null) | |
declare -r YLW=$(tput setaf 3 2>/dev/null) | |
declare -r MGN=$(tput setaf 5 2>/dev/null) | |
declare -r CYN=$(tput setaf 6 2>/dev/null) | |
declare -r RST=$(tput sgr0 2>/dev/null) | |
# download firmware data for all channels | |
declare -A fw_data | |
printf "Downloading firmware data, please wait ...\\n" | |
for channel in "${!CHANNEL_URLS[@]}"; do | |
fw_data+=([$channel]=$(curl -sSL "${CHANNEL_URLS[$channel]}")) || exit | |
done | |
# iterate over firmware data and report information | |
for channel in "${!fw_data[@]}"; do | |
printf "\\n--- Firmware Channel: ${GRN}%s${RST} ---\\n" "$channel" | |
while read -r fw_info; do | |
fw_binary_url=$(jq -r .fw_binary_url <<< "$fw_info") | |
fw_file_version_LSB=$(jq -r .fw_file_version_LSB <<< "$fw_info") | |
fw_file_version_MSB=$(jq -r .fw_file_version_MSB <<< "$fw_info") | |
fw_filesize=$(jq -r .fw_filesize <<< "$fw_info") | |
fw_basename=${fw_binary_url##*/} | |
fw_basename=${fw_basename%%.ota.ota.signed} | |
fw_basename=${fw_basename%%.sig.ota.signed} | |
fw_file_version=$(((fw_file_version_MSB << 16) + fw_file_version_LSB)) | |
[[ -n $FILTER ]] && ! grep -qi "$FILTER" <<< "$fw_basename" && continue | |
printf "${CYN}%s${RST} version ${YLW}0x%x${RST}, ${MGN}%d${RST} bytes\\n" \ | |
"$fw_basename" "$fw_file_version" "$fw_filesize" | |
done < <(jq -c "sort_by(.fw_binary_url)|.[]" <<< "${fw_data[$channel]}") | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment