I’ve been googling this on and off for a while. I’m certain it is possible, but I keep disappearing down rabbit holes of overly complex solutions, or those using long defunct add-ons.
I simply want to add menu entries to run arbitrary bash scripts, to save needing to ssh in to mount and dismount veracrypted volumes on external drives. Nothing fancy required, although display of a simple message dialog would be useful.
As long as you’re using systemd-based fstab mounts, I’d have thought a systemd service “unit” would do the trick (though you’ll probably need one unit file per disk).
In the /etc/fstab you’d need to associate the disk’s UUID with its mount point. See here.
Then for each mount point, create a .service file in /etc/systemd/system. I think the name can be arbitrary but it’s better to associate it with the mount point name, so I’ve called this one mnt-test.service since it’s for a mount point of /mnt/test.
osmc@osmc:~$ cat /etc/systemd/system/mnt-test.service
Description=Run script when /mnt/test is mounted
My script logit.sh just writes a message to the system journal, BTW.
Remember to enable it (sudo systemctl enable mnt-test.sh).
I can’t guarantee that it’ll work first time but it should be a step in the right direction. One caveat: if you’re using autofs, then this isn’t going to work.
Ideally I’d like to run them via a menu, but otherwise they’d need to run on connection of a usb device (with a switch statement to select the correct decryption key for the appropriate device), and on shutdown.