Skip to content

Instantly share code, notes, and snippets.

@nbuchwitz
Last active July 11, 2023 14:32
Show Gist options
  • Save nbuchwitz/5aa2aa1a91244ac1fec0d8c11afec322 to your computer and use it in GitHub Desktop.
Save nbuchwitz/5aa2aa1a91244ac1fec0d8c11afec322 to your computer and use it in GitHub Desktop.
#!/bin/bash
rpi_revision_code() {
# see https://www.raspberrypi.com/documentation/computers/raspberry-pi.html#new-style-revision-codes
code=$(grep Revision /proc/cpuinfo | cut -f 2 -d \: | xargs)
echo $((16#${code}))
}
rpi_type() {
code=$(rpi_revision_code)
mask=4080
echo $(((code & mask) >> 4))
}
is_cm4() {
test $(rpi_type) -eq 20
}
is_cm4_with_wifi() {
is_cm4 && grep -q 'DRIVER=brcmfmac' /sys/class/ieee80211/phy0/device/uevent 2>/dev/null
}
if is_cm4; then
echo "I'm a RPi CM4"
fi
if is_cm4_with_wifi; then
echo "I'm a RPi CM4 with WiFi"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment