Raspberry Pi Shutdown Switch – Safely Turning off the Pi
http://www.3cc.org/blog/2013/01/raspberry-pi-shutdown-switch-safely-turning-off-the-pi/
I followed the project above but set pin 17 to be internally pulled up. Then connect the wires like the above project but leave out any resistors and add the following python script in /etc/rc.local
python shutdown_button.py
shutdown_button.py :
import RPi.GPIO as GPIO
import time
import os
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN,pull_up_down=GPIO.PUD_UP)
while True:
print GPIO.input(17)
if(GPIO.input(17) == False):
os.system("sudo shutdown -h now")
break
time.sleep(1)