Ticket #2289: pwmconfig

File pwmconfig, 18.9 kB (added by khali, 1 year ago)

Modified version of pwmconfig

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