#!/bin/sh

# name        : bdflush
# author      : Matthias Grimm <matthiasgrimm@users.sourceforge.net>
# description : toggle laptop mode in kernel and adjust
#               memory management buffer flush timeouts
#               This script will first look for an global laptop-mode
#               script before running a private version.
# requirements: laptop-mode patch in kernel
#               laptopmode.sh somewhere on your system
# limitations : none 
#
# --- end of public part -- don't change below this line ---

if [ -x event.d/apmd-compat ]; then
	if [ -x /etc/apm/event.d/laptop-mode ]; then
		logger -p daemon.error -t pmcs-bdflush "External laptop-mode script found - exiting."
		exit 0
	fi
fi

# source configuration
. pmcs-config
if [ -w /proc/sys/vm/laptop_mode ]; then
  if [ -x $general_LMScript ]; then
    case "$1" in
      powersave)
  	$general_LMScript $powersave_LaptopMode
	;;
      custom)
        $general_LMScript $custom_LaptopMode
        ;;
      performance)
        $general_LMScript $performance_LaptopMode
        ;;
    esac
  elif [ -x logger ]; then
     logger -p daemon.error -t pmcs-bdflush "Can't find $general_LMScript."
  fi
elif [ -x logger ]; then	
  logger -p daemon.error -t pmcs-bdflush "Laptop-mode patch missing in kernel."
fi


