On Mon, Jul 19, 2010 at 08:46:32PM +0200, LuX wrote:
By the way, what I wanted to do when I encountered this "stupid"
problem with -f flag, if not "clever", might at least be usefull for
other people. I wanted to add to wmii some basic ability to deal with
USB pens:
- mount and open them automatically when plugged in;
- show them as buttons in the right bar, with focus or normal colors
depending on whether their file system is mounted or unmounted; - unmount/remount them by simple clicks on their buttons.
It might be that your removable device manager skvm does this job
perfectly, I don't know. The point is that skvm is not available in
the core repository of Arch Linux, the distro I'm using from now on,
and I do not use to compile programs from source. So I have found a
way to add this feature with wmii-3.9.2 just by modifying
appropriately the wmiirc file. If some people are interested, this is
available here:

skvm scares me, not least because it's ugly and I can't even figure out quite what it does. I'm not terribly fond of pmount either. I'm currently using a (heavily) modified hal-based mounting script that does the job quite nicely. Attached.

Your script does look useful though. I'll have to have a good look at it later. I tend to use the commandline or wimenu, but I think that for the purposes of your script I'd have used wmii9menu.

--
Kris Maglione

Most software today is very much like an Egyptian pyramid with
millions of bricks piled on top of each other, with no structural
integrity, but just done by brute force and thousands of slaves.
        --Alan Kay

#!/bin/dash
# vim:se ft=sh ts=4 sw=4 et tw=80 cin cino=(0,ml,\:0:
#
# Copyright (C) 2009 DaTaPaX, GPL Licensed

# halmount/halumount
#-------------
# Mounts and unmounts using hal (via dbus)
#
# More info:
#   http://people.freedesktop.org/~david/hal-spec/hal-spec.html

# ToDo
#   * Read in defaults for help display from Hal

# Version
APP_VER="0.21"

# Program name
PROG="$(basename $0)"
MOUNTNAME="halmount"
UMOUNTNAME="halumount"

mounting() { test "$PROG" != "$UMOUNTNAME"; }

# Default FS type
FSTYPE=""

# Default mount options
OPTIONS=""

# Default Destination directory
DESTDIR=""

# Default to listing devices
LIST=""

EJECT=""

usage() {
    cat <<!
HalMount/HalUMount v${APP_VER}

HalMount mounts and unmounts using hal (via dbus)

    Usage: $PROG -h|--help
           $MOUNTNAME -l
           $MOUNTNAME [-t <fstype>] [-o <options>] <device> [destdir]
           $UMOUNTNAME -l
           $UMOUNTNAME [-o <options>] <device|destdir>
    
    -h|--help           - Displays this help
    -l                  - List available devices for mounting/unmounting
    -t <fstype>         - Filesystem type (default: auto)
    -o <options>        - Mount options
    <device>            - Label, UUID or device node of device to mount (eg: 
/dev/sdb1)
    <destdir>           - Destination mount directory (under /media, default: 
<device label>)

    Examples:
    
        $MOUNTNAME /dev/sdb1
        $MOUNTNAME 'APPLE IPOD' iPod
        $UMOUNTNAME 'APPLE IPOD'
!
    exit $1
}

abort() {
    echo >&2 $2
    exit $1
}

lookup() { hal-get-property --udi "$1" --key "$2" | sed 1q; }
search() { hal-find-by-property --key "$1" --string $2; }
send()   { dbus-send "$@" >/dev/null || abort $? "ERROR: dbus-send failed"; }
is_mounted() { test "$(lookup $1 volume.is_mounted)" = true; }

while getopts ehlo:t: opt
do
    case $opt in
    e)
        EJECT=1;;
    h)
        usage 0;;
    l)
        LIST=1
        break;;
    o)
        OPTIONS="$OPTARG";;
    t)
        FSTYPE="$OPTARG";;
    '?')
        usage 1;;
    esac
done

if mounting; then
    OPTIONS="${OPTIONS},uid=$(id -u)"
fi

shift $(($OPTIND - 1))

# If listing, no mount point or destination directory will be accepted
if [ -z "$LIST" ]; then
    DEVICE="$1"; shift

    if mounting && [ $# -gt 0 ]; then
        DESTDIR="$1"; shift
    fi
fi

if [ "$#" -ne 0 ]; then
    abort 1 "ERROR: Too many arguments"
fi

if [ -n "$LIST" ]; then
    # List devices
    search info.category volume |
    while read udi; do

        info=""
        for i in fstype uuid label; do info="$info      $(lookup $udi 
volume.$i)"; done
        dev="$(lookup $udi block.device)"

        mounted=
        case "$(lookup $udi volume.is_mounted)" in
        false)
            mounting && echo "$dev      $info";;
        true)
            mounting || echo "$dev      $(lookup $udi volume.mount_point)       
$info";;
        esac
    done

    exit 0
fi

if [ -z "$DEVICE" ]; then
    abort 2 "ERROR: No device specified"
fi

if [ ! -b "$DEVICE" ]; then
    DEVICE=$(blkid -U "$DEVICE" || blkid -L "$DEVICE")
fi

# Retrieve the UDI for this device
udi="$(search block.device "$DEVICE")"

# First, check if it's a destination dir (for unmounting)
if [ -z "$udi" ] && ! mounting; then
    # mount_point does not contain a trailing slash
    DESTDIR="${DEVICE%/}"

    udi="$(search volume.mount_point "$DESTDIR")"
fi

# No device
if [ -z "$udi" ]; then
    abort 3 "ERROR: Couldn't find device in Hal"
fi

if mounting; then
    if is_mounted $udi; then
        abort 4 "Device $DEVICE already mounted on $(lookup $udi 
volume.mount_point)"
    fi

    # NOTE: --print-reply req'd for blocking
    send --system --print-reply --dest=org.freedesktop.Hal \
         $udi \
         org.freedesktop.Hal.Device.Volume.Mount \
         string:"$DESTDIR" \
         string:"$FSTYPE" \
         array:string:"$OPTIONS"

    if [ "$DESTDIR" = "" ]; then
        echo "Mounted $DEVICE to $(lookup $udi volume.mount_point)"
    fi
else
    # Unmounting
    method=org.freedesktop.Hal.Device.Volume.Unmount
    if [ -n "$EJECT" ]; then
        method=org.freedesktop.Hal.Device.Volume.Eject
    elif ! is_mounted $udi; then
        abort 4 "Device $DEVICE is not currently mounted"
    fi

    # NOTE: --print-reply req'd for blocking
    send --system --print-reply --dest=org.freedesktop.Hal \
         $udi \
         $method \
         array:string:"$OPTIONS"
fi

Reply via email to