updated on Fri Jan 20 04:00:45 UTC 2012
[aur-mirror.git] / eee-fan / eee-fan-ctrl.sh
blob4358e7a01c03f6e46ed3a9590768669455de9a87
1 #!/bin/sh
2 # A script to control the fan in the eeepc
3 ## yet another dubious Dougal script for Puppy Linux, October 2008
4 ## Licenced under GPL v2 or later
5 ## No BASHisms I'm aware of...
6 # Update Nov. 2nd: add clean exiting (trap SIGTERM) and VERBOSE_LOGGING
8 SCRIPT_NAME=$(basename $0)
9 CONFIG_FILE="/etc/eee-fan.conf"
10 LOG_FILE="/var/log/eee-fan.log"
12 # Make sure the eee module is loaded
13 if [ ! -d /proc/eee ] ; then
14 if grep -Fq 'eee ' /proc/modules ; then
15 echo "$SCRIPT_NAME: Error: /proc/eee doesn't exist" >&2
16 exit
17 elif modprobe eee ; then
18 # sleep a little, just in case (I don't have an eee, so don't know...)
19 sleep 5
20 if [ ! -d /proc/eee ] ; then
21 echo "$SCRIPT_NAME: Error: /proc/eee doesn't exist" >&2
22 exit
24 else
25 echo "$SCRIPT_NAME: Error: failed to load module eee.ko" >&2
26 exit
30 # a function to set fan to auto and exit
31 exit_script(){
32 echo 40 > /proc/eee/fan_speed
33 echo 0 > /proc/eee/fan_manual
34 $ENABLE_LOGGING && echo "$(date +'%b %d %T ') Set mode to auto ; Exiting" >>$LOG_FILE
35 [ "$1" ] && echo "$SCRIPT_NAME: Error: $@" >&2
36 exit
39 # a function to read config file and make sure we have everything (or set to default)
40 read_config(){
41 . $CONFIG_FILE || exit_script "failed to read configuration file. Exiting."
42 [ "$CONTROL_FAN" = "true" ] || exit_script
43 [ -z "$CONTROL_FAN" -o -z "$SLEEP_TIME" -o -z "$HIGH_TEMP" -o -z "$LOW_TEMP" -o -z "$FAN_SPEED" ] && exit_script "wrong values in configuration file. Exiting."
44 # make sure max temp is reasonable and higher than low temp...
45 [ $HIGH_TEMP -le $MAX_TEMP -a $HIGH_TEMP -gt $LOW_TEMP ] || exit_script "bad HIGH_TEMP value. Exiting."
46 # make sure low temp is reasonable...
47 [ $LOW_TEMP -ge $MIN_TEMP ] || exit_script "MIN_TEMP is too low. Exiting."
48 # make sure speed is between 0-100
49 [ $FAN_SPEED -ge 0 -a $FAN_SPEED -le 100 ] || exit_script "bad FAN_SPEED. Exiting"
50 [ $SLEEP_TIME -gt 0 ] || exit_script "bad SLEEP_TIME value. Exiting"
53 # Trap sighup, so we can re-read the configuration without having to terminate
54 trap "read_config" HUP
55 trap "exit_script" SIGTERM
57 # Source config file (also exits if needed)
58 read_config
60 # Move old config file
61 $ENABLE_LOGGING && mv $LOG_FILE $LOG_FILE.old 2>/dev/null
63 # Change to manual control
64 echo 1 > /proc/eee/fan_manual
65 $ENABLE_LOGGING && echo "$(date +'%b %d %T ') Starting ; Set fan to manual" >>$LOG_FILE
67 # Keep track of the state we're in, so we don't keep checking the fan speed
68 STATE="off"
69 # start with off
70 echo 0 > /proc/eee/fan_speed
72 # Start the loop
73 while true ; do
74 #TEMP=$(cat /proc/eee/temperature)
75 read TEMP < /proc/eee/temperature
76 [ -z "$TEMP" ] && exit_script "no temperature value found. Exiting"
77 if [ $TEMP -ge $HIGH_TEMP ] && [ "$STATE" = "off" ] ; then
78 echo "$FAN_SPEED" > /proc/eee/fan_speed
79 STATE="on"
80 $ENABLE_LOGGING && echo "$(date +'%b %d %T ') Temperature ${TEMP}C ; Set fan speed to $FAN_SPEED" >>$LOG_FILE
81 elif [ $TEMP -lt $LOW_TEMP ] && [ "$STATE" = "on" ] ; then
82 echo 0 > /proc/eee/fan_speed
83 STATE="off"
84 $ENABLE_LOGGING && echo "$(date +'%b %d %T ') Temperature ${TEMP}C ; Set fan speed to 0" >>$LOG_FILE
86 $VERBOSE_LOGGING && echo "$(date +'%b %d %T ') Temperature: ${TEMP}C" >>$LOG_FILE
87 sleep $SLEEP_TIME
88 done