So, what if you need to determine EXACTLY which sort of Raspberry Pi you are working with?
Perhaps you are running an ansible playbook that is making a network map in order to document which devices are located where. Of course, there are many ways to accomplish this, but I like simplicity and this script gets the job done for me (though I might gather a bit more data than this particular script outputs). Yes, it’s possible to do this locally with an ansible gather facts, but I haven’t gotten around to that part yet (I’m currently working on another issue and, since time is a valuable commodity, I chose this path.) As with everything, I’m always open to suggestions for improvement.
Here’s a little bash script and data file that ansible (or what have you) can push to the device that will output specifically defined output data (see code snippet).
You can find the script and the data file on my github open repository:
RasPi_Hardware_Mod_Rev_codes.sh REQUIRES: RasPi_Hardware_Mod_Rev_codes.data
#BashNugget
dataFile='RasPi_Hardware_Mod_Rev_codes.data' revString=`grep $( cat /proc/cpuinfo | grep Revision | awk '{ print $3 }' | tr "[a-z]" "[A-Z]" ) "$dataFile"` [[ ! $revString = '' ]] && echo 'RasPi Type Found: ' || { echo 'RasPi Type not found: EXITING' && exit; } raspiType=`echo "$revString" | cut -d ':' -f1` raspiMem=`echo "$revString" | cut -d ':' -f2` echo 'RasPi Type: '$raspiType echo 'RasPi Mem: '$raspiMem