Skip to content

Commit

Permalink
Move shell raspberry pi check into setup
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreWohnsland committed Aug 27, 2024
1 parent 3e9c25d commit f792118
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 36 deletions.
14 changes: 12 additions & 2 deletions scripts/setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@
# Options:
# dashboard: set up dashboard, otherwise will set up CocktailBerry

is_raspberry_pi() {
if grep -q "Raspberry Pi" /proc/device-tree/model 2>/dev/null; then
return 0
else
return 1
fi
}

echo "Installing updates, this may take a while..."
sudo apt update && sudo sudo apt -y full-upgrade

Expand Down Expand Up @@ -83,7 +91,7 @@ else
pip install requests pyyaml GitPython typer pyfiglet qtawesome piicodev pyqtspinner pillow psutil distro
# try to install mfrc522, this will probably fail on non raspberry pi devices
if is_raspberry_pi; then
pip install mfrc522 || echo "ERROR: Could not install mfrc522, are you on a Raspberry Pi?"
pip install mfrc522 rpi_ws281x || echo "ERROR: Could not install mfrc522, are you on a Raspberry Pi?"
fi
# try to install python-periphery, so other devices may also use the gpio
pip install python-periphery || echo "ERROR: Could not install python-periphery, if you are on a RPi, this is not needed"
Expand All @@ -94,6 +102,8 @@ else
echo "qtsass is needed if you want to customize the CocktailBerry GUI and use your own colors"
pip install qtsass
# on none RPi devices, we need to set control to the GPIOs, and set user to sudoers
./setup_non_rpi.sh
if ! is_raspberry_pi; then
./setup_non_rpi.sh
fi
fi
echo "Done with the setup"
58 changes: 24 additions & 34 deletions scripts/setup_non_rpi.sh
Original file line number Diff line number Diff line change
@@ -1,42 +1,32 @@
#!/bin/bash

is_raspberry_pi() {
if grep -q "Raspberry Pi" /proc/device-tree/model 2>/dev/null; then
return 0
else
return 1
fi
}

# Check if the script is running on a non-Raspberry Pi device
if ! is_raspberry_pi; then
echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/99_$(whoami)_nopasswd" >/dev/null
sudo chmod 0440 "/etc/sudoers.d/99_$(whoami)_nopasswd"
if ! getent group gpio >/dev/null; then
echo "Creating gpio group"
sudo groupadd gpio
fi
echo "Setting up GPIOs for non Raspberry Pi devices"
sudo usermod -aG gpio "$USER"
echo "$(whoami) ALL=(ALL) NOPASSWD: ALL" | sudo tee "/etc/sudoers.d/99_$(whoami)_nopasswd" >/dev/null
sudo chmod 0440 "/etc/sudoers.d/99_$(whoami)_nopasswd"
if ! getent group gpio >/dev/null; then
echo "Creating gpio group"
sudo groupadd gpio
fi
echo "Setting up GPIOs for non Raspberry Pi devices"
sudo usermod -aG gpio "$USER"

# Create the setup_gpio_permissions.sh script
sudo cp ./scripts/setup_gpio_permissions.sh /usr/local/bin/setup_gpio_permissions.sh
sudo cp ./scripts/setup_gpio_permissions.service /etc/systemd/system/setup_gpio_permissions.service
# Create the setup_gpio_permissions.sh script
sudo cp ./scripts/setup_gpio_permissions.sh /usr/local/bin/setup_gpio_permissions.sh
sudo cp ./scripts/setup_gpio_permissions.service /etc/systemd/system/setup_gpio_permissions.service

# Make the script executable
sudo chmod +x /usr/local/bin/setup_gpio_permissions.sh
sudo systemctl enable setup_gpio_permissions.service
sudo systemctl start setup_gpio_permissions.service
# Make the script executable
sudo chmod +x /usr/local/bin/setup_gpio_permissions.sh
sudo systemctl enable setup_gpio_permissions.service
sudo systemctl start setup_gpio_permissions.service

# Execute the script to apply permissions immediately
sudo /usr/local/bin/setup_gpio_permissions.sh
# Execute the script to apply permissions immediately
sudo /usr/local/bin/setup_gpio_permissions.sh

# set the rules to enable gpio
# only both in combination seem to work
sudo apt install python3-pip libgpiod2
sudo cp ./scripts/99-gpio.rules /etc/udev/rules.d/99-gpio.rules
sudo udevadm control --reload-rules
sudo udevadm trigger
# set the rules to enable gpio
# only both in combination seem to work
sudo apt install python3-pip libgpiod2
sudo cp ./scripts/99-gpio.rules /etc/udev/rules.d/99-gpio.rules
sudo udevadm control --reload-rules
sudo udevadm trigger

echo "Please reboot your device now, to apply the changes"
fi
echo "Please reboot your device now, to apply the changes"

0 comments on commit f792118

Please sign in to comment.