Skip to content

Instantly share code, notes, and snippets.

@gigawatts
Last active October 14, 2016 23:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save gigawatts/07b3e810acd86dafe1e3c5a465e99476 to your computer and use it in GitHub Desktop.
#!/bin/bash
## Extract version from MPM hex or img update file
## Run with no arguments for usage
function hex2string () {
I=0
while [ $I -lt ${#1} ];
do
echo -en "\x"${1:$I:2}
let "I += 2"
done
}
if [ $# -lt 1 ]; then
echo "Extracts the version string from a given .hex or .img MPM update file"
echo "Usage: ${0} <hex file>"
exit 1
fi
if [ ! -f "${1}" ]; then
echo "${0}: '${1}': No such file"
exit 1
fi
version=$(strings "${1}" | grep -E '(v[0-9]+(\.[0-9]+){1,2}(-[0-9]+-g[0-9a-f]{5}+)?(-dirty)?)|(g[0-9a-f]{5}(-dirty)?)')
if [ -z "${version}" ]; then
#ver2=$(hex2string "`tail -6 ${1}|tr -d :|head -2`" | strings | grep -E '(v[0-9]+(\.[0-9]+){1,2}(-[0-9]+-g[0-9a-f]{5}+)?(-dirty)?)|(g[0-9a-f]{5}(-dirty)?)' )
ver2=$(hex2string "`tail -6 ${1}|tr -d :`" | strings|head -2)
if [ -z "${ver2}" ]; then
echo "Version string not found" >&2
else
echo "${ver2}"
fi
else
echo "${version}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment