root/lm-sensors/trunk/prog/pwm/pwmconfig @ 5749

Revision 5749, 20.4 KB (checked in by khali, 4 years ago)

Exit immediately if not root.

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