Ferk / udev-media-automount

A simple automount mechanism using udev rules
Other
121 stars 59 forks source link

eject without requiring password #28

Open dhjelmar opened 6 months ago

dhjelmar commented 6 months ago

Requested Capability

An option to eject any auto-mounted flashdrive without requiring a password would be helpful. Possibly there's a configuration file I could add to /etc/media-automount.d? It isn't clear to me though how to do that.

Supporting Detail

A password is required to eject using udev-media-automount. I am running PeppermintOS and successfully auto-mounted an exfat formatted flash drive.

No password is required to unmount and eject if I mount the same exfat drive using the following:

mount () { 
    # Usage example: mount sda1
    udisksctl mount --block-device /dev/$1
}

The same behavior is observed (i.e., requiring a password to unmount if mounted with automount, and not requiring a password to unmount if mounted with the above function) regardless of whether I use a file manager or the following command to eject:

unmount(){
    # Function that unmounts, if needed, then powers off a USB drive
    # Usage example: unmount sda1

    # # original simple unmount and power off function
    # udisksctl unmount -b /dev/$1 && udisksctl power-off -b /dev/$1

    disk=`lsblk | grep $1`                    # find target disk
    mounted="$(echo $disk | cut -d' ' -f7)"   # parse to find mountpoint (6th column)
    echo "disk = " $disk
    echo "mounted = " $mounted
    if [ -z "$mounted" ]
    then
        # $var is empty so just power off drive
    echo "Power off drive $1"
    udisksctl power-off -b /dev/$1
    else
        # $var is not empty so unmount and power off drive
    echo "Unmount and power off drive $1"
        udisksctl unmount -b /dev/$1 && udisksctl power-off -b /dev/$1
    fi
}

Aside

Your utility has been really helpful. I had been using the above commands to mount and unmount/eject, but I had not yet figured out how to mount a Yubikey. I found your script while researching udev rules, and it worked great.