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
17 elif modprobe eee
; then
18 # sleep a little, just in case (I don't have an eee, so don't know...)
20 if [ ! -d /proc
/eee
] ; then
21 echo "$SCRIPT_NAME: Error: /proc/eee doesn't exist" >&2
25 echo "$SCRIPT_NAME: Error: failed to load module eee.ko" >&2
30 # a function to set fan to auto and exit
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
39 # a function to read config file and make sure we have everything (or set to default)
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)
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
70 echo 0 > /proc
/eee
/fan_speed
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
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
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