FWIW, to parse the /etc/version.txt file (mostly) correctly:
Code:
# Get the FW version
fw_build_maj="$(awk '/Version:/ { print $NF }' /etc/version.txt | awk -F- '{ print $NF }')"
fw_build_min="$(awk '/Version:/ { print $NF }' /etc/version.txt | awk -F- '{ print $1 }')"
# Legacy major versions used to have a leading zero, which is stripped from the complete build number. Except on really ancient builds, that (or an extra) 0 is always used as a separator between maj and min...
fw_build_maj_pp="${fw_build_maj#0}"
# That only leaves some weird diags build that handle this stuff in potentially even weirder ways to take care of...
if [ "${fw_build_maj}" -eq "${fw_build_min}" ] ; then
# Weird diags builds... (5.0.0)
fw_build="${fw_build_maj_pp}0???"
else
# Most common instance... maj#6 + 0 + min#3 or maj#5 + 0 + min#3 (potentially with a leading 0 stripped from maj#5)
if [ ${#fw_build_min} -eq 3 ] ; then
fw_build="${fw_build_maj_pp}0${fw_build_min}"
else
# Truly ancient builds... For instance, 2.5.6, which is maj#5 + min#4 (with a leading 0 stripped from maj#5)
fw_build="${fw_build_maj_pp}${fw_build_min}"
fi
fi
(Snippet from the device_id script in the Helper extension).