[Usbmount-commit] r20 - in trunk/usbmount: . debian
Martin Dickopp
mdickopp-guest@costa.debian.org
Tue, 12 Apr 2005 15:50:27 +0000
Author: mdickopp-guest
Date: 2005-04-12 15:50:26 +0000 (Tue, 12 Apr 2005)
New Revision: 20
Added:
trunk/usbmount/00_create_model_symlink
trunk/usbmount/00_remove_model_symlink
trunk/usbmount/debian/postrm
Modified:
trunk/usbmount/README
trunk/usbmount/debian/changelog
trunk/usbmount/debian/install
trunk/usbmount/debian/preinst
trunk/usbmount/debian/prerm
trunk/usbmount/usbmount
trunk/usbmount/usbmount.dev
Log:
* The model name symlink now includes the vendor if known.
* Run hook scripts when a device or partition is mounted or unmounted.
Describe how to use this feature in the README file.
* Moved /etc/usbmount.conf to /etc/usbmount/usbmount.conf.
* Moved deletion of mount points in /media from prerm to postrm. Delete
them not only when the package is removed, but also when installing is
aborted.
* Moved creation and deletion of model name symlinks to hook scripts.
* New package (version 0.0.10).
Added: trunk/usbmount/00_create_model_symlink
===================================================================
--- trunk/usbmount/00_create_model_symlink 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/00_create_model_symlink 2005-04-12 15:50:26 UTC (rev 20)
@@ -0,0 +1,40 @@
+#!/bin/sh
+# This script creates the model name symlink in /var/run/usbmount.
+# Copyright (C) 2005 Martin Dickopp
+#
+# This file is free software; the copyright holder gives unlimited
+# permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+#
+set -e
+
+# Replace spaces with underscores, remove special characters in vendor
+# and model name.
+UM_VENDOR=`echo "$UM_VENDOR" | sed 's/ /_/g; s/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-]//g'`
+UM_MODEL=`echo "$UM_MODEL" | sed 's/ /_/g; s/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-]//g'`
+
+# Exit if both vendor and model name are empty.
+test -n "$UM_VENDOR" || test -n "$UM_MODEL" || exit 0
+
+# Build symlink name.
+if test -n "$UM_VENDOR" && test -n "$UM_MODEL"; then
+ name="${UM_VENDOR}_$UM_MODEL"
+else
+ name="$UM_VENDOR$UM_MODEL"
+fi
+
+# Append partition number, if any, to the symlink name.
+partition=`echo "$UM_DEVICE" | sed 's/^.*[^0123456789]\([0123456789]*\)/\1/'`
+if test -n "$partition"; then
+ name="${name}_$partition"
+fi
+
+# If the symlink does not yet exist, create it.
+test -e "/var/run/usbmount/$name" || ln -sf "$UM_MOUNTPOINT" "/var/run/usbmount/$name"
+
+exit 0
Property changes on: trunk/usbmount/00_create_model_symlink
___________________________________________________________________
Name: svn:executable
+ *
Added: trunk/usbmount/00_remove_model_symlink
===================================================================
--- trunk/usbmount/00_remove_model_symlink 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/00_remove_model_symlink 2005-04-12 15:50:26 UTC (rev 20)
@@ -0,0 +1,23 @@
+#!/bin/sh
+# This script removes the model name symlink in /var/run/usbmount.
+# Copyright (C) 2005 Martin Dickopp
+#
+# This file is free software; the copyright holder gives unlimited
+# permission to copy and/or distribute it, with or without
+# modifications, as long as this notice is preserved.
+#
+# This file is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+#
+set -e
+
+ls /var/run/usbmount | while read name; do
+ if test "`readlink \"/var/run/usbmount/$name\" || :`" = "$UM_MOUNTPOINT"; then
+ rm -f "/var/run/usbmount/$name"
+ break
+ fi
+done
+
+exit 0
Property changes on: trunk/usbmount/00_remove_model_symlink
___________________________________________________________________
Name: svn:executable
+ *
Modified: trunk/usbmount/README
===================================================================
--- trunk/usbmount/README 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/README 2005-04-12 15:50:26 UTC (rev 20)
@@ -1,5 +1,5 @@
USBmount
---------
+========
The USBmount package automatically mounts USB mass storage devices
(typically USB pens) when they are plugged in, and unmounts them when
@@ -17,5 +17,33 @@
desktop environment. Users which would like an icon to appear when an
USB device is plugged in should use the pmount and hal packages instead.
-The comments in the configuration file /etc/usbmount.conf describe how
-to configure the package.
+The comments in the configuration file /etc/usbmount/usbmount.conf
+describe how to configure the package.
+
+
+Hook Scripts
+------------
+
+After a device or partition has been mounted, the command 'run-parts
+/etc/usbmount/mount.d' is executed. This runs all scripts in
+/etc/usbmount/mount.d which adhere to a certain naming convention; see
+the run-parts manual page for details.
+
+The following environment variables are available to the scripts (in
+addition to those set in /etc/usbmount/usbmount.conf and by the hotplug
+and udev systems):
+
+UM_DEVICE - filename of the device node
+UM_MOUNTPOINT - mointpoint
+UM_FILESYSTEM - filesystem type
+UM_MOUNTOPTIONS - mount options that have been passed to the mount command
+UM_VENDOR - vendor of the device (empty if unknown)
+UM_MODEL - model name of the device (empty if unknown)
+
+Likewise, the command 'run-parts /etc/usbmount/umount.d' is executed
+after a device or partition has been unmounted. The scripts can make use
+of the environment variables UM_DEVICE, UM_MOUNTPOINT and UM_FILESYSTEM.
+Note that vendor and model name are no longer easily available when the
+device has been removed. If you need this information in an unmount hook
+script, write it to a file in a mount hook script and read it back in
+the unmount hook script.
Modified: trunk/usbmount/debian/changelog
===================================================================
--- trunk/usbmount/debian/changelog 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/debian/changelog 2005-04-12 15:50:26 UTC (rev 20)
@@ -1,14 +1,23 @@
usbmount (0.0.10) unstable; urgency=low
+ * Upload sponsored by Rafael Laboissiere.
* When a partition (as opposed to a partition-less device) is mounted,
- an underscore and the partition number are appended to the model
+ an underscore and the partition number are appended to the model name
symlink.
+ * The model name symlink now includes the vendor if known.
* Acquire lock before 'udev_volume_id' is called. This causes the
partitions (on a device with more than one partition) to be mounted in
the right order.
* Fixed typos in log messages.
+ * Run hook scripts when a device or partition is mounted or unmounted
+ (closes: #303562). Describe how to use this feature in the README file.
+ * Moved /etc/usbmount.conf to /etc/usbmount/usbmount.conf.
+ * Moved deletion of mount points in /media from prerm to postrm. Delete
+ them not only when the package is removed, but also when installing is
+ aborted.
+ * Moved creation and deletion of model name symlinks to hook scripts.
- --
+ -- Martin Dickopp <martin@zero-based.org> Tue, 12 Apr 2005 17:45:51 +0200
usbmount (0.0.9) unstable; urgency=low
Modified: trunk/usbmount/debian/install
===================================================================
--- trunk/usbmount/debian/install 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/debian/install 2005-04-12 15:50:26 UTC (rev 20)
@@ -1,3 +1,5 @@
usbmount usr/share/usbmount
usbmount.dev etc/dev.d/block
-usbmount.conf etc
+usbmount.conf etc/usbmount
+00_create_model_symlink etc/usbmount/mount.d
+00_remove_model_symlink etc/usbmount/umount.d
Copied: trunk/usbmount/debian/postrm (from rev 17, trunk/usbmount/debian/prerm)
===================================================================
--- trunk/usbmount/debian/prerm 2005-04-07 09:03:16 UTC (rev 17)
+++ trunk/usbmount/debian/postrm 2005-04-12 15:50:26 UTC (rev 20)
@@ -0,0 +1,29 @@
+#!/bin/sh
+set -e
+
+# If an upgraded from a version before 0.0.10 is aborted
+# and /etc/usbmount.conf has already been moved to
+# /etc/usbmount/usbmount.conf, move it back.
+if test "$1" = abort-upgrade || test "$1" = abort-install; then
+ if test -n "$2" && dpkg --compare-versions "$2" lt 0.0.10; then
+ if test -f /etc/usbmount/usbmount.conf && ! test -e /etc/usbmount.conf; then
+ mv /etc/usbmount/usbmount.conf /etc/usbmount.conf
+ fi
+ if test -d /etc/usbmount; then
+ rmdir /etc/usbmount || :
+ fi
+ fi
+fi
+
+# If the package is removed or installing is aborted, try to remove the
+# default mountpoints. Failure to do so is not considered fatal.
+if test "$1" = remove || test "$1" = abort-install; then
+ rm -f /media/usb 2> /dev/null || :
+ for i in 0 1 2 3 4 5 6 7; do
+ rmdir /media/usb$i 2> /dev/null || :
+ done
+fi
+
+#DEBHELPER#
+
+exit 0
Modified: trunk/usbmount/debian/preinst
===================================================================
--- trunk/usbmount/debian/preinst 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/debian/preinst 2005-04-12 15:50:26 UTC (rev 20)
@@ -1,10 +1,21 @@
#!/bin/sh
set -e
-# Actions to perform if the package is installed.
+# If the package is upgraded from a version before 0.0.10,
+# move /etc/usbmount.conf to /etc/usbmount/usbmount.conf.
+if test "$1" = upgrade || test "$1" = install; then
+ if test -n "$2" && dpkg --compare-versions "$2" lt 0.0.10 \
+ && test -f /etc/usbmount.conf \
+ && ! test -e /etc/usbmount/usbmount.conf; then
+ test -d /etc/usbmount || mkdir /etc/usbmount
+ echo Moving /etc/usbmount.conf to /etc/usbmount/usbmount.conf ...
+ mv /etc/usbmount.conf /etc/usbmount/usbmount.conf
+ fi
+fi
+
+# If the package is installed, try to create the default mountpoints.
+# Failure to do so is not considered fatal.
if test "$1" = install; then
- # Try to create the default mountpoints. Failure to do so is not
- # considered fatal.
mkdir /media 2> /dev/null || :
for i in 0 1 2 3 4 5 6 7; do
mkdir /media/usb$i 2> /dev/null || :
Modified: trunk/usbmount/debian/prerm
===================================================================
--- trunk/usbmount/debian/prerm 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/debian/prerm 2005-04-12 15:50:26 UTC (rev 20)
@@ -1,16 +1,8 @@
#!/bin/sh
set -e
-# Actions to perform if the package is removed.
+# Remove contents of /var/run/usbmount before the package is removed.
if test "$1" = remove; then
- # Try to remove the default mountpoints. Failure to do so is not
- # considered fatal.
- rm -f /media/usb 2> /dev/null || :
- for i in 0 1 2 3 4 5 6 7; do
- rmdir /media/usb$i 2> /dev/null || :
- done
-
- # Remove contents of /var/run/usbmount.
rm -f /var/run/usbmount/*
fi
Modified: trunk/usbmount/usbmount
===================================================================
--- trunk/usbmount/usbmount 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/usbmount 2005-04-12 15:50:26 UTC (rev 20)
@@ -97,40 +97,44 @@
if test -n "$MOUNTOPTIONS"; then
options="$MOUNTOPTIONS${options:+,$options}"
fi
- if test -n "$options"; then
- options="-o $options"
- fi
# Mount the filesystem.
- log info "executing command: mount -t $fstype $options $DEVNAME $mountpoint"
- mount -t "$fstype" $options "$DEVNAME" "$mountpoint"
+ log info "executing command: mount -t$fstype ${options:+-o$options} $DEVNAME $mountpoint"
+ mount "-t$fstype" "${options:+-o$options}" "$DEVNAME" "$mountpoint"
- # Create a symlink in /var/run/usbmount if the device
- # has a model name.
+ # Determine vendor and model.
+ vendor=
+ if test -r "/sys$DEVPATH/device/vendor"; then
+ vendor="`cat \"/sys$DEVPATH/device/vendor\"`"
+ elif test -r "/sys$DEVPATH/../device/vendor"; then
+ vendor="`cat \"/sys$DEVPATH/../device/vendor\"`"
+ fi
+ vendor="`echo \"$vendor\" | sed 's/^ *//; s/ *$//'`"
model=
if test -r "/sys$DEVPATH/device/model"; then
model="`cat \"/sys$DEVPATH/device/model\"`"
elif test -r "/sys$DEVPATH/../device/model"; then
model="`cat \"/sys$DEVPATH/../device/model\"`"
fi
- model="`echo \"$model\" | sed 's/^[ ]*//; s/[ ]*$//; s/[ ]/_/g; s/[^0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ._-]//g; s/^\.*//'`"
- if test -n "$model" && test -r "/sys$DEVPATH/../device/model"; then
- # Append partition number to model name.
- partnumber="`echo \"$DEVNAME\" | sed 's/^.*[^0123456789]\([0123456789]*\)$/\1/'`"
- model="$model${partnumber:+_$partnumber}"
- fi
- if test -n "$model"; then
- if ! test -e "/var/run/usbmount/$model"; then
- log info "creating symlink /var/run/usbmount/$model -> $mountpoint"
- ln -sf "$mountpoint" "/var/run/usbmount/$model"
- fi
- fi
+ model="`echo \"$model\" | sed 's/^ *//; s/ *$//'`"
+
+ # Run hook scripts; ignore errors.
+ export UM_DEVICE="$DEVNAME"
+ export UM_MOUNTPOINT="$mountpoint"
+ export UM_FILESYSTEM="$fstype"
+ export UM_MOUNTOPTIONS="$options"
+ export UM_VENDOR="$vendor"
+ export UM_MODEL="$model"
+ log info "executing command: run-parts /etc/usbmount/mount.d"
+ run-parts /etc/usbmount/mount.d || :
else
# No suitable mount point found.
log warning "no mountpoint found for $DEVNAME"
exit 1
fi
fi
+ else
+ log debug "$DEVNAME does not contain a filesystem or disklabel"
fi
fi
@@ -147,13 +151,12 @@
log info "executing command: umount -l $mountpoint"
umount -l "$mountpoint"
- # If a model symlink exists for this device, remove it.
- ls /var/run/usbmount | while read model; do
- if test "`readlink /var/run/usbmount/$model || :`" = "$mountpoint"; then
- log info "removing /var/run/usbmount/$model"
- rm -f "/var/run/usbmount/$model"
- fi
- done
+ # Run hook scripts; ignore errors.
+ export UM_DEVICE="$DEVNAME"
+ export UM_MOUNTPOINT="$mountpoint"
+ export UM_FILESYSTEM="$fstype"
+ log info "executing command: run-parts /etc/usbmount/umount.d"
+ run-parts /etc/usbmount/umount.d || :
fi
break
fi
Modified: trunk/usbmount/usbmount.dev
===================================================================
--- trunk/usbmount/usbmount.dev 2005-04-11 18:37:03 UTC (rev 19)
+++ trunk/usbmount/usbmount.dev 2005-04-12 15:50:26 UTC (rev 20)
@@ -25,8 +25,8 @@
VERBOSE="no"
# Read configuration file.
-if test -r /etc/usbmount.conf; then
- . /etc/usbmount.conf
+if test -r /etc/usbmount/usbmount.conf; then
+ . /etc/usbmount/usbmount.conf
fi
# Execute (un)mounting script.