First time poster, not first time RasPi user.
I am trying to figure out a failsafe way to shutdown any Pi(w/ rasbian) due to the oft-sited issues with SD card corruption when the power cable is yanked out.
This issue has been addressed many times in the past, the strategies I most often see are a python script and a GPIO button, or with a separate micro-controller via UART or SPI.
I would prefer to find a way of doing so via USB because it doesn't require first installing a script(python/GPIO) or plugging something into the GPIO(UART/SPI). Likewise, if you would like to shutdown a Pi, you just plug in the USB stick(and maybe press a button on said stick)
So, would it be possible to implement something like this on some sort of USB stick?
My first thought was a USB flash drive with an autorun shell script that would run anytime it was plugged into a Pi. I am no Linux guru, but I did some digging and it seems in order for this to work, the Pi's system must first be modified to accept autorun scripts(something to do with UDEV?). This in not ideal because I would like to be able to plug it into any pi(like one with a brand new copy of rasbian) and cause a shutdown.
My next thought was to use something like an Atmega 32u4 on a USB stick to implement a shutdown, but I do not know much about USB protocols so I am not sure where to start. My most basic implementation(far from ideal), would be to use the 32u4 as a USB HID via Arduino to send the keystrokes to open a terminal and enter "sudo shutdown -h now". This might very well work fine, I will test it out when I get home, but it seems pretty janky and I'm sure there's a better way.
Would anyone be able to point me down the right path?