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

Revision 5767, 20.5 KB (checked in by khali, 4 years ago)

Clean up the code writing the configuration file.

  • 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 "INTERVAL=$INTERVAL" >>$tmpfile
686        echo "FCTEMPS=$FCTEMPS" >>$tmpfile
687        echo "FCFANS=$FCFANS" >>$tmpfile
688        echo "MINTEMP=$MINTEMP" >>$tmpfile
689        echo "MAXTEMP=$MAXTEMP" >>$tmpfile
690        echo "MINSTART=$MINSTART" >>$tmpfile
691        echo "MINSTOP=$MINSTOP" >>$tmpfile
692        [ -n "$MINPWM" ] && echo "MINPWM=$MINPWM" >>$tmpfile
693        [ -n "$MAXPWM" ] && echo "MAXPWM=$MAXPWM" >>$tmpfile
694        mv $tmpfile $FCCONFIG
695        chmod +r $FCCONFIG
696        #check if file was written correctly
697        echo 'Configuration saved'
698}
699
700INTERVAL=10
701PS3='select (1-n): '
702DEFMINTEMP=20
703DEFMAXTEMP=60
704DEFMINSTART=150
705DEFMINSTOP=100
706
707function filter_cfgvar()
708{
709        echo "$1" | sed -e 's/ /\n/g' \
710                  | egrep "$2" \
711                  | sed -e 's/.*=//g'
712}
713
714# "select" won't repeat the list of options, so we enclose it in a
715# never-ending loop so that it starts over again with each iteration.
716# I admit it's not exactly nice, but I do not have a better idea to
717# keep usability at an acceptable level.
718while [ 1 ] ; do
719echo
720echo 'Select fan output to configure, or other action:'
721select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show configuration"; do
722        case $pwms in
723        "Change INTERVAL")
724                echo
725                echo "Current interval is $INTERVAL seconds."
726                echo -n "Enter the interval at which fancontrol should update PWM values (in s): "
727                read INTERVAL #check user input here
728                break ;;
729        "Just quit")
730                exit ;;
731        "Save and quit")
732                SaveConfig
733                exit ;;
734        "Show configuration")
735                echo
736                echo "Common Settings:"
737                echo "INTERVAL=$INTERVAL"
738                for pwmo in $pwmactive
739                do
740                        echo
741                        echo "Settings of ${pwmo}:"
742                        echo "  Depends on `filter_cfgvar "$FCTEMPS" "$pwmo"`"
743                        echo "  Controls `filter_cfgvar "$FCFANS" "$pwmo"`"
744                        echo "  MINTEMP=`filter_cfgvar "$MINTEMP" $pwmo`"
745                        echo "  MAXTEMP=`filter_cfgvar "$MAXTEMP" "$pwmo"`"
746                        echo "  MINSTART=`filter_cfgvar "$MINSTART" "$pwmo"`"
747                        echo "  MINSTOP=`filter_cfgvar "$MINSTOP" "$pwmo"`"
748                        XMINP=`filter_cfgvar "$MINPWM" "$pwmo"`
749                        [ -n "$XMINP" ] && echo "  MINPWM=$XMINP"
750                        XMAXP=`filter_cfgvar "$MAXPWM" "$pwmo"`
751                        [ -n "$XMAXP" ] && echo "  MAXPWM=$XMAXP"
752                done
753                echo
754                break ;;
755
756        "`echo ${pwmactive} |sed -e 's/ /\n/g' | egrep "${pwms}"`" )
757                pwmsed=`echo ${pwms} | sed -e 's/\//\\\\\//g'` #escape / for sed
758                echo
759
760                echo 'Devices:'
761                print_devices ""
762                echo
763
764                echo 'Current temperature readings are as follows:'
765                for j in $TEMPS
766                do
767                        S=`cat $j`
768                        let S="$S / 1000"
769                        echo "$j        $S"
770                done
771                FAN=`echo $fanactive|cut -d' ' -f$REPLY`
772                FAN_MIN=`echo $fanactive_min|cut -d' ' -f$REPLY`
773                FCFANS="`echo $FCFANS | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=$FAN"
774                echo
775                echo "Select a temperature sensor as source for ${pwms}:"
776                select tempss in $TEMPS "None (Do not affect this PWM output)"; do
777                        if [ "$tempss" = "None (Do not affect this PWM output)" ]
778                        then
779
780                                break;
781                        else
782                                if [ "$FCTEMPS" = "" ]
783                                then
784                                        FCTEMPS="${pwms}=${tempss}"
785                                else
786                                        FCTEMPS="`echo $FCTEMPS | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${tempss}"
787                                fi
788                        fi
789                        echo
790                        echo 'Enter the low temperature (degree C)'
791                        echo -n "below which the fan should spin at minimum speed ($DEFMINTEMP): "
792                        read XMT
793                        if [ "$XMT" = "" ]
794                        then
795                                XMT=$DEFMINTEMP
796                        fi
797                        if [ "$MINTEMP" = "" ]
798                        then
799                                MINTEMP="${pwms}=${XMT}"
800                        else
801                                MINTEMP="`echo $MINTEMP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMT}"
802                        fi
803                        echo
804                        echo 'Enter the high temperature (degree C)'
805                        echo -n "over which the fan should spin at maximum speed ($DEFMAXTEMP): "
806                        read XMT
807                        if [ "$XMT" = "" ]
808                        then
809                                XMT=$DEFMAXTEMP
810                        fi
811                        if [ "$MAXTEMP" = "" ]
812                        then
813                                MAXTEMP="${pwms}=${XMT}"
814                        else
815                                MAXTEMP="`echo $MAXTEMP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMT}"
816                        fi
817
818                        if [ $FAN_MIN -eq 0 ]
819                        then
820                                echo
821                                echo "Enter the minimum PWM value (0-$MAX)"
822                                echo -n "at which the fan STOPS spinning (press t to test) ($DEFMINSTOP): "
823                                read XMSTOP
824
825                                if [ "$XMSTOP" = "" ]
826                                then
827                                        XMSTOP=$DEFMINSTOP
828                                fi
829                                if [ "$XMSTOP" = "t" -o "$XMSTOP" = "T" ]
830                                then
831                                        TestMinStop $FAN
832                                        XMSTOP=$fanval
833                                fi
834                        else
835                                XMSTOP=0
836                        fi
837                        if [ "$MINSTOP" = "" ]
838                        then
839                                MINSTOP="${pwms}=${XMSTOP}"
840                        else
841                                MINSTOP="`echo $MINSTOP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMSTOP}"
842                        fi
843
844                        if [ $FAN_MIN -eq 0 ]
845                        then
846                                echo
847                                echo "Enter the minimum PWM value ($XMSTOP-$MAX)"
848                                echo -n "at which the fan STARTS spinning (press t to test) ($DEFMINSTART): "
849                                read XMSTART
850
851                                if [ "$XMSTART" = "" ]
852                                then
853                                        XMSTART=$DEFMINSTART
854                                fi
855                                if [ "$XMSTART" = "t" -o "$XMSTART" = "T" ]
856                                then
857                                        TestMinStart $XMSTOP
858                                        XMSTART=$fanval
859                                fi
860                        else
861                                XMSTART=$DEFMINSTART
862                        fi
863                        if [ "$MINSTART" = "" ]
864                        then
865                                MINSTART="${pwms}=${XMSTART}"
866                        else
867                                MINSTART="`echo $MINSTART | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMSTART}"
868                        fi
869
870                        if [ $XMSTOP -gt 0 ]
871                        then
872                                echo
873                                echo "Enter the PWM value (0-$XMSTOP) to use when the temperature"
874                                echo -n "is below the low temperature limit (0): "
875                                read XMINP
876                        else
877                                XMINP=""
878                        fi
879                        if [ -n "$XMINP" ]
880                        then
881                                if [ "$MINPWM" = "" ]
882                                then
883                                        MINPWM="${pwms}=${XMINP}"
884                                else
885                                        MINPWM="`echo $MINPWM | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMINP}"
886                                fi
887                        fi
888                        echo
889                        echo "Enter the PWM value ($XMSTOP-$MAX) to use when the temperature"
890                        echo -n "is over the high temperature limit ($MAX): "
891                        read XMAXP
892                        if [ -n "$XMAXP" ]
893                        then
894                                if [ "$MAXPWM" = "" ]
895                                then
896                                        MAXPWM="${pwms}=${XMAXP}"
897                                else
898                                        MAXPWM="`echo $MAXPWM | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMAXP}"
899                                fi
900                        fi
901                        echo
902                        break;
903                done
904                break ;;
905
906        *)
907                echo "No such option. Enter a number."
908                break ;;
909        esac
910done
911done
Note: See TracBrowser for help on using the browser.