Advertisement
Hisma

Delayed Shutdown Script

Dec 23rd, 2018
4,626
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.01 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. # Define ignition gpio
  4. IGN_PIN=23
  5.  
  6. # predefine gpio state (up = high)
  7. sudo /usr/bin/gpio -g mode $IGN_PIN up
  8.  
  9. while true; do
  10.     if [ $IGN_PIN -ne 0 ]; then
  11.         IGN_GPIO=`gpio -g read $IGN_PIN`
  12.         if [ $IGN_GPIO -ne 1 ] ; then
  13.             if [ ! -f /tmp/ignition_on ]; then
  14.                 touch /tmp/ignition_on
  15.                 /sbin/shutdown -c && echo 0 > /sys/class/backlight/rpi_backlight/bl_power # turn the pi screen back on
  16.                 /bin/echo -e 'connect XX:XX:XX:XX:XX:XX \n quit \n' | bluetoothctl # reconnect to bt. Modify to match your phone's mac ID
  17.                
  18.             fi
  19.         else
  20.             if [ -f /tmp/ignition_on ]; then
  21.                 rm /tmp/ignition_on
  22.                 /sbin/shutdown --poweroff 58 && echo 58 > /sys/class/backlight/rpi_backlight/bl_power # turn the pi screen off
  23.                 /bin/echo -e 'remove XX:XX:XX:XX:XX:XX \n quit \n' | bluetoothctl # disconnect bt. Modify to match your phone's mac ID
  24.             fi
  25.         fi
  26.     fi
  27.     sleep 1
  28. done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement