summaryrefslogtreecommitdiffstats
path: root/tdeioslave/media/contrib
diff options
context:
space:
mode:
Diffstat (limited to 'tdeioslave/media/contrib')
-rw-r--r--tdeioslave/media/contrib/README18
-rwxr-xr-xtdeioslave/media/contrib/mediamanager_usbstorage.dev108
-rwxr-xr-xtdeioslave/media/contrib/usbcam82
3 files changed, 208 insertions, 0 deletions
diff --git a/tdeioslave/media/contrib/README b/tdeioslave/media/contrib/README
new file mode 100644
index 000000000..8f6041578
--- /dev/null
+++ b/tdeioslave/media/contrib/README
@@ -0,0 +1,18 @@
+Those scripts are an example on how to allow media:/ to use
+hotplugging events if you don't use HAL. They're targeting
+"Linux 2.6 + hotplug + udev" platforms, but we can surely make
+something equivalent for Linux 2.4, FreeBSD...
+
+They are just examples, the packagers will surely develop their
+own version (I'm currently using them on Debian Sid, Linux 2.6.9
+though).
+
+1) mediamanager_usbstorage.dev
+This file only needs to be copied to /etc/dev.d/default
+
+2) usbcam
+This one is a bit more complicated to install.
+The file must be copied into /etc/hotplug/usb and the file
+/etc/hotplug/usb/usbcam.usermap must exists (you can use
+libgphoto2's print-usb-usermap command to create it)
+
diff --git a/tdeioslave/media/contrib/mediamanager_usbstorage.dev b/tdeioslave/media/contrib/mediamanager_usbstorage.dev
new file mode 100755
index 000000000..d12a3e687
--- /dev/null
+++ b/tdeioslave/media/contrib/mediamanager_usbstorage.dev
@@ -0,0 +1,108 @@
+#!/bin/sh
+# /etc/dev.d/default/mediamanager_usbstorage.dev
+# Notify all KDE sessions (thanks to the mediamanager) that a new
+# usb_storage device appeared or disappeared
+#
+
+# to debug this script, uncomment the next line and see /tmp/mediamanager_usbstorage.debug after execution
+#DEBUG=1
+
+# exit immediately if /usr/bin/ is not yet available (during boot if /usr is a separate partition)
+/bin/ls -d /usr/bin/ >/dev/null 2>&1 || exit
+
+DEBUGOUT=/tmp/mediamanager_usbstorage.debug.$$
+if [ "$DEBUG" = "1" -a -z "$2" ]; then
+ echo "executing $0 $@" > $DEBUGOUT
+ echo "with the following environment variables:" >> $DEBUGOUT
+ env >> $DEBUGOUT
+ echo "----" >> $DEBUGOUT
+ sh -x $0 $@ debug >> $DEBUGOUT 2>&1
+ exit
+fi
+
+# we only manage block devices
+if [ "$1" != "block" ]; then exit; fi
+
+# we only manage usb_storage devices
+if [ "$ACTION" = "add" ]; then
+ device="`ls /sys$DEVPATH/../device/../../../ 2> /dev/NULL | grep ':' | head -1`"
+ if [ -z "$device" -o ! -e /sys/bus/usb/drivers/usb-storage/$device ]; then
+ # The behavior is not the same for every kernel it seems.
+ # Testing the driver/ directory just in case.
+ device="`ls /sys$DEVPATH/../device/../../../driver 2> /dev/NULL | grep ':' | head -1`"
+ if [ -z "$device" -o ! -e /sys/bus/usb/drivers/usb-storage/$device ]; then
+ exit
+ fi
+ fi
+fi
+
+# functions for syslog
+LOGGER="logger -t `basename $0`[$$] -p user.notice"
+write_syslog () {
+ echo ${@} | $LOGGER
+}
+
+# be sure the drivers are loaded
+/sbin/modprobe -q usb_storage
+/sbin/modprobe -q vfat
+
+# create the FSH required /media directory
+# See: http://www.pathname.com/fhs/pub/fhs-2.3.html#MEDIAMOUNTPOINT
+MNT=media
+if [ ! -d /$MNT ]; then
+ mkdir /$MNT
+ write_syslog "Created the /$MNT directory"
+fi
+
+# we need DEVPATH, DEVNAME and ACTION, so we warn the user that executes this script by hand
+if [ -z "$DEVPATH" -a -z "$DEVNAME" -a -z "$ACTION" ]; then
+ echo
+ echo "This script must be called by udevd because it needs the following environment variables: DEVPATH, DEVNAME, ACTION"
+ echo "So you must copy this script as /etc/dev.d/default/updfstab-2.6.dev and set it executable"
+ echo "See: http://www.kernel.org/pub/linux/utils/kernel/hotplug/RFC-dev.d"
+ echo
+ exit
+fi
+
+# if $DEVPATH/device exists, we are a device, not a partition, so exit
+if [ -d /sys${DEVPATH}/device ]; then exit; fi
+
+dcop_users="`ps aux | grep dcopserver | grep -v grep | awk '{print $1}' | sort | uniq`"
+
+# if the current device is being added
+if [ "$ACTION" = "add" ]; then
+ # get partition information
+ partition="/sys${DEVPATH}/../device/../../.."
+ # We check twice again... marvelous random kernel behaviour changes...
+ if [ -e $partition/product ]; then
+ product="`cat $partition/product`"
+ else
+ product="`cat $partition/../product`"
+ fi
+ if [ -e $partition/manufacturer ]; then
+ manufacturer="`cat $partition/manufacturer`"
+ else
+ manufacturer="`cat $partition/../manufacturer`"
+ fi
+
+ write_syslog "Invoking dcop..."
+ write_syslog "kded mediamanager removablePlug $DEVNAME \"$manufacturer $product\""
+
+ method="kded mediamanager removablePlug"
+ for user in $dcop_users ; do
+ dcop --user $user --all-sessions $method $DEVNAME "$manufacturer $product"
+ done
+
+elif [ "$ACTION" = "remove" ]; then
+ write_syslog "Invoking dcop..."
+ write_syslog "kded mediamanager removableUnplug $DEVNAME"
+
+ method="kded mediamanager removableUnplug"
+ for user in $dcop_users ; do
+ dcop --user $user --all-sessions $method $DEVNAME
+ done
+
+ umount $DEVNAME
+fi
+
+
diff --git a/tdeioslave/media/contrib/usbcam b/tdeioslave/media/contrib/usbcam
new file mode 100755
index 000000000..85158d96b
--- /dev/null
+++ b/tdeioslave/media/contrib/usbcam
@@ -0,0 +1,82 @@
+#!/bin/sh
+#
+# /etc/hotplug/usb/usbcam
+#
+# Set up newly plugged in USB camera
+# Notify all KDE sessions (thanks to the mediamanager) that a
+# new camera appeared or disappeared
+
+# to debug this script, uncomment the next line and see /tmp/usbcam.debug after execution
+#DEBUG=1
+
+# exit immediately if /usr/bin/ is not yet available (during boot if /usr is a separate partition)
+/bin/ls -d /usr/bin/ >/dev/null 2>&1 || exit
+
+GROUP=camera
+
+if [ "${ACTION}" = "add" ] && [ -f "${DEVICE}" ]
+then
+ chmod a-rwx "${DEVICE}"
+ chgrp "${GROUP}" "${DEVICE}"
+ chmod ug+rw "${DEVICE}"
+fi
+
+
+DEBUGOUT=/tmp/usbcam.debug.$$
+if [ "$DEBUG" = "1" -a -z "$2" ]; then
+ echo "executing $0 $@" > $DEBUGOUT
+ echo "with the following environment variables:" >> $DEBUGOUT
+ env >> $DEBUGOUT
+ echo "----" >> $DEBUGOUT
+ sh -x $0 $@ debug >> $DEBUGOUT 2>&1
+ exit
+fi
+
+# functions for syslog
+LOGGER="logger -t `basename $0`[$$] -p user.notice"
+write_syslog () {
+ echo ${@} | $LOGGER
+}
+
+if [ -z "$REMOVER" ]; then
+ write_syslog "No remover found"
+ exit
+fi
+
+dcop_users="`ps aux | grep dcopserver | grep -v grep | awk '{print $1}' | sort | uniq`"
+
+# if the current device is being added
+if [ "$ACTION" = "add" ]; then
+ write_syslog "Copying remover..."
+ cp /etc/hotplug/usb/usbcam $REMOVER
+ chmod +x $REMOVER
+ # get camera information
+ camera="/sys${DEVPATH}/.."
+ if [ -e $camera/product ]; then product="`cat $camera/product`"; fi
+ if [ -e $camera/manufacturer ]; then manufacturer="`cat $camera/manufacturer`"; fi
+
+ write_syslog "Invoking dcop..."
+ write_syslog "kded mediamanager removableCamera $DEVICE \"$manufacturer $product\""
+
+ method="kded mediamanager removablePlug"
+ for user in $dcop_users ; do
+ dcop --user $user --all-sessions $method $DEVICE "$manufacturer $product"
+ done
+
+ method="kded mediamanager removableCamera"
+ for user in $dcop_users ; do
+ dcop --user $user --all-sessions $method $DEVICE
+ done
+
+elif [ "$ACTION" = "remove" ]; then
+ write_syslog "Invoking dcop..."
+ write_syslog "kded mediamanager removableUnplug $DEVICE"
+
+ method="kded mediamanager removableUnplug"
+ for user in $dcop_users ; do
+ dcop --user $user --all-sessions $method $DEVICE
+ done
+
+fi
+
+