Skip to content

Commit

Permalink
detect raspi better now that 64bit os is here
Browse files Browse the repository at this point in the history
  • Loading branch information
zoff99 committed Jan 8, 2024
1 parent 579def0 commit 48769a2
Showing 1 changed file with 58 additions and 2 deletions.
60 changes: 58 additions & 2 deletions toxblinkenwall/scripts/set_os_dir.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,66 @@
#! /bin/bash


is_pitwo() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]04[0-9a-fA-F]$" /proc/cpuinfo
return $?
}

is_pizero() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]0[9cC][0-9a-fA-F]$" /proc/cpuinfo
return $?
}

# ...while tests for Pi 3 and 4 just test processor type, so will also find CM3, CM4, Zero 2 etc.

is_pithree() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]2[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
return $?
}

is_pifour() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]3[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
return $?
}

is_pifive() {
grep -q "^Revision\s*:\s*[ 123][0-9a-fA-F][0-9a-fA-F]4[0-9a-fA-F][0-9a-fA-F][0-9a-fA-F]$" /proc/cpuinfo
return $?
}

is_any_pi() {
if is_pitwo; then
echo 2
elif is_pithree; then
echo 3
elif is_pifour; then
echo 4
elif is_pifive; then
echo 5
elif is_pizero; then
echo 0
else
echo -1
fi
}

is_any_pi=$(is_any_pi)

if [[ "$OSTYPE" == "linux-gnu" ]]; then
if [[ "$is_any_pi""x" == "-1x" ]]; then
_OS_DIR_="/linux/"
else
# default RPI dir
_OS_DIR_="/raspi/"
# check for other models of the RPI
pi_model=$(tr -d '\0' </proc/device-tree/model)
echo $pi_model|grep 'Raspberry Pi Zero W' >/dev/null 2> /dev/null
pizero_w=$?
if [ $pizero_w == 0 ]; then
_OS_DIR_="/rpi_zerow/"
fi
fi
elif [[ "$OSTYPE" == "linux-gnueabihf" ]]; then

# default RPI dir
_OS_DIR_="/raspi/"
# check for other models of the RPI
Expand All @@ -13,7 +70,6 @@ elif [[ "$OSTYPE" == "linux-gnueabihf" ]]; then
if [ $pizero_w == 0 ]; then
_OS_DIR_="/rpi_zerow/"
fi

elif [[ "$OSTYPE" == "darwin"* ]]; then
# Mac OSX
_OS_DIR_="/osx/"
Expand Down

0 comments on commit 48769a2

Please sign in to comment.