udiskie --event-hook poorly documented and severely misbehaves with shell scripts
Background: I wanted udiskie to create a symlink to the drive when it's mounted, and remove said link once it's unmounted. Should be simple enough, right? Unfortunately not.
There are no examples or documentation on how to include event hooks in the config file (moreover, there seems to be some confusion online on whether these are called event_hook or simply hook). Surely there should be a way to hook specific commands to specific events, but if it exists, I couldn't find it.
I fell back on trying to to use the --event-hook arg directly, and trying to squeeze everything as a shell command. Apparently all udiskie does is call exec on whatever's provided there, so I've written a quick script to do what I want:
$!/bin/bash
# $1 is {event}
# $2 is {mount_path}
# $3 is {id_label}
if [[ $1 -eq device_mounted ]]
then
ln -sf "$2" "${HOME}/$3"
elif [[ $1 -eq device_unmounted ]]
then
rm -f "${HOME}/$3}"
fi
I then invoked udiskie with:
udiskie --no-notify --event-hook "/path/to/create-links.sh {event} {mount_path} {id_label}"
But it didn't work. For whatever reason, udiskie apparently receives a SIGSTOP (or SIGTSTP?) whenever an event happens (????), then followed by all sorts of terminal shenanigans and weird behavior (going nonresponsive, calling exit multiple time, ctrl+C not working, before randomly exiting the shell entirely).
I tried bypassing that by maybe starting a separate shell, so --event-hook "/bin/bash -c /path/to/create-links.sh {event} {mount_path} {id_label}, and still no luck. Same freaky behavior.
What actually eventually worked is to replace the shell script with a compiled C program that does just that. Been working perfectly ever since.
Problem is... Why did I have to go through all that? Something as simple as some
--exec-on-connected
--exec-on-mount
--exec-on-umount
...
options would have done just fine. Then I could just directly input my ln and rm commands.
If something like that does exist, for the life of me I couldn't find any references to it, not in the example config, or the manpage, or searching online. AI chatbots gave me "solutions" that they seem to be hallucinating.