After thinking about BusKill product that triggers a command once the USB cord disconnects, I have been thinking at a simple alternative.
BusKill official project website
When using a laptop connected to power most of the time, you may want it to power off once it gets disconnected, this can be really useful if you use it in a public area like a bar or a train. The idea is to protect the laptop if it gets stolen while in use and unlocked.
Here is how to proceed on Linux, using a trigger on an udev rule looking for a change in the power_supply subsystem.
For OpenBSD users, it is possible to use apmd as I explained in this article:
=> Rarely known OpenBSD features: apmd daemon hooks
In the example, the script will just power off the machine, it is up to you to do whatever you want like destroy the LUKS master key or trigger the coffee machine :D
Create a file /etc/udev/rules.d/disconnect.rules , you can name it how you want as long as it ends with .rules :
SUBSYSTEM=="power_supply", ENV{POWER_SUPPLY_ONLINE}=="0", ENV{POWER_SUPPLY_TYPE}=="Mains", RUN+="/usr/local/bin/power_supply_off"
Create a file /usr/local/bin/power_supply_off that will be executed when you unplug the laptop:
... continue reading