You are not logged in.

#1 2010-04-25 19:54:10

some-guy94
Member
Registered: 2009-08-15
Posts: 360

udvm: A simple udisks-based script that automounts drives

I know this is not the best code in the world, but I thought someone else might want it.

udvm automounts drives using udisks for people like me who like thunar but want to get rid of HAL.
Run it as a user.

#!/bin/bash
# UDisks log
ulog=$(mktemp -u /tmp/udvm.fifo.XXXXXX)
mkfifo "${ulog}"
trap "rm -f ${ulog}" EXIT SIGINT SIGTERM

# Start monitoring
(udisks --monitor >"${ulog}") &
udisks_pid=$!

while ps ${udisks_pid} &>/dev/null && [[ -e "${ulog}" ]]; do
    devices=()
    read -t 2 output < "${ulog}"
    devices=($(echo "${output}"| grep '^added:' | sed s:.*/::g))

    # Mount all 'real' devices
    for ((i=0; i < ${#devices[@]}; i++)); do
        if [[ $(udisks --show-info "/dev/${devices[i]}"                         \
                | sed -n 's/ *usage: *//p') == "filesystem" ]]; then
            udisks --mount "/dev/${devices[i]}" >/dev/null &&               \
            echo "mounted: /dev/${devices[i]}"
        fi
    done
done
kill ${udisks_pid}
exit

Offline

#2 2010-04-26 12:16:15

JohannesSM64
Member
From: Norway
Registered: 2009-10-11
Posts: 623
Website

Re: udvm: A simple udisks-based script that automounts drives

Is it better than the first rule here:
http://wiki.archlinux.org/index.php/Udev

Offline

#3 2010-04-26 20:38:48

some-guy94
Member
Registered: 2009-08-15
Posts: 360

Re: udvm: A simple udisks-based script that automounts drives

It might work similar to the same as the second rule, but not the first.

This needs to be run as a separate daemon, so if the rule works fine for you, stick with it. I made this because I have other users that use gnome, so they will have the drives being mounted twice if they are logged in.

Offline

Board footer

Powered by FluxBB