Last active
January 8, 2026 05:16
-
-
Save DavesCodeMusings/5c5ba8680d85d9da7cd6c119647bb137 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #! /bin/sh | |
| # When you're not using systemd on your Raspberry Pi, you | |
| # can still enjoy GPIO push-button shutdown. | |
| # Run this as: | |
| # gpio_pwr_btn.sh & | |
| # It will sit in the background and wait for GPIO to go low. | |
| # When it does, it will issue the shutdown command. | |
| GPIO=GPIO26 | |
| SHUTDOWN_CMD=halt | |
| PATH=/usr/bin:/bin:/sbin | |
| PULLED_UP_STATE=$(gpioget --bias pull-up --numeric $GPIO) | |
| if [ $PULLED_UP_STATE -ne 1 ]; then | |
| echo "GPIO state is: $PULLED_UP_STATE. Expecting 1." | |
| echo "Is something else using $GPIO?" | |
| echo "Can't configure as shutdown button." | |
| else | |
| gpiomon --utc --bias pull-up --edges falling --num-events 1 --quiet $GPIO | |
| # Will pause here until GPIO goes low. | |
| if [ $? -ne 0 ]; then | |
| echo "There was an error monitoring $GPIO. Aborting." | |
| exit 1 | |
| fi | |
| echo "GPIO shutdown request: $GPIO" | wall | |
| $SHUTDOWN_CMD | |
| fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment