#! /bin/sh

log () {
	if [ -S /dev/log ]; then
		logger -t coldplug "$@"
	else
		echo "$@"
	fi
}

run_hotplug_rc () {
	log "Running $1"
	if $1 start; then
		log "$(printf "   %-8s [success]\n" "$2")"
	else
		log "$(printf "   %-8s [failed]\n" "$2")"
	fi
}

if [ -d /etc/hotplug ]; then
	for RC in /etc/hotplug/*.rc; do
		basename="${RC#/etc/hotplug/}"
		name="${basename%.rc}"
		case $name in
			pci|usb|ide|scsi)
				# Defer these until last so that we can
				# guarantee ordering.
				continue
				;;
			*)
				run_hotplug_rc "$RC" "$name"
				;;
		esac
	done
	for name in pci usb ide scsi; do
		if [ -x "/etc/hotplug/$name.rc" ]; then
			run_hotplug_rc "/etc/hotplug/$name.rc" "$name"
		fi
	done
fi
