#!/bin/sh # (c) MandrakeSoft, Chmouel Boudjnah <chmouel@mandrakesoft.com> # $Id: usb,v 1.46 2002/11/18 22:05:31 flepied Exp $ # # usb This shell script takes care of starting and stopping # your usb devices. # # description: This startup script try to load your modules for your usb devices. if [ -f /etc/modules.conf ];then conf_file=/etc/modules.conf elif [ -f /etc/conf.modules ];then conf_file=/etc/conf.modules else exit 0 fi if [ -f /etc/sysconfig/usb ];then source /etc/sysconfig/usb fi grep -iq nousb /proc/cmdline && exit 0 . /etc/rc.d/init.d/functions if [ "$USB" = "no" ];then exit 0 fi ARCH=$(uname -m) function load_module () { opt="" phrase=$1 alias=$2 [ -n "$3" ] && opt="-r" modules=`egrep -s "^(probeall|alias)( |\t)+"$alias"( |\t)+" $conf_file | sed "s/^.*$alias//"` for module in $modules; do if [ -n "$module" ] && [ "$module" != "off" ];then action "Initializing USB controller (%s): " $module modprobe "$opt" $module fi done return 0; } function get_usb_interface () { if ! egrep -q "^(probeall|alias) usb-interface" $conf_file;then exit 0 fi } function mount_proc_usb () { if grep -q usbdevfs /proc/filesystems;then if ! grep -q /proc/bus/usb /proc/mounts;then action "Mount USB filesystem" mount -t usbdevfs -o devmode=0664,devgid=43 none /proc/bus/usb fi fi } function remove_module () { modules="$@" for module in "$modules";do modprobe -r $module >/dev/null 2>&1 done } function usb_stop () { # call this multiple times if you had to take down components of the # USB subsystem by hand; it cleans up whatever can # be cleaned up, letting the system quiesce further. # disconnect all controllers we can, and kernel drivers # HCDs first, so most drivers reduce their use counts. remove_module usb-ohci usb-uhci uhci remove_module ehci-hcd hcd # user mode code may keep usbdevfs busy for a while yet ... # OK, usbcore won't actually be removed unless there happen to be # no USB drivers loaded, and usbdevfs isn't mounted. let's force # removal of autocleanable modules before trying to rmmod usbcore rmmod -as # Now let's workaround the fact that some USB modules never increase # their module use counts, so that "rmmod -a" won't unload them. # (And we can't use "modprobe --autoclean" anyway.) remove_module joydev keybdev wacom wmforce remove_module cpia_usb cpia dc2xx rio500 mdc800 scanner remove_module acm audio ibmcam uss720 printer hid remove_module microtek dsbr100 evdev pegasus plusb remove_module usb-serial usb-storage net1080 usbnet kaweth remove_module ov511 videodev belkin_sa digi_acceleport empeg ftdi_sio remove_module keyspan_pda keyspan omninet visor whiteheat usbserial remove_module bluetooth dabusb mct_u232 modprobe -r usbkbd >/dev/null 2>&1 modprobe -r input >/dev/null 2>&1 modprobe -r usbvision >/dev/null 2>&1 # ok, hope that user mode drivers/managers closed their fds. umount /proc/bus/usb >/dev/null 2>&1 remove_module usbcore # we did everything we could ... return 0; } PKLVL=$(cut -f1 /proc/sys/kernel/printk) case $1 in start) get_usb_interface; sysctl -n -w kernel.printk=0 load_module "Loading USB interface" usb-interface || retval=1 awk '/^((alias)|(probe)) +usb-interface[0-9]/ {print $2, " ", $3}' $conf_file | ( \ while read line mod; do nmb=${line##usb-interface} [[ $loaded != *$mod* ]] && { load_module "Loading USB interface$nmb" $line || retval=1 } loaded="$loaded $mod" done ) mount_proc_usb # Static modules that we want to insert and not detected by usbd. if [ "$MOUSE" = "yes" ];then action "Loading USB mouse" /sbin/modprobe mousedev fi if [ "$KEYBOARD" = "yes" ];then action "Loading USB keyboard" /sbin/modprobe keybdev fi if [ "$STORAGE" = "yes" ];then action "Loading USB storage" /sbin/modprobe usb-storage fi if [ "$PRINTER" = "yes" ];then action "Loading USB printer" /sbin/modprobe printer fi if [ "$VISOR" = "yes" ];then action "Loading USB visor" /sbin/modprobe visor fi sysctl -n -w kernel.printk=$PKLVL ;; stop) # usb_stop; rm -f /var/lock/subsys/usb ;; status) if fgrep -q usbcore /proc/modules;then gprintf "USB Loaded." echo else gprintf "USB not loaded." echo fi exit 0 ;; reload) ;; restart) $0 stop $0 start ;; *) gprintf "Usage: %s\n" "$(basename $0) {start|stop|restart|status}" exit 0 ;; esac exit 0