udiskie icon indicating copy to clipboard operation
udiskie copied to clipboard

Run command after automount

Open coldfix opened this issue 1 year ago • 3 comments

But I'm trying to make it do things outside its design: when a USB stick containing a filesystem with specific UUIDs is inserted, I want it to automount, then autorun a specific command ("/usr/local/bin/make-backup" :-). I've got a patch that adds that functionality, but it's a bit invasive, so I'm not sure if you'd want it.

I should also see if I can have it autorun a command when a disk is inserted into the optical drive. Ideally it would run different commands based on the medium type: blank: run make-backup audio cd: extract all the tracks and convert them to .mp3 dvd: run vlc cd-rom: mount the filesystem etc. But that might require lots of changes to the udiskie config syntax.

	-- JF

Originally posted by @dajt1725 in https://github.com/coldfix/udiskie/issues/284#issuecomment-2061718611

coldfix avatar Apr 17 '24 18:04 coldfix

Let's continue this discussion in a separate issue.

What you describe sounds similar to what --event_hook provides. Does that not solve your issue?

I've got a patch that adds that functionality, but it's a bit invasive, so I'm not sure if you'd want it.

If you already did the work, feel free to submit it as a PR. If I don't like it, I can reject or propose improvements. If you haven't put in the work yet, might be good to coordinate.

coldfix avatar Apr 17 '24 18:04 coldfix

Hi @dajt1725, I pulled your comment over into this new issue. Let me know if this is something that you want to follow up on, otherwise, we could just close it.

coldfix avatar Apr 24 '24 17:04 coldfix

On Wed, Apr 24, 2024 at 10:59:41AM -0700, Thomas G. wrote:

Hi @dajt1725, I pulled your comment over into this new issue. Let me know if this is something that you want to follow up on, otherwise, we could just close it.

I have a branch with working (in testing, at least) autorun here, but it needs a bit of cleanup/splitting into component pieces before it's merged. At the moment the branch contains: 1: a fix for event_hook to work on device_changed and job_failed events. 2: alphabetically sorting lists of options and attributes because I was finding the unsorted lists hard to read. 3: New media-related matching attributes (so I can autorun different commands on different types of media. 4: The actual autorun code, which needs cleanup and optimization. 5: Unrelated changes that should be reverted.

The functional difference between autorun and event-hook is that there is a single event hook that is called for all events on all devices. Autorun specifies "when this event occurs on a device that matches these attributes, run this command". So while it would be possible to write an event hook command to perform like autorun, it requires the event hook to know a lot about device UUIDs, etc, which I would rather have stay internal to udiskie.

To give you an idea of what it looks like, here's my config file. Note that most of the scripts are stubs, but they show off the idea.

 -- JF

dajt1725 avatar Apr 25 '24 14:04 dajt1725