#!/bin/sh
# Startup script for cpupower
#
# chkconfig: 12345 06 99
# description: Configure CPU power related settings

# Source function library.
. /etc/rc.d/init.d/functions

prog="cpupower"

[ -f /usr/bin/$prog ] || exit 5

CPUPOWER_START_OPTS="frequency-set -g performance"
CPUPOWER_STOP_OPTS="frequency-set -g ondemand"

if [ -f /etc/sysconfig/$prog ]; then
  . /etc/sysconfig/$prog
fi

start_cpupower() {
  echo -n "Configuring cpu frequency scaling: "

  daemon "$prog $CPUPOWER_START_OPTS >/dev/null"
  RETVAL=$?
  echo
  return $RETVAL
}

stop_cpupower() {
  echo -n "Resetting cpu frequency scaling: "

  daemon "$prog $CPUPOWER_STOP_OPTS >/dev/null"
  RETVAL=$?
  echo
  return $RETVAL
}

case "$1" in
  start)
    start_cpupower
    ;;

  stop)
    stop_cpupower
    ;;

  status)
    $prog frequency-info
    exit 0
    ;;

  restart)
    stop
    start
    ;;

  *)
    echo $"Usage: $0 {start|stop|restart|status}"
    exit 3
    ;;
esac

exit $RETVAL
