#!/bin/bash # process for getting firmware (at least for gen3) # 1. get the app id (e.g. MiniPMG3) from /rpc/Shelly.GetDeviceInfo on the device # 2. load the json firmware list from https://updates.shelly.cloud/update/{APP} # 3. download the firmware from the url for the desired channel if ! command -v curl >/dev/null 2>&1; then echo "curl not found; please install curl" >&2 exit 1 fi if ! command -v jq >/dev/null 2>&1; then echo "jq not found; please install jq" >&2 exit 1 fi app=$1 if [ -z "${app}" ]; then echo "usage: $0 []" >&2 exit 1 fi appinfo=$(curl --insecure --fail --no-progress-meter "https://updates.shelly.cloud/update/${app}") if [ $? != 0 ]; then exit 1 fi channel=$2 if [ -z "${channel}" ]; then # No channel specified, list available channels echo ${appinfo} | jq '(["channel", "version"] | (., map(length*"-"))), (. | with_entries( select(.value | type == "object" and has("url") )) | keys[] as $k | [ ($k), (.[$k].version) ]) | @tsv' -r exit 0 fi # get url and version for chosen channel url=`echo ${appinfo} | jq ".${channel}.url" -r` if [ -z "${url}" ] || [ "${url}" = "null" ]; then echo "channel ${channel} doesn't exist or no url found" >&2 exit 1 fi version=`echo ${appinfo} | jq ".${channel}.version" -r` if [ -z "${version}" ] || [ "${version}" = "null" ]; then echo "channel ${channel} doesn't exist or no version found" >&2 exit 1 fi declare -l app_lowercase="${app}" filename="shelly-${app_lowercase}-${version}.zip" curl --insecure -o ${filename} ${url} echo "${filename}"