home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / etc / init.d / powernowd < prev    next >
Encoding:
Text File  |  2006-07-20  |  3.5 KB  |  137 lines

  1. #! /bin/sh
  2.  
  3. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  4. DAEMON=/usr/sbin/powernowd
  5. NAME=powernowd
  6. DESC=powernowd
  7.  
  8. test -x $DAEMON || exit 0
  9.  
  10. # create the file /etc/default/powernowd if you want to override the value of
  11. # variable OPTIONS and change the default behavior of the daemon as launched
  12.  
  13. OPTIONS="-q"
  14. [ -f /etc/default/$NAME ] && . /etc/default/$NAME
  15.  
  16. # Get lsb functions
  17. . /lib/lsb/init-functions
  18. . /etc/default/rcS
  19.  
  20. if [ "x$VERBOSE" = "xno" ]; then
  21.         MODPROBE_OPTIONS="$MODPROBE_OPTIONS -Q"
  22.         export MODPROBE_OPTIONS
  23. fi
  24.  
  25. set -e
  26.  
  27. load_modules() {
  28.         #stop the kernel printk'ing at all while we load.
  29.         PRINTK=`cat /proc/sys/kernel/printk`
  30.         [ "$VERBOSE" = no ] && echo "0 0 0 0" > /proc/sys/kernel/printk
  31.  
  32.         #build a list of current modules so we don't load a module twice
  33.         LIST=`/sbin/lsmod|awk '!/Module/ {print $1}'`
  34.         
  35.         #get list of available modules
  36.         LOC="/lib/modules/`uname -r`/kernel/drivers/cpufreq"
  37.         if [ -d $LOC ]; then
  38.           MODAVAIL=`( find $LOC -type f -name "*.o" -printf "basename %f .o\n"; \
  39.                    find $LOC -type f -name "*.ko" -printf "basename %f .ko\n" ) | /bin/sh`
  40.         else
  41.           MODAVAIL=""
  42.         fi
  43.  
  44.         
  45.         #echo "Loading cpufreq modules:"
  46.         for mod in $MODAVAIL; do
  47.         #        echo "     $mod"
  48.                 echo $LIST| grep -q -w "$mod" || modprobe $mod >/dev/null || /bin/true
  49.         done
  50.         
  51.         #cpufreq is built in on powerpc; just return
  52.         if [ "`uname -m`" = "ppc" ]; then
  53.                 return 0
  54.         fi
  55.  
  56.  
  57.         #new style detection system
  58.         if [ ! "$FREQDRIVER" = "" ]; then 
  59.                 modprobe "$FREQDRIVER"
  60.         else
  61.             . /usr/share/powernowd/cpufreq-detect.sh
  62.                 [ ! -z "$MODULE" ] && (modprobe "$MODULE"||modprobe "$MODULE_FALLBACK")
  63.         fi
  64.  
  65.         if [ "$USE_OLD_DETECT" = "fish" ]; then
  66.         # now lets load the driver
  67.         if [ ! $FREQDRIVER = "" ]; then 
  68.                 modprobe $FREQDRIVER||true
  69.         fi
  70.         if [ "`uname -m`" = "x86_64" ]; then 
  71.                 modprobe powernow-k8 >/dev/null 2>&1||true
  72.         fi
  73.  
  74.         if [ ! -f /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor ]; then
  75.                 modprobe acpi > /dev/null 2>&1|| true
  76.         fi
  77.         fi
  78.         echo "$PRINTK" > /proc/sys/kernel/printk
  79. }
  80.  
  81. check_kernel() {
  82.     CPUFREQ=/sys/devices/system/cpu/cpu0/cpufreq
  83.  
  84.     if [ -f "$CPUFREQ/scaling_governor" ] && \
  85.         [ -f "$CPUFREQ/scaling_available_governors" ] && \
  86.         grep -q userspace "$CPUFREQ/scaling_available_governors"
  87.     then
  88.         return 0
  89.     else
  90.         return 1
  91.     fi
  92. }
  93.  
  94. start() {
  95.            log_begin_msg "Starting $DESC... "
  96.     if check_kernel
  97.     then
  98.     #       echo "Starting $DESC: "
  99.         start-stop-daemon --start --quiet --oknodo --exec $DAEMON -- $OPTIONS >/dev/null 2>&1 || {
  100.                     status=$?
  101.                     log_end_msg $status
  102.                     return $status
  103.                 }
  104.     else
  105.         log_success_msg "CPU frequency scaling not supported"
  106.     #    echo "required sysfs objects not found!"
  107.     #    echo -e "\tRead /usr/share/doc/powernowd/README.Debian for more information."
  108.     fi
  109.            log_end_msg 0
  110.     return 0
  111. }
  112.  
  113. case "$1" in
  114.   start)
  115.         [ "x$DO_MODULES" = "xyes" -a -f /proc/modules ] && load_modules
  116.     [ "x$DO_MODULES" = "xyes" ] || start
  117.     ;;
  118.   stop)
  119.     log_begin_msg "Stopping $DESC: "
  120.     start-stop-daemon --stop --quiet --oknodo --exec $DAEMON
  121.     log_end_msg $?
  122.     ;;
  123.   restart|force-reload)
  124.         $0 stop
  125.     sleep 1
  126.     $0 start
  127.     #echo "$NAME."
  128.     ;;
  129.   *)
  130.     N=/etc/init.d/$NAME
  131.     log_success_msg "Usage: $N {start|stop|restart|force-reload}" >&2
  132.     exit 1
  133.     ;;
  134. esac
  135.  
  136. exit 0
  137.