#!/bin/bash
#
# hotplug This scripts starts hotpluggable subsystems.
#
# chkconfig: 2345 01 99
# description:	Starts and stops each hotpluggable subsystem. \
#		On startup, may simulate hotplug events for devices \
#		that were present at boot time, before filesystems \
#		(or other resources) used by hotplug agents were available.
#
# $Id: hotplug,v 1.3 2002/12/03 02:01:48 dbrownell Exp $
#
# Modified for Source Mage GNU/Linux (http://www.sourcemage.org)
# 2006-01-04 Arwed v. Merkatz <v.merkatz@gmx.net>
#   * don't disable hotplug unless udev gets used on >= 2.6.15
#
# 2005-12-12 Treeve Jelbert <treeve01@pi.be>
#       * don't run if linux >= 2.6.15
#
# 2004-06-15 Seth Woolley <seth@tautology.org>
# 	* init.d echo underrides for child scripts.
#
# Modified for Source Mage GNU/Linux (http://www.sourcemage.org)
# 2003-07-10 Eric Sandall <sandalle@sourcemage.org>
#
# Modified for Source Mage GNU/Linux (http://www.sourcemage.org)
# 2003-07-31 Jose Bernardo Silva <jbernardo@sourcemage.org>
#
# SMGL-script-version=20030731
#
# SMGL-START:1 2 3 4 S:S11
# SMGL-STOP:0 6:K89
#

PROGRAM=/bin/true
RUNLEVEL=S
NEEDS="+local_fs"

# source function library
. /etc/init.d/smgl_init
. /etc/sysconfig/devices

        KVERREL=`uname -r`
        KVER=${KVERREL%-*}
        KVER_MAJOR=${KVER%.*}
        KVER_MINOR=${KVER##*.}

        if [ "$KVER_MAJOR" == "2.6" ]; then
                # kernel 2.6.15-rc1 don't use hotplug
                if [ $KVER_MINOR -ge 15 -a "$DEVICES" = "udev" ]; then
                        echo "hotplug not needed for kernel-$KVERREL"
                        exit 0
                fi
        fi


start(){
	[ -d /var/lock/subsys ] || mkdir -p /var/lock/subsys
	for RC in /etc/hotplug/*.rc
	do
	    ( unset -f echo; $RC start )
	done
	touch /var/lock/subsys/hotplug
	echo "Hotplug started"
}

restart(){
	for RC in /etc/hotplug/*.rc
	do
	    ( unset -f echo; $RC restart )
	done
}

status(){
	for RC in /etc/hotplug/*.rc
	do
	    ( unset -f echo; $RC status )
	done
}

stop(){
	for RC in /etc/hotplug/*.rc
        do
	    ( unset -f echo; $RC stop )
        done
        rm -f /var/lock/subsys/hotplug
	echo "Hotplug stopped"
}

reload(){
	for RC in /etc/hotplug/*.rc
        do
	    ( unset -f echo; $RC stop )
        done
	for RC in /etc/hotplug/*.rc
        do
	    ( unset -f echo; $RC start )
        done
        rm -f /var/lock/subsys/hotplug
}

