random- collection of un-sorted bollocks |
git clone git://git.acid.vegas/random.git |
Log | Files | Refs | Archive |
deadman (911B)
1 #!/bin/sh 2 # USB Deadman's Switch - Developed by acidvegas (https://git.acid.vegas/random) 3 4 # This script will create a udev rule that will execute a payload when a USB drive is removed. 5 # udev is typically installed & running on most Linux distributions, but alwways verify. 6 7 if [ "$#" -ne 2 ]; then 8 echo "Usage: $0 <usb_path> <payload_path>" && exit 1 9 fi 10 11 USB_PATH=$1 12 PAYLOAD_PATH=$2 13 14 if [ ! -e "$USB_PATH" ]; then 15 echo "Error: USB drive at $USB_PATH not found." && exit 1 16 else if [ ! -f "$PAYLOAD_PATH" ]; then 17 echo "Error: Payload at $PAYLOAD_PATH not found." && exit 1 18 fi 19 20 LABEL=$(blkid -o value -s LABEL $USB_PATH) 21 UUID=$(blkid -o value -s UUID $USB_PATH) 22 23 echo "Deadman USB: $LABEL ($UUID)" 24 25 mkdir -p /etc/udev/rules.d/ 26 printf "ACTION==\"remove\", ENV{ID_FS_UUID}==\"$UUID\", RUN+=\"$PAYLOAD_PATH\"\n" > /etc/udev/rules.d/99-usb-removal.rules 27 28 udevadm control --reload-rules && udevadm trigger