There is likely a couple of ways to do that.
There is a dtoverlay for shut down, dtoverlay=gpio-shutdown
By default its tied to GPIO 3, grounding GPIO 3 will have Raspbian do a proper shut down. It can be mapped to another pin though. If you wanted it mapped to Button X it would be as follows
I don’t know how you set it for a long button press though?
The Pirate audio pinout is here, which shows what GPIO the buttons are wired too.
In python you can run
os.system("sudo shutdown now -P") and Raspbain will do a shutdown. You’d have to code up a file to watch the button for a long press. And have that file run on bootup with crontab etc. I do it this way on a couple of my headless setups, I just add the shutdown to my already running python file. I do it via GPIO commands. GPIO.add_event_detect(5, GPIO.FALLING, callback = Shutdown, bouncetime = 2000)
. There is more to it than that one line but that’s the gist of how it goes.