Make sure you have a raspberry pi. (This script is tested with the raspbian dist on a series 3 model B+)
DISCLAIMER: Look at the script for the PINS and PORTS used. You can change it in the section Configuration if you like.
-
Download the
raspberry-pi-power-button-script.pyscript, name something likeshutdown.pyand put it somewhere publicly available. -
Make script executable with
chmod +x <absolute_path_to>/shutdown.py.