#!/bin/sh # /usr/sbin/dphys-hotplug - call action scripts when hotplug events happen # author franklin, last modification 2006.05.17 # This script is copyright ETH Zuerich Physics Departement, # use under either modified/non-advertising BSD or GPL license # called directly by the kernel, after setting /proc/sys/kernel/hotplug # has as $1 the type of event, such as "usb" or "net" set -e # get ready to work PATH=/sbin:/bin:/usr/sbin:/usr/bin export PATH # fix up the defective stdio situation, which crashes some grep and sed exec < /dev/null > /dev/null 2> /dev/null # what we are NAME=dphys-hotplug # setup a few things CONF_VERBOSE=yes if [ -f /${NAME}.debug ] ; then DEBUG_LOG=yes fi # scripts directory, contains scripts named # ${SCRIPTS}/.* (such as ${SCRIPTS}/usb.*) (old style names) or # ${SCRIPTS}/-* (such as ${SCRIPTS}/usb-*) (new style names) SCRIPTDIR=/etc/${NAME}.d # tell the world we are doing something if [ x${DEBUG_LOG} = xyes ] ; then /usr/bin/logger -t `/usr/bin/basename $0` -p user.debug \ DEBUG: $1 ACTION=${ACTION} PRODUCT=${PRODUCT} INTERFACE=${INTERFACE} \ TYPE=${TYPE} DEVFS=${DEVFS} DEVICE=${DEVICE} fi # first call the standard hotplug stuff, so that device gets registered /sbin/hotplug $@ if [ x${DEVFS} = x ] ; then /usr/bin/logger -t `/usr/bin/basename $0` -p user.warning \ WARNING: no usbdevfs, can not identify device type, aborting ... exit 1 fi if [ x${DEVICE} = x ] ; then /usr/bin/logger -t `/usr/bin/basename $0` -p user.error \ ERROR: usbdevfs faillure, did not identify device type, aborting ... exit 1 fi # then call our own action scripts if [ -d ${SCRIPTDIR} ] ; then # prevent trouble with * expansion when no files, so grep entire dir list SCRIPTS=`/bin/ls -1 ${SCRIPTDIR} | /bin/grep "^$1[\.-]" | \ /usr/bin/wc -l | tr -d ' '` if [ x${DEBUG_LOG} = xyes ] ; then /usr/bin/logger -t `/usr/bin/basename $0` -p user.debug \ DEBUG: SCRIPTS=${SCRIPTS} fi if [ ${SCRIPTS} != 0 ] ; then # tell the world we are going to do something if [ x${CONF_VERBOSE} = xyes ] ; then /usr/bin/logger -t `/usr/bin/basename $0` -p user.info \ $1 ${ACTION} ${DEVICE}, run "script(s):" \ `/bin/ls -1 ${SCRIPTDIR} | /bin/grep "^$1[\.-]"` fi # alphabetic row, so do not depend on other packages, just filter actions for SCRIPT in ${SCRIPTDIR}/$1[.-]* ; do # no parameters, as $1 has been used for all it can do # is now implied in the choice of script to run ${SCRIPT} done else # tell the world we are going to do nothing if [ x${CONF_VERBOSE} = xyes ] ; then /usr/bin/logger -t `/usr/bin/basename $0` -p user.info \ $1 ${ACTION} ${DEVICE}, no "script(s)" installed fi fi else # tell the world we can't do anything if [ x${CONF_VERBOSE} = xyes ] ; then /usr/bin/logger -t `/usr/bin/basename $0` -p user.info \ $1 ${ACTION} ${DEVICE}, no script directory ${SCRIPTDIR} fi fi exit 0