#!/bin/bash LED1=22 LED2=27 SHUTDOWN=3 case "$1" in start) # LED init echo "$LED1" > /sys/class/gpio/export echo "$LED2" > /sys/class/gpio/export echo out > /sys/class/gpio/gpio$LED1/direction echo 0 > /sys/class/gpio/gpio$LED1/value echo out > /sys/class/gpio/gpio$LED2/direction echo 1 > /sys/class/gpio/gpio$LED2/value #Button init echo "$SHUTDOWN" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio$SHUTDOWN/direction #This loop continuously checks if the shutdown button was pressed #It sleeps as long as that has not happened. buttonstate1=$(cat /sys/class/gpio/gpio$SHUTDOWN/value) shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value) while [ $shutdownSignal = $buttonstate1 ]; do shutdownSignal=$(cat /sys/class/gpio/gpio$SHUTDOWN/value) sleep 0.5 done shutdown -h now ;; stop) #unexport all GPIOs #echo "$SHUTDOWN" > /sys/class/gpio/unexport echo "$LED1" > /sys/class/gpio/unexport echo "$LED2" > /sys/class/gpio/unexport ;; esac exit $?