summaryrefslogtreecommitdiffstats
path: root/usbdev
diff options
context:
space:
mode:
authorncopa <ncopa@f176ef85-8d20-0410-844a-e957b5a1c371>2008-01-22 07:51:55 +0000
committerncopa <ncopa@f176ef85-8d20-0410-844a-e957b5a1c371>2008-01-22 07:51:55 +0000
commitf748fb67f007c7453c8b4cea7439347df60f5ae7 (patch)
tree96c800fd622a7f5198a97dc2f6ea1aa693d5d331 /usbdev
parentfefde488e66c2977e1b93e790029eb72d97edeac (diff)
downloadalpine-baselayout-f748fb67f007c7453c8b4cea7439347df60f5ae7.tar.bz2
alpine-baselayout-f748fb67f007c7453c8b4cea7439347df60f5ae7.tar.xz
release 1.7.0. fixed mdev stuff
Diffstat (limited to 'usbdev')
-rwxr-xr-xusbdev59
1 files changed, 52 insertions, 7 deletions
diff --git a/usbdev b/usbdev
index 34336e2..b1aff29 100755
--- a/usbdev
+++ b/usbdev
@@ -1,17 +1,62 @@
#!/bin/sh
+# script is buggy; until patched just do exit 0
+#exit 0
+
+# add zeros to device or bus
+add_zeros () {
+ case "$(echo $1 | wc -L)" in
+ 1) echo "00$1" ;;
+ 2) echo "0$1" ;;
+ *) echo "$1"
+ esac
+ exit 0
+}
+
+
+# bus and device dirs in /sys
+local USB_PATH=$(echo $MDEV | sed -e 's/usbdev\([0-9]\).[0-9]/usb\1/')
+USB_PATH=$(find /sys/devices -type d -name "$USB_PATH")
+local USB_DEV_DIR=$(echo $MDEV | sed -e 's/usbdev\([0-9]\).\([0-9]\)/\1-\2/')
+
+# dir names in /dev
+local BUS=$(add_zeros $(echo $MDEV | sed -e 's/^usbdev\([0-9]\).[0-9]/\1/'))
+local USB_DEV=$(add_zeros $(echo $MDEV | sed -e 's/^usbdev[0-9].\([0-9]\)/\1/'))
+
+
# try to load the proper driver for usb devices
case "$ACTION" in
add|"")
- for i in /sys/class/usb_device/$MDEV/device/*/modalias ; do
- [ -r "$i" ] && modprobe `cat $i` 2>/dev/null
+ # load usb bus driver
+ for i in $USB_PATH/*/modalias ; do
+ modprobe `cat $i` 2>/dev/null
done
+ # load usb device driver if existent
+ if [ -d $USB_PATH/$USB_DEV_DIR ]; then
+ for i in $USB_PATH/$USB_DEV_DIR/*/modalias ; do
+ modprobe `cat $i` 2>/dev/null
+ done
+ fi
+ # move usb device file
+ mkdir -p bus/usb/$BUS
+ mv $MDEV bus/usb/$BUS/$USB_DEV
;;
remove)
- for i in /sys/class/usb_device/$MDEV/device/*/modalias ; do
- [ -r "$i" ] && modprobe -r `cat $i` 2>/dev/null
+ # unload device driver, if device dir is existent
+ if [ -d $USB_PATH/$USB_DEV_DIR ]; then
+ for i in $USB_PATH/$USB_DEV_DIR/*/modalias ; do
+ modprobe -r `cat $i` 2>/dev/null
done
+ fi
+ # unload usb bus driver. Does this make sense?
+ # what happens, if two usb devices are plugged in
+ # and one is removed?
+ for i in $USB_PATH/*/modalias ; do
+ modprobe -r `cat $i` 2>/dev/null
+ done
+ # remove device file and possible empty dirs
+ rm -f bus/usb/$BUS/$USB_DEV
+ rmdir bus/usb/$BUS/ 2>/dev/null
+ rmdir bus/usb/ 2>/dev/null
+ rmdir bus/ 2>/dev/null
esac
-
-# we dont want the ugly usbdev[0-9].[0-9] dev.
-rm -f $MDEV