Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[devmon] exec on remove does not provide any information on the label #67

Open
hschwane opened this issue Feb 4, 2016 · 2 comments
Open
Labels
Milestone

Comments

@hschwane
Copy link

hschwane commented Feb 4, 2016

I wrote a script that get's mount point and label as parameters and creates a symlink to all musik files on the usb drive in a subfolder in my mpd musik directory, named after the label of the drive. It is executed with devmons exec on drive feature and everything works fine.
Now I want to delete all the symlinks again when the stick is removed, but when I have devmon start a script with exec on remove it does not provide a value for %l. Using on unmount is not an option because I am on a headless machine and most of the time usb drives will not be unmounted before they are removed.

Is there any option or workaround to get the result I am looking for?

@IgnorantGuru
Copy link
Owner

devmon doesn't cache the device info, it just reads it via libudev (via udevil or udisks) and reports it in real time. So after the device is removed, there is no device label to be read. udev only reports what device was removed.

To make it work this way, one could edit the devmon script so that it stores volume labels in an array, such that when a device is removed it can lookup the corresponding label.

Another possibility would be for your exec-on-drive command to read and save the volume label to a temp file with a name corresponding to the device name. Then when the device is removed, your exec-on-remove command could read the most recent label corresponding to that device from that file.

You could also include the volume label and device name in the name of the symlinks you create, so your script can remove them by device name. For example, name the symlink "sdd1-My Label", or "My Label-dev-sdd1". Then you could delete "sdd1-" or "-dev-sdd1" when you see sdd1 removed.

I'll leave this open as a request, though this is a fairly specialized use so is unlikely to be implemented in devmon.

@IgnorantGuru IgnorantGuru added this to the limbo milestone Feb 5, 2016
@hschwane
Copy link
Author

Thanks for the Info. I don't think that devmon should save this information on his own, because that would generate overhead which is unnecessary for most people. A notice in the documentation however, that mount point and label are not available for exec-on-remove calls would have saved me some debugging time ;)

I used A file now to store the label and device name and look it up later. Here is the code I used in case someone else trying to do something similar ands up on this page:

In the onMount script:

# put name and label in a file to look up later 
file=/tmp/usbmountlabels.tmp
echo $name >> $file
echo $label >> $file

in the onRemove script:

#find the label in the temp file and delete them there
file="/tmp/usbmountlabels.tmp"
found=false
while read -r line
do
    if [ $found = true ]
    then
        label="$line"
        found=false
    elif [ "$line" = "$name" ]
    then
        found=true
    else
        echo "$line"
    fi
done < "$file" > "/tmp/o.tmp"
mv "/tmp/o.tmp" "$file"

This worked for me, but I only tested with one flash drive, so use at own risk.

@IgnorantGuru IgnorantGuru modified the milestones: 0.4.5, limbo Feb 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants