#!/bin/bash # # /etc/rc.d/init.d/usb - Red Hat SysV-style initscript to load and remove the # appropriate modules for the USB bus and USB devices. # # Written by Alex Stewart as part of the Sony Z505 fixup kit. # # chkconfig: 2345 04 96 # description: The Universal Serial Bus (USB) provides plug-and-play access \ # to a wide variety of hardware peripherals. This script \ # manages the necessary drivers to use USB devices under Linux. # (the following settings should really be in an /etc/sysconfig/usb file (or # even managed by a more sophisticated load-on-demand facility), but I wanted # to keep things simple for people adding this to an existing system, and # currently load-on-demand doesn't work quite right for things like mousedev) # The driver required for the USB host bus: usb_controller="usb-uhci" # Drivers required for USB peripherals. Add additional device drivers here, # separated by spaces: # (these defaults should support almost all floppy/zip/etc drives, USB mice, # and USB keyboards) usb_drivers="usb-storage hid mousedev keybdev" # source function library . /etc/rc.d/init.d/functions # This function returns a list of all usb modules currently listed, in the # order in which their dependencies require they be removed. loaded_usb_modules() { modules="" test_modules="usbcore input" while [ -n "$test_modules" ]; do next_pass="" for module in $test_modules; do line=`lsmod | grep "^$module "` if [ -n "$line" ]; then modules="$modules $module" if echo $line | fgrep -q "["; then next_pass="$next_pass `echo $line | sed -e 's/.*\[\(.*\)\].*/\1/'`" fi fi done test_modules="$next_pass" done output="" for module in $modules; do output=" $module `echo \"$output\" | sed -e \"s/ $module / /g\"`" done echo $output } blanking=" \b\b\b\b\b\b\b\b\b\b\b\b\b\b\b\b" RETVAL=0 case "$1" in start) for m in $usb_controller $usb_drivers; do echo -en "\rStarting USB services: $m $blanking" modprobe $m || RETVAL=$? done echo -en "\rStarting USB services: $blanking" touch /var/lock/subsys/usb [ $RETVAL -eq 0 ] && success || failure echo ;; stop) for m in `loaded_usb_modules`; do echo -en "\rShutting down USB services: $m $blanking" rmmod $m || RETVAL=$? done echo -en "\rShutting down USB services: $blanking" [ $RETVAL -eq 0 ] && success || failure echo [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/gpm ;; restart|reload) $0 stop $0 start RETVAL=$? ;; status) modules=`loaded_usb_modules` if [ -n "$modules" ]; then echo "The following USB modules are loaded:" for m in $modules; do echo " $m" done RETVAL=0 else echo "No USB modules are currently loaded." RETVAL=1 fi ;; *) echo "Usage: usb {start|stop|status|restart|reload}" exit 1 esac exit $RETVAL