2015-08-10 20:49:46 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-04-19 07:10:28 +00:00
|
|
|
#| Jacob Alexander 2014
|
|
|
|
#| Arg List
|
|
|
|
#| 1 - size binary (e.g. avr-size)
|
2014-08-15 17:42:12 +00:00
|
|
|
#| 2 - measurement type (flash or ram)
|
2014-04-19 07:10:28 +00:00
|
|
|
#| 3 - binary file (e.g. kiibohd.hex)
|
|
|
|
#| 4 - total available (flash/ram) in bytes
|
2014-08-15 17:42:12 +00:00
|
|
|
#| 5 - flash/ram text
|
2014-04-19 07:10:28 +00:00
|
|
|
|
|
|
|
|
2014-08-15 17:42:12 +00:00
|
|
|
case "$2" in
|
|
|
|
"flash")
|
|
|
|
USED=$("$1" "$3" | tail -n-1 | awk '{ print $1+$2 }')
|
|
|
|
;;
|
|
|
|
"ram")
|
|
|
|
USED=$("$1" "$3" | tail -n-1 | awk '{ print $2+$3 }')
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "INVALID Measurement type: $2"
|
|
|
|
exit 1
|
|
|
|
esac
|
|
|
|
|
2014-04-19 07:10:28 +00:00
|
|
|
|
|
|
|
# Calculates the total flash/ram used
|
|
|
|
TOTAL="$4"
|
|
|
|
PERCENTAGE=$((USED * 100 / TOTAL))
|
|
|
|
|
|
|
|
# Size Colours
|
|
|
|
# Red/Flashing - Almost full
|
|
|
|
if (( PERCENTAGE > 95 )); then
|
|
|
|
COLOR="\t\033[1;5;31m"
|
|
|
|
# Red - Getting full
|
|
|
|
elif (( PERCENTAGE > 90 )); then
|
|
|
|
COLOR="\t\033[1;31m"
|
|
|
|
|
|
|
|
# Yellow - Starting to fill up
|
|
|
|
elif (( PERCENTAGE > 50 )); then
|
|
|
|
COLOR="\t\033[1;33m"
|
|
|
|
|
|
|
|
# Green - Lots of room
|
|
|
|
else
|
|
|
|
COLOR="\t\033[1;32m"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Displays Results
|
|
|
|
NAME="$5"
|
2014-08-15 17:42:12 +00:00
|
|
|
echo -e "\t\033[1m${NAME}\033[m: ${COLOR}${PERCENTAGE}%\033[m \t${USED}/${TOTAL}\tbytes"
|
2014-04-19 07:10:28 +00:00
|
|
|
|
|
|
|
exit 0
|
|
|
|
|