| 1 | #!/bin/bash |
|---|
| 2 | # |
|---|
| 3 | # pwmconfig |
|---|
| 4 | # Tests the pwm outputs of sensors and configures fancontrol |
|---|
| 5 | # |
|---|
| 6 | # Warning!!! This program will stop your fans, one at a time, |
|---|
| 7 | # for approximately 5 seconds each!!! |
|---|
| 8 | # This may cause your processor temperature to rise!!! |
|---|
| 9 | # Verify that all fans are running at normal speed after this |
|---|
| 10 | # program has exited!!! |
|---|
| 11 | # |
|---|
| 12 | # Copyright (C) 2007-2008 Jean Delvare <khali@linux-fr.org> |
|---|
| 13 | # |
|---|
| 14 | # This program is free software; you can redistribute it and/or modify |
|---|
| 15 | # it under the terms of the GNU General Public License as published by |
|---|
| 16 | # the Free Software Foundation; either version 2 of the License, or |
|---|
| 17 | # (at your option) any later version. |
|---|
| 18 | # |
|---|
| 19 | # This program is distributed in the hope that it will be useful, |
|---|
| 20 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 21 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 22 | # GNU General Public License for more details. |
|---|
| 23 | # |
|---|
| 24 | # You should have received a copy of the GNU General Public License |
|---|
| 25 | # along with this program; if not, write to the Free Software |
|---|
| 26 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, |
|---|
| 27 | # MA 02110-1301 USA. |
|---|
| 28 | # |
|---|
| 29 | # |
|---|
| 30 | |
|---|
| 31 | REVISION=$(echo '$Revision$' | cut -d' ' -f2) |
|---|
| 32 | REVDATE=$(echo '$Date$' | cut -d' ' -f2) |
|---|
| 33 | PIDFILE="/var/run/fancontrol.pid" |
|---|
| 34 | |
|---|
| 35 | if [ -f "$PIDFILE" ] |
|---|
| 36 | then |
|---|
| 37 | echo "File $PIDFILE exists. This typically means that the" |
|---|
| 38 | echo "fancontrol deamon is running. You should stop it before running pwmconfig." |
|---|
| 39 | echo "If you are certain that fancontrol is not running, then you can delete" |
|---|
| 40 | echo "$PIDFILE manually." |
|---|
| 41 | exit 1 |
|---|
| 42 | fi |
|---|
| 43 | |
|---|
| 44 | echo "# pwmconfig revision $REVISION ($REVDATE)" |
|---|
| 45 | echo 'This program will search your sensors for pulse width modulation (pwm)' |
|---|
| 46 | echo 'controls, and test each one to see if it controls a fan on' |
|---|
| 47 | echo 'your motherboard. Note that many motherboards do not have pwm' |
|---|
| 48 | echo 'circuitry installed, even if your sensor chip supports pwm.' |
|---|
| 49 | echo |
|---|
| 50 | echo 'We will attempt to briefly stop each fan using the pwm controls.' |
|---|
| 51 | echo 'The program will attempt to restore each fan to full speed' |
|---|
| 52 | echo 'after testing. However, it is ** very important ** that you' |
|---|
| 53 | echo 'physically verify that the fans have been to full speed' |
|---|
| 54 | echo 'after the program has completed.' |
|---|
| 55 | echo |
|---|
| 56 | |
|---|
| 57 | DELAY=5 # 3 seconds delay is too short for large fans, thus I increased it to 5 |
|---|
| 58 | MAX=255 |
|---|
| 59 | |
|---|
| 60 | DIR=/proc/sys/dev/sensors |
|---|
| 61 | if [ ! -d $DIR ] |
|---|
| 62 | then |
|---|
| 63 | if [ -d "/sys/class/hwmon" ] |
|---|
| 64 | then |
|---|
| 65 | SYSFS=2 |
|---|
| 66 | DIR="/sys/class/hwmon" |
|---|
| 67 | elif [ -d "/sys/bus/i2c/devices" ] |
|---|
| 68 | then |
|---|
| 69 | SYSFS=1 |
|---|
| 70 | DIR="/sys/bus/i2c/devices" |
|---|
| 71 | else |
|---|
| 72 | echo $0: 'No sensors found! (modprobe sensor modules?)' |
|---|
| 73 | exit 1 |
|---|
| 74 | fi |
|---|
| 75 | fi |
|---|
| 76 | |
|---|
| 77 | cd $DIR |
|---|
| 78 | if [ "$SYSFS" = "2" ] |
|---|
| 79 | then |
|---|
| 80 | PREFIX='hwmon*/device' |
|---|
| 81 | else |
|---|
| 82 | PREFIX='*-*' |
|---|
| 83 | fi |
|---|
| 84 | DEVICES=`echo $PREFIX` |
|---|
| 85 | if [ "$PREFIX" = "$DEVICES" ] |
|---|
| 86 | then |
|---|
| 87 | echo $0: 'No sensors found! (modprobe sensor modules?)' |
|---|
| 88 | exit 1 |
|---|
| 89 | fi |
|---|
| 90 | |
|---|
| 91 | MATCH=$PREFIX/'pwm[1-9]' |
|---|
| 92 | PWM=`echo $MATCH` |
|---|
| 93 | if [ "$SYSFS" = "1" -a "$MATCH" = "$PWM" ] |
|---|
| 94 | then |
|---|
| 95 | # Deprecated naming scheme (used in kernels 2.6.5 to 2.6.9) |
|---|
| 96 | MATCH=$PREFIX/'fan[1-9]_pwm' |
|---|
| 97 | PWM=`echo $MATCH` |
|---|
| 98 | fi |
|---|
| 99 | if [ "$MATCH" = "$PWM" ] |
|---|
| 100 | then |
|---|
| 101 | echo $0: 'There are no pwm-capable sensor modules installed' |
|---|
| 102 | exit 1 |
|---|
| 103 | fi |
|---|
| 104 | |
|---|
| 105 | if [ -n "$SYSFS" ] |
|---|
| 106 | then |
|---|
| 107 | MATCH=$PREFIX/'fan[1-9]_input' |
|---|
| 108 | else |
|---|
| 109 | MATCH=$PREFIX/'fan[1-9]' |
|---|
| 110 | fi |
|---|
| 111 | FAN=`echo $MATCH` |
|---|
| 112 | if [ "$MATCH" = "$FAN" ] |
|---|
| 113 | then |
|---|
| 114 | echo $0: 'There are no fan-capable sensor modules installed' |
|---|
| 115 | exit 1 |
|---|
| 116 | fi |
|---|
| 117 | |
|---|
| 118 | # $1 = padding |
|---|
| 119 | # Only works with Linux 2.6 |
|---|
| 120 | function print_devices() |
|---|
| 121 | { |
|---|
| 122 | for device in $DEVICES |
|---|
| 123 | do |
|---|
| 124 | echo "$1$device is `cat $device/name`" |
|---|
| 125 | done |
|---|
| 126 | } |
|---|
| 127 | |
|---|
| 128 | # $1 = pwm file name |
|---|
| 129 | function is_pwm_auto() |
|---|
| 130 | { |
|---|
| 131 | if [ -n "$SYSFS" ] |
|---|
| 132 | then |
|---|
| 133 | ENABLE=${1}_enable |
|---|
| 134 | if [ -f $ENABLE ] |
|---|
| 135 | then |
|---|
| 136 | if [ "`cat $ENABLE`" -gt 1 ] |
|---|
| 137 | then |
|---|
| 138 | return 0 |
|---|
| 139 | fi |
|---|
| 140 | fi |
|---|
| 141 | fi |
|---|
| 142 | |
|---|
| 143 | return 1 |
|---|
| 144 | } |
|---|
| 145 | |
|---|
| 146 | # $1 = pwm file name |
|---|
| 147 | function pwmdisable() |
|---|
| 148 | { |
|---|
| 149 | if [ -n "$SYSFS" ] |
|---|
| 150 | then |
|---|
| 151 | ENABLE=${1}_enable |
|---|
| 152 | # No enable file? Just set to max |
|---|
| 153 | if [ ! -f $ENABLE ] |
|---|
| 154 | then |
|---|
| 155 | echo $MAX > $1 |
|---|
| 156 | return 0 |
|---|
| 157 | fi |
|---|
| 158 | |
|---|
| 159 | # Try pwmN_enable=0 |
|---|
| 160 | echo 0 2>/dev/null > $ENABLE |
|---|
| 161 | if [ "`cat $ENABLE`" -eq 0 ] |
|---|
| 162 | then |
|---|
| 163 | # Success |
|---|
| 164 | return 0 |
|---|
| 165 | fi |
|---|
| 166 | |
|---|
| 167 | # It didn't work, try pwmN_enable=1 pwmN=255 |
|---|
| 168 | echo 1 2>/dev/null > $ENABLE |
|---|
| 169 | if [ "`cat $ENABLE`" -ne 1 ] |
|---|
| 170 | then |
|---|
| 171 | echo "$ENABLE stuck to `cat $ENABLE`" >&2 |
|---|
| 172 | return 1 |
|---|
| 173 | fi |
|---|
| 174 | |
|---|
| 175 | echo $MAX > $1 |
|---|
| 176 | if [ "`cat $1`" -ge 190 ] |
|---|
| 177 | then |
|---|
| 178 | # Success |
|---|
| 179 | return 0 |
|---|
| 180 | fi |
|---|
| 181 | |
|---|
| 182 | # Nothing worked |
|---|
| 183 | echo "$1 stuck to `cat $1`" >&2 |
|---|
| 184 | return 1 |
|---|
| 185 | else |
|---|
| 186 | echo $MAX 0 > $1 |
|---|
| 187 | fi |
|---|
| 188 | } |
|---|
| 189 | |
|---|
| 190 | # $1 = pwm file name |
|---|
| 191 | function pwmenable() |
|---|
| 192 | { |
|---|
| 193 | if [ -n "$SYSFS" ] |
|---|
| 194 | then |
|---|
| 195 | ENABLE=${1}_enable |
|---|
| 196 | if [ -w $ENABLE ] |
|---|
| 197 | then |
|---|
| 198 | echo 1 2>/dev/null > $ENABLE |
|---|
| 199 | if [ $? -ne 0 ] |
|---|
| 200 | then |
|---|
| 201 | return 1 |
|---|
| 202 | fi |
|---|
| 203 | fi |
|---|
| 204 | echo $MAX > $1 |
|---|
| 205 | else |
|---|
| 206 | echo $MAX 1 > $1 |
|---|
| 207 | fi |
|---|
| 208 | } |
|---|
| 209 | |
|---|
| 210 | # $1 = pwm file name; $2 = pwm value 0-255 |
|---|
| 211 | function pwmset() |
|---|
| 212 | { |
|---|
| 213 | echo $2 > $1 |
|---|
| 214 | } |
|---|
| 215 | |
|---|
| 216 | if [ -n "$SYSFS" ] |
|---|
| 217 | then |
|---|
| 218 | echo 'Found the following devices:' |
|---|
| 219 | print_devices " " |
|---|
| 220 | echo |
|---|
| 221 | fi |
|---|
| 222 | |
|---|
| 223 | echo 'Found the following PWM controls:' |
|---|
| 224 | for i in $PWM |
|---|
| 225 | do |
|---|
| 226 | echo " $i" |
|---|
| 227 | if [ -w $i ] |
|---|
| 228 | then |
|---|
| 229 | # First check if PWM output is in automatic mode |
|---|
| 230 | if is_pwm_auto $i |
|---|
| 231 | then |
|---|
| 232 | echo "$i is currently setup for automatic speed control." |
|---|
| 233 | echo 'In general, automatic mode is preferred over manual mode, as' |
|---|
| 234 | echo 'it is more efficient and it reacts faster. Are you sure that' |
|---|
| 235 | echo -n 'you want to setup this output for manual control? (n) ' |
|---|
| 236 | read X |
|---|
| 237 | if [ "$X" = "" -o "$X" != "y" -a "$X" != "Y" ] |
|---|
| 238 | then |
|---|
| 239 | continue |
|---|
| 240 | fi |
|---|
| 241 | fi |
|---|
| 242 | |
|---|
| 243 | pwmdisable $i |
|---|
| 244 | if [ $? -ne 0 ] |
|---|
| 245 | then |
|---|
| 246 | echo "Manual control mode not supported, skipping $i." |
|---|
| 247 | elif [ "$GOODPWM" = "" ] |
|---|
| 248 | then |
|---|
| 249 | GOODPWM=$i |
|---|
| 250 | else |
|---|
| 251 | GOODPWM="$GOODPWM $i" |
|---|
| 252 | fi |
|---|
| 253 | else |
|---|
| 254 | NOTROOT=1 |
|---|
| 255 | fi |
|---|
| 256 | done |
|---|
| 257 | |
|---|
| 258 | if [ "$GOODPWM" = "" ] |
|---|
| 259 | then |
|---|
| 260 | echo 'There are no usable PWM outputs.' |
|---|
| 261 | exit 1 |
|---|
| 262 | fi |
|---|
| 263 | |
|---|
| 264 | echo |
|---|
| 265 | echo "Giving the fans some time to reach full speed..." |
|---|
| 266 | sleep $DELAY |
|---|
| 267 | echo 'Found the following fan sensors:' |
|---|
| 268 | for i in $FAN |
|---|
| 269 | do |
|---|
| 270 | # this will return the first field if there's only one (sysfs) |
|---|
| 271 | S=`cat $i | cut -d' ' -f2` |
|---|
| 272 | if [ "$S" = "0" -o "$S" = "-1" ] |
|---|
| 273 | then |
|---|
| 274 | echo " $i current speed: 0 ... skipping!" |
|---|
| 275 | else |
|---|
| 276 | echo " $i current speed: $S RPM" |
|---|
| 277 | if [ "$GOODFAN" = "" ] |
|---|
| 278 | then |
|---|
| 279 | GOODFAN=$i |
|---|
| 280 | SPEEDS=$S |
|---|
| 281 | else |
|---|
| 282 | GOODFAN="$GOODFAN $i" |
|---|
| 283 | SPEEDS="$SPEEDS $S" |
|---|
| 284 | fi |
|---|
| 285 | fi |
|---|
| 286 | done |
|---|
| 287 | echo |
|---|
| 288 | |
|---|
| 289 | if [ "$GOODFAN" = "" ] |
|---|
| 290 | then |
|---|
| 291 | echo 'There are no working fan sensors, all readings are 0.' |
|---|
| 292 | echo 'Make sure you have a 3-wire fan connected.' |
|---|
| 293 | echo 'You may also need to increase the fan divisors.' |
|---|
| 294 | echo 'See doc/fan-divisors for more information.' |
|---|
| 295 | exit 1 |
|---|
| 296 | fi |
|---|
| 297 | |
|---|
| 298 | if [ "$NOTROOT" = "1" ] |
|---|
| 299 | then |
|---|
| 300 | echo 'As you are not root, we cannot write the PWM settings.' |
|---|
| 301 | echo 'Please run as root to continue.' |
|---|
| 302 | exit 1 |
|---|
| 303 | fi |
|---|
| 304 | |
|---|
| 305 | echo 'Warning!!! This program will stop your fans, one at a time,' |
|---|
| 306 | echo "for approximately $DELAY seconds each!!!" |
|---|
| 307 | echo 'This may cause your processor temperature to rise!!!' |
|---|
| 308 | echo 'If you do not want to do this hit control-C now!!!' |
|---|
| 309 | echo -n 'Hit return to continue: ' |
|---|
| 310 | read X |
|---|
| 311 | echo |
|---|
| 312 | |
|---|
| 313 | PLOTTER=gnuplot |
|---|
| 314 | STEP=15 |
|---|
| 315 | PDELAY=2 |
|---|
| 316 | # Use a smaller step for low PWM values as this is typically where the |
|---|
| 317 | # more important fan speed changes are happening. |
|---|
| 318 | STEP2=2 |
|---|
| 319 | STEP2_BELOW=31 |
|---|
| 320 | |
|---|
| 321 | function pwmdetail() |
|---|
| 322 | { |
|---|
| 323 | P=$1 |
|---|
| 324 | F=$2 |
|---|
| 325 | PLOT= |
|---|
| 326 | |
|---|
| 327 | type $PLOTTER > /dev/null 2>&1 |
|---|
| 328 | if [ $? -eq 0 ] |
|---|
| 329 | then |
|---|
| 330 | echo -n "Would you like to generate a graphical plot using $PLOTTER (y)? " |
|---|
| 331 | read X |
|---|
| 332 | if [ "$X" = "y" -o "$X" = "Y" -o "$X" = "" ] |
|---|
| 333 | then |
|---|
| 334 | PLOT=y |
|---|
| 335 | fi |
|---|
| 336 | else |
|---|
| 337 | if [ -n "$DISPLAY" ] |
|---|
| 338 | then |
|---|
| 339 | echo "Note: If you had $PLOTTER installed, I could generate a graphical plot." |
|---|
| 340 | fi |
|---|
| 341 | fi |
|---|
| 342 | |
|---|
| 343 | if [ "$PLOT" = "y" ] |
|---|
| 344 | then |
|---|
| 345 | TMP1=`mktemp -t pwmtest1.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1; } |
|---|
| 346 | TMP2=`mktemp -t pwmtest2.XXXXXXXXXX` || { rm -f $TMP1 ; echo "$0: Cannot create temporary file" >&2; exit 1; } |
|---|
| 347 | echo "set xlabel \"PWM: $P\"" > $TMP1 |
|---|
| 348 | echo "set ylabel \"FAN: $F (RPM)\"" >> $TMP1 |
|---|
| 349 | echo 'set nokey' >> $TMP1 |
|---|
| 350 | echo 'set xrange [0:255]' >> $TMP1 |
|---|
| 351 | echo "plot \"$TMP2\" with lines" >> $TMP1 |
|---|
| 352 | echo 'pause -1 " Hit return to continue..."' >> $TMP1 |
|---|
| 353 | > $TMP2 |
|---|
| 354 | fi |
|---|
| 355 | |
|---|
| 356 | local threshold=100000 |
|---|
| 357 | let pwm=$MAX |
|---|
| 358 | pwmenable $P |
|---|
| 359 | while [ $pwm -ge 0 ] |
|---|
| 360 | do |
|---|
| 361 | pwmset $P $pwm |
|---|
| 362 | sleep $PDELAY |
|---|
| 363 | if [ $? -ne 0 ] |
|---|
| 364 | then |
|---|
| 365 | pwmdisable $P |
|---|
| 366 | echo '^C received, aborting...' |
|---|
| 367 | rm -f $TMP1 $TMP2 |
|---|
| 368 | exit 1 |
|---|
| 369 | fi |
|---|
| 370 | # this will return the first field if there's only one (sysfs) |
|---|
| 371 | S=`cat $F | cut -d' ' -f2` |
|---|
| 372 | # Fan speed should never increase significantly |
|---|
| 373 | if [ $S -gt $threshold ] |
|---|
| 374 | then |
|---|
| 375 | echo " PWM $pwm FAN $S (probably incorrect)" |
|---|
| 376 | else |
|---|
| 377 | echo " PWM $pwm FAN $S" |
|---|
| 378 | let threshold=S*6/5 |
|---|
| 379 | fi |
|---|
| 380 | |
|---|
| 381 | if [ "$PLOT" = "y" ] |
|---|
| 382 | then |
|---|
| 383 | echo "$pwm $S" >> $TMP2 |
|---|
| 384 | fi |
|---|
| 385 | if [ "$S" = "0" -o "$S" = "-1" ] |
|---|
| 386 | then |
|---|
| 387 | pwmdisable $P |
|---|
| 388 | echo " Fan Stopped at PWM = $pwm" |
|---|
| 389 | if [ $pwm -eq $MAX ] |
|---|
| 390 | then |
|---|
| 391 | echo " This fan appears to stop when the PWM is enabled;" |
|---|
| 392 | echo " perhaps the fan input shares a pin with the PWM output" |
|---|
| 393 | echo " on the sensor chip." |
|---|
| 394 | echo " You cannot control this fan with this PWM output." |
|---|
| 395 | rm -f $TMP1 $TMP2 |
|---|
| 396 | echo |
|---|
| 397 | return 0 |
|---|
| 398 | fi |
|---|
| 399 | break |
|---|
| 400 | fi |
|---|
| 401 | if [ $pwm -lt $STEP2_BELOW ] |
|---|
| 402 | then |
|---|
| 403 | let pwm=$pwm-$STEP2 |
|---|
| 404 | else |
|---|
| 405 | let pwm=$pwm-$STEP |
|---|
| 406 | fi |
|---|
| 407 | done |
|---|
| 408 | pwmdisable $P |
|---|
| 409 | if [ "$PLOT" = "y" ] |
|---|
| 410 | then |
|---|
| 411 | $PLOTTER $TMP1 |
|---|
| 412 | rm -f $TMP1 $TMP2 |
|---|
| 413 | fi |
|---|
| 414 | echo |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | for i in $GOODPWM |
|---|
| 418 | do |
|---|
| 419 | echo Testing pwm control $i ... |
|---|
| 420 | pwmenable $i |
|---|
| 421 | if [ $? -ne 0 ] |
|---|
| 422 | then |
|---|
| 423 | echo "Manual control mode not supported, skipping." |
|---|
| 424 | continue |
|---|
| 425 | fi |
|---|
| 426 | pwmset $i 0 |
|---|
| 427 | sleep $DELAY |
|---|
| 428 | if [ $? -ne 0 ] |
|---|
| 429 | then |
|---|
| 430 | pwmdisable $i |
|---|
| 431 | echo '^C received, restoring PWM and aborting...' |
|---|
| 432 | exit 1 |
|---|
| 433 | fi |
|---|
| 434 | let pwmactivecount=0 |
|---|
| 435 | let count=1 |
|---|
| 436 | for j in $GOODFAN |
|---|
| 437 | do |
|---|
| 438 | OS=`echo $SPEEDS | cut -d' ' -f$count` |
|---|
| 439 | # this will return the first field if there's only one (sysfs) |
|---|
| 440 | S=`cat $j | cut -d' ' -f2` |
|---|
| 441 | echo " $j ... speed was $OS now $S" |
|---|
| 442 | pwmdisable $i |
|---|
| 443 | let threshold=2*$OS/3 |
|---|
| 444 | if [ $S -lt $threshold ] |
|---|
| 445 | then |
|---|
| 446 | echo " It appears that fan $j" |
|---|
| 447 | echo " is controlled by pwm $i" |
|---|
| 448 | # |
|---|
| 449 | # a PWM can control more than one fan.... |
|---|
| 450 | # |
|---|
| 451 | if [ $pwmactivecount -eq 0 ] |
|---|
| 452 | then |
|---|
| 453 | let pwmactivecount=1 |
|---|
| 454 | pwmactive="$i ${pwmactive}" |
|---|
| 455 | fanactive="$j ${fanactive}" |
|---|
| 456 | fanactive_min="$S ${fanactive_min}" |
|---|
| 457 | else |
|---|
| 458 | fanactive="$j+${fanactive}" #not supported yet by fancontrol |
|---|
| 459 | fanactive_min="$S+${fanactive_min}" |
|---|
| 460 | fi |
|---|
| 461 | sleep $DELAY |
|---|
| 462 | if [ $? -ne 0 ] |
|---|
| 463 | then |
|---|
| 464 | echo '^C received, aborting...' |
|---|
| 465 | exit 1 |
|---|
| 466 | fi |
|---|
| 467 | # this will return the first field if there's only one (sysfs) |
|---|
| 468 | S=`cat $j | cut -d' ' -f2` |
|---|
| 469 | if [ $S -lt $threshold ] |
|---|
| 470 | then |
|---|
| 471 | echo " Fan $j has not returned to speed, please investigate!" |
|---|
| 472 | else |
|---|
| 473 | echo -n "Would you like to generate a detailed correlation (y)? " |
|---|
| 474 | read X |
|---|
| 475 | if [ "$X" = "y" -o "$X" = "Y" -o "$X" = "" ] |
|---|
| 476 | then |
|---|
| 477 | pwmdetail $i $j |
|---|
| 478 | fi |
|---|
| 479 | fi |
|---|
| 480 | else |
|---|
| 481 | echo " no correlation" |
|---|
| 482 | fi |
|---|
| 483 | let count=count+1 |
|---|
| 484 | done |
|---|
| 485 | echo |
|---|
| 486 | if [ "$pwmactivecount" = "0" ] |
|---|
| 487 | then |
|---|
| 488 | echo "No correlations were detected." |
|---|
| 489 | echo "There is either no fan connected to the output of $i," |
|---|
| 490 | echo "or the connected fan has no rpm-signal connected to one of" |
|---|
| 491 | echo "the tested fan sensors. (Note: not all motherboards have" |
|---|
| 492 | echo "the pwm outputs connected to the fan connectors," |
|---|
| 493 | echo "check out the hardware database on http://www.almico.com/forumindex.php)" |
|---|
| 494 | echo |
|---|
| 495 | echo -n "Did you see/hear a fan stopping during the above test (n)? " |
|---|
| 496 | read X |
|---|
| 497 | if [ "$X" = "y" -o "$X" = "Y" ] |
|---|
| 498 | then |
|---|
| 499 | pwmactive="$i ${pwmactive}" |
|---|
| 500 | fi |
|---|
| 501 | echo |
|---|
| 502 | fi |
|---|
| 503 | done |
|---|
| 504 | |
|---|
| 505 | |
|---|
| 506 | echo 'Testing is complete.' |
|---|
| 507 | echo 'Please verify that all fans have returned to their normal speed.' |
|---|
| 508 | echo |
|---|
| 509 | echo 'The fancontrol script can automatically respond to temperature changes' |
|---|
| 510 | echo 'of your system by changing fanspeeds.' |
|---|
| 511 | echo -n 'Do you want to set up its configuration file now (y)? ' |
|---|
| 512 | |
|---|
| 513 | read X |
|---|
| 514 | if [ "$X" = "n" -o "$X" = "N" ] |
|---|
| 515 | then |
|---|
| 516 | exit |
|---|
| 517 | fi |
|---|
| 518 | |
|---|
| 519 | if [ -n "$SYSFS" ] |
|---|
| 520 | then |
|---|
| 521 | MATCH=$PREFIX/'temp[1-9]_input' |
|---|
| 522 | else |
|---|
| 523 | MATCH=$PREFIX/'temp[1-9]' |
|---|
| 524 | fi |
|---|
| 525 | TEMPS=`echo $MATCH` |
|---|
| 526 | if [ "$MATCH" = "$TEMPS" ] |
|---|
| 527 | then |
|---|
| 528 | echo $0: 'There are no temperature-capable sensor modules installed' |
|---|
| 529 | exit 1 |
|---|
| 530 | fi |
|---|
| 531 | |
|---|
| 532 | function AskPath() |
|---|
| 533 | { |
|---|
| 534 | echo -n 'What should be the path to your fancontrol config file (/etc/fancontrol)? ' |
|---|
| 535 | |
|---|
| 536 | read FCCONFIG |
|---|
| 537 | if [ "$FCCONFIG" = "" ] |
|---|
| 538 | then |
|---|
| 539 | FCCONFIG="/etc/fancontrol" |
|---|
| 540 | fi |
|---|
| 541 | } |
|---|
| 542 | |
|---|
| 543 | AskPath |
|---|
| 544 | |
|---|
| 545 | function ClearConfig() |
|---|
| 546 | { |
|---|
| 547 | FCTEMPS="" |
|---|
| 548 | FCFANS="" |
|---|
| 549 | MINTEMP="" |
|---|
| 550 | MAXTEMP="" |
|---|
| 551 | MINSTART="" |
|---|
| 552 | MINSTOP="" |
|---|
| 553 | MINPWM="" |
|---|
| 554 | MAXPWM="" |
|---|
| 555 | } |
|---|
| 556 | |
|---|
| 557 | function LoadConfig() |
|---|
| 558 | { |
|---|
| 559 | # Nothing to do |
|---|
| 560 | if [ ! -f "$1" ] |
|---|
| 561 | then |
|---|
| 562 | ClearConfig |
|---|
| 563 | return 0 |
|---|
| 564 | fi |
|---|
| 565 | |
|---|
| 566 | echo "Loading configuration from $1 ..." |
|---|
| 567 | INTERVAL=`egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL= *//g'` |
|---|
| 568 | FCTEMPS=`egrep '^FCTEMPS=.*$' $1 | sed -e 's/FCTEMPS= *//g'` |
|---|
| 569 | FCFANS=`egrep '^FCFANS=.*$' $1 | sed -e 's/FCFANS= *//g'` |
|---|
| 570 | MINTEMP=`egrep '^MINTEMP=.*$' $1 | sed -e 's/MINTEMP= *//g'` |
|---|
| 571 | MAXTEMP=`egrep '^MAXTEMP=.*$' $1 | sed -e 's/MAXTEMP= *//g'` |
|---|
| 572 | MINSTART=`egrep '^MINSTART=.*$' $1 | sed -e 's/MINSTART= *//g'` |
|---|
| 573 | MINSTOP=`egrep '^MINSTOP=.*$' $1 | sed -e 's/MINSTOP= *//g'` |
|---|
| 574 | MINPWM=`egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM= *//g'` |
|---|
| 575 | MAXPWM=`egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM= *//g'` |
|---|
| 576 | |
|---|
| 577 | # Check for configuration change |
|---|
| 578 | local item |
|---|
| 579 | for item in $FCFANS |
|---|
| 580 | do |
|---|
| 581 | if [ ! -f "`echo $item | sed -e 's/=.*$//'`" ] |
|---|
| 582 | then |
|---|
| 583 | echo "Configuration appears to be outdated, discarded" |
|---|
| 584 | ClearConfig |
|---|
| 585 | return 0 |
|---|
| 586 | fi |
|---|
| 587 | done |
|---|
| 588 | } |
|---|
| 589 | |
|---|
| 590 | LoadConfig $FCCONFIG |
|---|
| 591 | |
|---|
| 592 | # $1 = pwm value below which the fan is stopped |
|---|
| 593 | function TestMinStart() |
|---|
| 594 | { |
|---|
| 595 | echo |
|---|
| 596 | echo 'Now we increase the PWM value in 10-unit-steps.' |
|---|
| 597 | echo 'Let the fan stop completely, then press return until the' |
|---|
| 598 | echo "fan starts spinning. Then enter 'y'." |
|---|
| 599 | echo 'We will use this value +20 as the starting speed.' |
|---|
| 600 | let fanok=0 |
|---|
| 601 | let fanval="$1" |
|---|
| 602 | |
|---|
| 603 | pwmenable $pwms |
|---|
| 604 | until [ "$fanok" = "1" ] |
|---|
| 605 | do |
|---|
| 606 | if [ $fanval -gt 240 ] ; then let fanval=$MAX ; let fanok=1 ; fi |
|---|
| 607 | echo -n "Setting $pwms to $fanval..." |
|---|
| 608 | pwmset $pwms $fanval |
|---|
| 609 | read FANTEST |
|---|
| 610 | if [ "$FANTEST" != "" ] ; then let fanok=1 ; fi |
|---|
| 611 | let fanval=fanval+10 |
|---|
| 612 | done |
|---|
| 613 | pwmdisable $pwms |
|---|
| 614 | |
|---|
| 615 | let fanval=fanval+20 |
|---|
| 616 | if [ $fanval -gt 240 ] ; then let fanval=$MAX ; fi |
|---|
| 617 | echo "OK, using $fanval" |
|---|
| 618 | } |
|---|
| 619 | |
|---|
| 620 | # $1 = fan input to read the fan speed from |
|---|
| 621 | function TestMinStop() |
|---|
| 622 | { |
|---|
| 623 | local faninput=$1 |
|---|
| 624 | local threshold=100000 |
|---|
| 625 | local fanspeed |
|---|
| 626 | |
|---|
| 627 | echo |
|---|
| 628 | echo 'Now we decrease the PWM value to figure out the lowest usable value.' |
|---|
| 629 | echo 'We will use a slightly greater value as the minimum speed.' |
|---|
| 630 | let fanval=$MAX |
|---|
| 631 | |
|---|
| 632 | pwmenable $pwms |
|---|
| 633 | while [ $fanval -ge 0 ] |
|---|
| 634 | do |
|---|
| 635 | pwmset $pwms $fanval |
|---|
| 636 | sleep $PDELAY |
|---|
| 637 | fanspeed=`cat $faninput | cut -d' ' -f2` |
|---|
| 638 | if [ $fanspeed -gt $threshold ] |
|---|
| 639 | then |
|---|
| 640 | echo " PWM $fanval -> $fanspeed RPM (probably incorrect)" |
|---|
| 641 | break |
|---|
| 642 | else |
|---|
| 643 | echo " PWM $fanval -> $fanspeed RPM" |
|---|
| 644 | if [ $fanspeed = "0" -o $fanspeed = "-1" ] |
|---|
| 645 | then |
|---|
| 646 | break |
|---|
| 647 | fi |
|---|
| 648 | let threshold=fanspeed*6/5 |
|---|
| 649 | fi |
|---|
| 650 | if [ $fanval -lt $STEP2_BELOW ] |
|---|
| 651 | then |
|---|
| 652 | let fanval=$fanval-$STEP2 |
|---|
| 653 | else |
|---|
| 654 | let fanval=$fanval-$STEP |
|---|
| 655 | fi |
|---|
| 656 | done |
|---|
| 657 | pwmdisable $pwms |
|---|
| 658 | |
|---|
| 659 | if [ $fanval -lt $STEP2_BELOW ] |
|---|
| 660 | then |
|---|
| 661 | let 'fanval=fanval+2*STEP2' |
|---|
| 662 | else |
|---|
| 663 | let 'fanval=fanval+STEP' |
|---|
| 664 | fi |
|---|
| 665 | echo "OK, using $fanval" |
|---|
| 666 | } |
|---|
| 667 | |
|---|
| 668 | function SaveConfig() |
|---|
| 669 | { |
|---|
| 670 | echo |
|---|
| 671 | echo "Saving configuration to $FCCONFIG..." |
|---|
| 672 | tmpfile=`mktemp -t pwmcfg.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1; } |
|---|
| 673 | trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15 |
|---|
| 674 | echo "# Configuration file generated by pwmconfig, changes will be lost" >$tmpfile |
|---|
| 675 | echo -e "INTERVAL=$INTERVAL\nFCTEMPS=$FCTEMPS\nFCFANS=$FCFANS\nMINTEMP=$MINTEMP\nMAXTEMP=$MAXTEMP\nMINSTART=$MINSTART\nMINSTOP=$MINSTOP" >>$tmpfile |
|---|
| 676 | [ -n "$MINPWM" ] && echo "MINPWM=$MINPWM" >>$tmpfile |
|---|
| 677 | [ -n "$MAXPWM" ] && echo "MAXPWM=$MAXPWM" >>$tmpfile |
|---|
| 678 | mv $tmpfile $FCCONFIG |
|---|
| 679 | chmod +r $FCCONFIG |
|---|
| 680 | #check if file was written correctly |
|---|
| 681 | echo 'Configuration saved' |
|---|
| 682 | } |
|---|
| 683 | |
|---|
| 684 | INTERVAL=10 |
|---|
| 685 | PS3='select (1-n): ' |
|---|
| 686 | DEFMINTEMP=20 |
|---|
| 687 | DEFMAXTEMP=60 |
|---|
| 688 | DEFMINSTART=150 |
|---|
| 689 | DEFMINSTOP=100 |
|---|
| 690 | |
|---|
| 691 | function filter_cfgvar() |
|---|
| 692 | { |
|---|
| 693 | echo "$1" | sed -e 's/ /\n/g' \ |
|---|
| 694 | | egrep "$2" \ |
|---|
| 695 | | sed -e 's/.*=//g' |
|---|
| 696 | } |
|---|
| 697 | |
|---|
| 698 | # "select" won't repeat the list of options, so we enclose it in a |
|---|
| 699 | # never-ending loop so that it starts over again with each iteration. |
|---|
| 700 | # I admit it's not exactly nice, but I do not have a better idea to |
|---|
| 701 | # keep usability at an acceptable level. |
|---|
| 702 | while [ 1 ] ; do |
|---|
| 703 | echo |
|---|
| 704 | echo 'Select fan output to configure, or other action:' |
|---|
| 705 | select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show configuration"; do |
|---|
| 706 | case $pwms in |
|---|
| 707 | "Change INTERVAL") |
|---|
| 708 | echo |
|---|
| 709 | echo "Current interval is $INTERVAL seconds." |
|---|
| 710 | echo -n "Enter the interval at which fancontrol should update PWM values (in s): " |
|---|
| 711 | read INTERVAL #check user input here |
|---|
| 712 | break ;; |
|---|
| 713 | "Just quit") |
|---|
| 714 | exit ;; |
|---|
| 715 | "Save and quit") |
|---|
| 716 | SaveConfig |
|---|
| 717 | exit ;; |
|---|
| 718 | "Show configuration") |
|---|
| 719 | echo |
|---|
| 720 | echo "Common Settings:" |
|---|
| 721 | echo "INTERVAL=$INTERVAL" |
|---|
| 722 | for pwmo in $pwmactive |
|---|
| 723 | do |
|---|
| 724 | echo |
|---|
| 725 | echo "Settings of ${pwmo}:" |
|---|
| 726 | echo " Depends on `filter_cfgvar "$FCTEMPS" "$pwmo"`" |
|---|
| 727 | echo " Controls `filter_cfgvar "$FCFANS" "$pwmo"`" |
|---|
| 728 | echo " MINTEMP=`filter_cfgvar "$MINTEMP" $pwmo`" |
|---|
| 729 | echo " MAXTEMP=`filter_cfgvar "$MAXTEMP" "$pwmo"`" |
|---|
| 730 | echo " MINSTART=`filter_cfgvar "$MINSTART" "$pwmo"`" |
|---|
| 731 | echo " MINSTOP=`filter_cfgvar "$MINSTOP" "$pwmo"`" |
|---|
| 732 | XMINP=`filter_cfgvar "$MINPWM" "$pwmo"` |
|---|
| 733 | [ -n "$XMINP" ] && echo " MINPWM=$XMINP" |
|---|
| 734 | XMAXP=`filter_cfgvar "$MAXPWM" "$pwmo"` |
|---|
| 735 | [ -n "$XMAXP" ] && echo " MAXPWM=$XMAXP" |
|---|
| 736 | done |
|---|
| 737 | echo |
|---|
| 738 | break ;; |
|---|
| 739 | |
|---|
| 740 | "`echo ${pwmactive} |sed -e 's/ /\n/g' | egrep "${pwms}"`" ) |
|---|
| 741 | pwmsed=`echo ${pwms} | sed -e 's/\//\\\\\//g'` #escape / for sed |
|---|
| 742 | echo |
|---|
| 743 | if [ -n "$SYSFS" ] |
|---|
| 744 | then |
|---|
| 745 | echo 'Devices:' |
|---|
| 746 | print_devices "" |
|---|
| 747 | echo |
|---|
| 748 | fi |
|---|
| 749 | echo 'Current temperature readings are as follows:' |
|---|
| 750 | for j in $TEMPS |
|---|
| 751 | do |
|---|
| 752 | # this will return the first field if there's only one (sysfs) |
|---|
| 753 | S=`cat $j | cut -d' ' -f3` |
|---|
| 754 | if [ -n "$SYSFS" ] |
|---|
| 755 | then |
|---|
| 756 | let S="$S / 1000" |
|---|
| 757 | fi |
|---|
| 758 | echo "$j $S" |
|---|
| 759 | done |
|---|
| 760 | FAN=`echo $fanactive|cut -d' ' -f$REPLY` |
|---|
| 761 | FAN_MIN=`echo $fanactive_min|cut -d' ' -f$REPLY` |
|---|
| 762 | FCFANS="`echo $FCFANS | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=$FAN" |
|---|
| 763 | echo |
|---|
| 764 | echo "Select a temperature sensor as source for ${pwms}:" |
|---|
| 765 | select tempss in $TEMPS "None (Do not affect this PWM output)"; do |
|---|
| 766 | if [ "$tempss" = "None (Do not affect this PWM output)" ] |
|---|
| 767 | then |
|---|
| 768 | |
|---|
| 769 | break; |
|---|
| 770 | else |
|---|
| 771 | if [ "$FCTEMPS" = "" ] |
|---|
| 772 | then |
|---|
| 773 | FCTEMPS="${pwms}=${tempss}" |
|---|
| 774 | else |
|---|
| 775 | FCTEMPS="`echo $FCTEMPS | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${tempss}" |
|---|
| 776 | fi |
|---|
| 777 | fi |
|---|
| 778 | echo |
|---|
| 779 | echo 'Enter the low temperature (degree C)' |
|---|
| 780 | echo -n "below which the fan should spin at minimum speed ($DEFMINTEMP): " |
|---|
| 781 | read XMT |
|---|
| 782 | if [ "$XMT" = "" ] |
|---|
| 783 | then |
|---|
| 784 | XMT=$DEFMINTEMP |
|---|
| 785 | fi |
|---|
| 786 | if [ "$MINTEMP" = "" ] |
|---|
| 787 | then |
|---|
| 788 | MINTEMP="${pwms}=${XMT}" |
|---|
| 789 | else |
|---|
| 790 | MINTEMP="`echo $MINTEMP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMT}" |
|---|
| 791 | fi |
|---|
| 792 | echo |
|---|
| 793 | echo 'Enter the high temperature (degree C)' |
|---|
| 794 | echo -n "over which the fan should spin at maximum speed ($DEFMAXTEMP): " |
|---|
| 795 | read XMT |
|---|
| 796 | if [ "$XMT" = "" ] |
|---|
| 797 | then |
|---|
| 798 | XMT=$DEFMAXTEMP |
|---|
| 799 | fi |
|---|
| 800 | if [ "$MAXTEMP" = "" ] |
|---|
| 801 | then |
|---|
| 802 | MAXTEMP="${pwms}=${XMT}" |
|---|
| 803 | else |
|---|
| 804 | MAXTEMP="`echo $MAXTEMP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMT}" |
|---|
| 805 | fi |
|---|
| 806 | |
|---|
| 807 | if [ $FAN_MIN -eq 0 ] |
|---|
| 808 | then |
|---|
| 809 | echo |
|---|
| 810 | echo "Enter the minimum PWM value (0-$MAX)" |
|---|
| 811 | echo -n "at which the fan STOPS spinning (press t to test) ($DEFMINSTOP): " |
|---|
| 812 | read XMSTOP |
|---|
| 813 | |
|---|
| 814 | if [ "$XMSTOP" = "" ] |
|---|
| 815 | then |
|---|
| 816 | XMSTOP=$DEFMINSTOP |
|---|
| 817 | fi |
|---|
| 818 | if [ "$XMSTOP" = "t" -o "$XMSTOP" = "T" ] |
|---|
| 819 | then |
|---|
| 820 | TestMinStop $FAN |
|---|
| 821 | XMSTOP=$fanval |
|---|
| 822 | fi |
|---|
| 823 | else |
|---|
| 824 | XMSTOP=0 |
|---|
| 825 | fi |
|---|
| 826 | if [ "$MINSTOP" = "" ] |
|---|
| 827 | then |
|---|
| 828 | MINSTOP="${pwms}=${XMSTOP}" |
|---|
| 829 | else |
|---|
| 830 | MINSTOP="`echo $MINSTOP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMSTOP}" |
|---|
| 831 | fi |
|---|
| 832 | |
|---|
| 833 | if [ $FAN_MIN -eq 0 ] |
|---|
| 834 | then |
|---|
| 835 | echo |
|---|
| 836 | echo "Enter the minimum PWM value ($XMSTOP-$MAX)" |
|---|
| 837 | echo -n "at which the fan STARTS spinning (press t to test) ($DEFMINSTART): " |
|---|
| 838 | read XMSTART |
|---|
| 839 | |
|---|
| 840 | if [ "$XMSTART" = "" ] |
|---|
| 841 | then |
|---|
| 842 | XMSTART=$DEFMINSTART |
|---|
| 843 | fi |
|---|
| 844 | if [ "$XMSTART" = "t" -o "$XMSTART" = "T" ] |
|---|
| 845 | then |
|---|
| 846 | TestMinStart $XMSTOP |
|---|
| 847 | XMSTART=$fanval |
|---|
| 848 | fi |
|---|
| 849 | else |
|---|
| 850 | XMSTART=$DEFMINSTART |
|---|
| 851 | fi |
|---|
| 852 | if [ "$MINSTART" = "" ] |
|---|
| 853 | then |
|---|
| 854 | MINSTART="${pwms}=${XMSTART}" |
|---|
| 855 | else |
|---|
| 856 | MINSTART="`echo $MINSTART | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMSTART}" |
|---|
| 857 | fi |
|---|
| 858 | |
|---|
| 859 | if [ $XMSTOP -gt 0 ] |
|---|
| 860 | then |
|---|
| 861 | echo |
|---|
| 862 | echo "Enter the PWM value (0-$XMSTOP) to use when the temperature" |
|---|
| 863 | echo -n "is below the low temperature limit (0): " |
|---|
| 864 | read XMINP |
|---|
| 865 | else |
|---|
| 866 | XMINP="" |
|---|
| 867 | fi |
|---|
| 868 | if [ -n "$XMINP" ] |
|---|
| 869 | then |
|---|
| 870 | if [ "$MINPWM" = "" ] |
|---|
| 871 | then |
|---|
| 872 | MINPWM="${pwms}=${XMINP}" |
|---|
| 873 | else |
|---|
| 874 | MINPWM="`echo $MINPWM | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMINP}" |
|---|
| 875 | fi |
|---|
| 876 | fi |
|---|
| 877 | echo |
|---|
| 878 | echo "Enter the PWM value ($XMSTOP-$MAX) to use when the temperature" |
|---|
| 879 | echo -n "is over the high temperature limit ($MAX): " |
|---|
| 880 | read XMAXP |
|---|
| 881 | if [ -n "$XMAXP" ] |
|---|
| 882 | then |
|---|
| 883 | if [ "$MAXPWM" = "" ] |
|---|
| 884 | then |
|---|
| 885 | MAXPWM="${pwms}=${XMAXP}" |
|---|
| 886 | else |
|---|
| 887 | MAXPWM="`echo $MAXPWM | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMAXP}" |
|---|
| 888 | fi |
|---|
| 889 | fi |
|---|
| 890 | echo |
|---|
| 891 | break; |
|---|
| 892 | done |
|---|
| 893 | break ;; |
|---|
| 894 | |
|---|
| 895 | *) |
|---|
| 896 | echo "No such option. Enter a number." |
|---|
| 897 | break ;; |
|---|
| 898 | esac |
|---|
| 899 | done |
|---|
| 900 | done |
|---|