#!/bin/sh
#
# A generic /sbin/hotplug multiplexer program
#
# This script allows any program to be called when /sbin/hotplug is
# called.  It will run any programs located in the default hotplug
# directory (currently /etc/hotplug.d/) that match up with the first
# argument that this script is called with.  The matching is done by
# adding a directory name to the default directory and looking for any
# programs in that directory that are executable, and end in .hotplug
# (to allow backup programs to be live on safely.)
# 
# For example, if /sbin/hotplug is called with the usb argument then
# this script will look in the /etc/hotplug.d/usb/ directory for any
# executable programs that end in .hotplug.
#
# After all programs in the argument directory are executed, the
# "default" directory is searched for any executable programs in it,
# that end in .hotplug.  The default directory is currently
# /etc/hotplug/default/
#
# - Greg Kroah-Hartman
#   May 1, 2003
#
# Released under the GPL Version 2.
#

# if [ -f "/tmp/number" ]; then
# 	NUM=$((`cat /tmp/number`+1))
# 	echo "${NUM}" > /tmp/number
# else
# 	NUM=0
# 	echo "0" > /tmp/number
# fi

# FileName=/tmp/usb-dev-${NUM}
# NUM=0
# for ITEM in $@
# do
# 	echo "argv[${NUM}]: ${ITEM}" >> ${FileName}
# 	NUM=$((${NUM}+1))
# done

# NUM=0
# for ITEM in `env`
# do
# 	echo "env[${NUM}]: ${ITEM}" >> ${FileName}
# 	NUM=$((${NUM}+1))
# done
# echo "==========" >> ${FileName}

FileName="/dev/null"
DIR="/usr/syno/hotplug.d"

#if [ ! -e "/proc/bus/usb/devices" ]; then
#  /usr/syno/hotplug/usb.rc start >> ${FileName} 2>&1
#fi


for I in "${DIR}/$1/"*.hotplug "${DIR}/"default/*.hotplug ; do
	if [ -f $I ]; then
		$I $1 > ${FileName} 2>&1
	fi
done


