#!/bin/sh
#=================================================================
# Begin sshd
#
# Description : Start sshd daemon
# chkconfig: 2345 55 25
#
#=================================================================

### BEGIN INIT INFO
# Provides:            $lm_sensors
# Required-Start:      
# Should-Start:
# Required-Stop:       
# Should-Stop:
# Default-Start:       2 3 4 5
# Default-Stop:        0 1 6
# Short-Description:   Install lm_sensors drivers.
# Description:         Install lm_sensors drivers.
# X-LFS-Provided-By:   LFS
#
### END INIT INFO

. /lib/lsb/init-functions

LOCK=/run/lock
PSENSORS=/usr/local/bin/sensors
if [ ! -x $PSENSORS ]; then
  PSENSORS=/usr/bin/sensors
fi

RETVAL=0
prog="lm_sensors"

# This functions checks if sensor support is compiled into the kernel, if
# sensors are configured, and loads the config file
check_sensors()

{
CONFIG=/etc/sysconfig/lm_sensors
if ! [ -r "$CONFIG" ] || ! grep '^HWMON_MODULES' $CONFIG >/dev/null 2>&1; then
  log_warning_msg "$1 $prog: not configured, run sensors-detect"
  exit 6
  fi

# Load config file
. "$CONFIG"
}

start()

{
check_sensors "Starting"

log_info_msg "Starting $prog: loading module "
for module in $BUS_MODULES $HWMON_MODULES ; do
  echo -n "${module} "
  /sbin/modprobe $module >/dev/null 2>&1
  done
$PSENSORS -s
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
  touch $LOCK/lm_sensors
  fi
evaluate_retval
}

stop()

{
log_info_msg "Stopping $prog: "
for module in $HWMON_MODULES $BUS_MODULES ; do
  /sbin/modprobe -r $module >/dev/null 2>&1
  done
RETVAL=$?
if [ $RETVAL -eq 0 ] ; then
  rm -f $LOCK/lm_sensors
  fi
evaluate_retval
}

dostatus()

{
$PSENSORS
RETVAL=$?
if [ $RETVAL -ne 0 ]; then
  RETVAL=3
  fi
}

restart()

{
stop
sleep 1
start
}

condrestart()

{
[ -e /var/lock/subsys/lm_sensors ] && restart || :
}

# See how we were called.
case "$1" in
  start)
	start
	;;
  stop)
	stop
	;;
  status)
	dostatus
	;;
  restart|reload)
	restart
	;;
  condrestart)
	condrestart
	;;
  *)
	echo "Usage: $0 {start|stop|status|restart|reload|condrestart}"
	exit 3
esac

exit $RETVAL
