2
0
mirror of https://github.com/lm-sensors/lm-sensors synced 2025-09-02 23:35:57 +00:00

Update pwmconfig

replaced deprecated sub shell syntax

Signed-off-by: Guenter Roeck <linux@roeck-us.net>
This commit is contained in:
jschwender
2018-03-09 22:53:53 +01:00
committed by Guenter Roeck
parent 33463a1c77
commit 3daae37d58

View File

@@ -42,7 +42,7 @@ then
exit 1 exit 1
fi fi
if [ "`id -u`" != "0" ] if [ "$(id -u)" != "0" ]
then then
echo "You need to be root to run this script." echo "You need to be root to run this script."
exit 1 exit 1
@@ -80,7 +80,7 @@ else
fi fi
cd $DIR cd $DIR
DEVICES=`echo $PREFIX` DEVICES=$(echo $PREFIX)
if [ "$PREFIX" = "$DEVICES" ] if [ "$PREFIX" = "$DEVICES" ]
then then
echo $0: 'No sensors found! (modprobe sensor modules?)' echo $0: 'No sensors found! (modprobe sensor modules?)'
@@ -109,12 +109,12 @@ for device in $DEVICES
do do
# Find available fan control outputs # Find available fan control outputs
MATCH=$device/'pwm[1-9]' MATCH=$device/'pwm[1-9]'
device_pwm=`echo $MATCH` device_pwm=$(echo $MATCH)
if [ "$SYSFS" = "1" -a "$MATCH" = "$device_pwm" ] if [ "$SYSFS" = "1" -a "$MATCH" = "$device_pwm" ]
then then
# Deprecated naming scheme (used in kernels 2.6.5 to 2.6.9) # Deprecated naming scheme (used in kernels 2.6.5 to 2.6.9)
MATCH=$device/'fan[1-9]_pwm' MATCH=$device/'fan[1-9]_pwm'
device_pwm=`echo $MATCH` device_pwm=$(echo $MATCH)
fi fi
if [ "$MATCH" != "$device_pwm" ] if [ "$MATCH" != "$device_pwm" ]
then then
@@ -123,7 +123,7 @@ do
# Find available fan monitoring inputs # Find available fan monitoring inputs
MATCH=$device/'fan[1-9]_input' MATCH=$device/'fan[1-9]_input'
device_fan=`echo $MATCH` device_fan=$(echo $MATCH)
if [ "$MATCH" != "$device_fan" ] if [ "$MATCH" != "$device_fan" ]
then then
FAN="$FAN $device_fan" FAN="$FAN $device_fan"
@@ -148,7 +148,7 @@ function print_devices()
for device in $DEVICES for device in $DEVICES
do do
name=`cat $device/name 2> /dev/null` name=$(cat $device/name 2> /dev/null)
[ -z "$name" ] && name="unknown (no name attribute)" [ -z "$name" ] && name="unknown (no name attribute)"
echo "$1$device is $name" echo "$1$device is $name"
done done
@@ -161,7 +161,7 @@ function is_pwm_auto()
if [ -f $ENABLE ] if [ -f $ENABLE ]
then then
if [ "`cat $ENABLE`" -gt 1 ] if [ "$(cat $ENABLE)" -gt 1 ]
then then
return 0 return 0
fi fi
@@ -184,7 +184,7 @@ function pwmdisable()
# Try pwmN_enable=0 # Try pwmN_enable=0
echo 0 2>/dev/null > $ENABLE echo 0 2>/dev/null > $ENABLE
if [ "`cat $ENABLE`" -eq 0 ] if [ "$(cat $ENABLE)" -eq 0 ]
then then
# Success # Success
return 0 return 0
@@ -192,21 +192,21 @@ function pwmdisable()
# It didn't work, try pwmN_enable=1 pwmN=255 # It didn't work, try pwmN_enable=1 pwmN=255
echo 1 2>/dev/null > $ENABLE echo 1 2>/dev/null > $ENABLE
if [ "`cat $ENABLE`" -ne 1 ] if [ "$(cat $ENABLE)" -ne 1 ]
then then
echo "$ENABLE stuck to `cat $ENABLE`" >&2 echo "$ENABLE stuck to $(cat $ENABLE)" >&2
return 1 return 1
fi fi
echo $MAX > $1 echo $MAX > $1
if [ "`cat $1`" -ge 190 ] if [ "$(cat $1)" -ge 190 ]
then then
# Success # Success
return 0 return 0
fi fi
# Nothing worked # Nothing worked
echo "$1 stuck to `cat $1`" >&2 echo "$1 stuck to $(cat $1)" >&2
return 1 return 1
} }
@@ -239,7 +239,7 @@ echo
echo 'Found the following PWM controls:' echo 'Found the following PWM controls:'
for i in $PWM for i in $PWM
do do
P=`cat $i` P=$(cat $i)
echo " $i current value: $P" echo " $i current value: $P"
if [ -w $i ] if [ -w $i ]
then then
@@ -284,7 +284,7 @@ sleep $DELAY
echo 'Found the following fan sensors:' echo 'Found the following fan sensors:'
for i in $FAN for i in $FAN
do do
S=`cat $i` S=$(cat $i)
if [ "$S" = "0" -o "$S" = "-1" ] if [ "$S" = "0" -o "$S" = "-1" ]
then then
echo " $i current speed: 0 ... skipping!" echo " $i current speed: 0 ... skipping!"
@@ -351,8 +351,8 @@ function pwmdetail()
if [ "$PLOT" = "y" ] if [ "$PLOT" = "y" ]
then then
TMP1=`mktemp -t pwmtest1.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1; } TMP1=$(mktemp -t pwmtest1.XXXXXXXXXX) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
TMP2=`mktemp -t pwmtest2.XXXXXXXXXX` || { rm -f $TMP1 ; echo "$0: Cannot create temporary file" >&2; exit 1; } TMP2=$(mktemp -t pwmtest2.XXXXXXXXXX) || { rm -f $TMP1 ; echo "$0: Cannot create temporary file" >&2; exit 1; }
echo "set xlabel \"PWM: $P\"" > $TMP1 echo "set xlabel \"PWM: $P\"" > $TMP1
echo "set ylabel \"FAN: $F (RPM)\"" >> $TMP1 echo "set ylabel \"FAN: $F (RPM)\"" >> $TMP1
echo 'set nokey' >> $TMP1 echo 'set nokey' >> $TMP1
@@ -375,7 +375,7 @@ function pwmdetail()
rm -f $TMP1 $TMP2 rm -f $TMP1 $TMP2
exit 1 exit 1
fi fi
S=`cat $F` S=$(cat $F)
# Fan speed should never increase significantly # Fan speed should never increase significantly
if [ $S -gt $threshold ] if [ $S -gt $threshold ]
then then
@@ -441,7 +441,7 @@ do
# Sample all current fan speeds at once, so that we can quickly # Sample all current fan speeds at once, so that we can quickly
# disable PWM and return all fans to full speed # disable PWM and return all fans to full speed
CURRENT_SPEEDS="`cat $GOODFAN`" CURRENT_SPEEDS="$(cat $GOODFAN)"
pwmdisable $i pwmdisable $i
let pwmactivecount=0 let pwmactivecount=0
@@ -449,8 +449,8 @@ do
S_MIN= S_MIN=
for j in $GOODFAN for j in $GOODFAN
do do
OS=`echo $SPEEDS | cut -d' ' -f$count` OS=$(echo $SPEEDS | cut -d' ' -f$count)
S=`echo $CURRENT_SPEEDS | cut -d' ' -f$count` S=$(echo $CURRENT_SPEEDS | cut -d' ' -f$count)
echo " $j ... speed was $OS now $S" echo " $j ... speed was $OS now $S"
let threshold=3*$OS/4 let threshold=3*$OS/4
if [ $S -lt $threshold ] if [ $S -lt $threshold ]
@@ -483,7 +483,7 @@ do
S_MIN=$S S_MIN=$S
fi fi
S=`cat $j` S=$(cat $j)
if [ $S -lt $threshold ] if [ $S -lt $threshold ]
then then
echo " Fan $j has not returned to speed, please investigate!" echo " Fan $j has not returned to speed, please investigate!"
@@ -541,7 +541,7 @@ for device in $DEVICES
do do
# Find available temperature monitoring inputs # Find available temperature monitoring inputs
MATCH=$device/'temp[1-9]_input' MATCH=$device/'temp[1-9]_input'
device_temp=`echo $MATCH` device_temp=$(echo $MATCH)
if [ "$MATCH" != "$device_temp" ] if [ "$MATCH" != "$device_temp" ]
then then
TEMPS="$TEMPS $device_temp" TEMPS="$TEMPS $device_temp"
@@ -580,10 +580,10 @@ function ValidateDevices()
for entry in $OLD_DEVPATH for entry in $OLD_DEVPATH
do do
device=`echo "$entry" | sed -e 's/=[^=]*$//'` device=$(echo "$entry" | sed -e 's/=[^=]*$//')
path=`echo "$entry" | sed -e 's/^[^=]*=//'` path=$(echo "$entry" | sed -e 's/^[^=]*=//')
if [ "`DevicePath "$device"`" != "$path" ] if [ "$(DevicePath "$device")" != "$path" ]
then then
echo "Device path of $device has changed" echo "Device path of $device has changed"
outdated=1 outdated=1
@@ -592,10 +592,10 @@ function ValidateDevices()
for entry in $OLD_DEVNAME for entry in $OLD_DEVNAME
do do
device=`echo "$entry" | sed -e 's/=[^=]*$//'` device=$(echo "$entry" | sed -e 's/=[^=]*$//')
name=`echo "$entry" | sed -e 's/^[^=]*=//'` name=$(echo "$entry" | sed -e 's/^[^=]*=//')
if [ "`DeviceName "$device"`" != "$name" ] if [ "$(DeviceName "$device")" != "$name" ]
then then
echo "Device name of $device has changed" echo "Device name of $device has changed"
outdated=1 outdated=1
@@ -642,17 +642,17 @@ function LoadConfig()
fi fi
echo "Loading configuration from $1 ..." echo "Loading configuration from $1 ..."
INTERVAL=`egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL= *//g'` INTERVAL=$(egrep '^INTERVAL=.*$' $1 | sed -e 's/INTERVAL= *//g')
OLD_DEVPATH=`egrep '^DEVPATH=.*$' $1 | sed -e 's/DEVPATH= *//g'` OLD_DEVPATH=$(egrep '^DEVPATH=.*$' $1 | sed -e 's/DEVPATH= *//g')
OLD_DEVNAME=`egrep '^DEVNAME=.*$' $1 | sed -e 's/DEVNAME= *//g'` OLD_DEVNAME=$(egrep '^DEVNAME=.*$' $1 | sed -e 's/DEVNAME= *//g')
FCTEMPS=`egrep '^FCTEMPS=.*$' $1 | sed -e 's/FCTEMPS= *//g'` FCTEMPS=$(egrep '^FCTEMPS=.*$' $1 | sed -e 's/FCTEMPS= *//g')
FCFANS=`egrep '^FCFANS=.*$' $1 | sed -e 's/FCFANS= *//g'` FCFANS=$(egrep '^FCFANS=.*$' $1 | sed -e 's/FCFANS= *//g')
MINTEMP=`egrep '^MINTEMP=.*$' $1 | sed -e 's/MINTEMP= *//g'` MINTEMP=$(egrep '^MINTEMP=.*$' $1 | sed -e 's/MINTEMP= *//g')
MAXTEMP=`egrep '^MAXTEMP=.*$' $1 | sed -e 's/MAXTEMP= *//g'` MAXTEMP=$(egrep '^MAXTEMP=.*$' $1 | sed -e 's/MAXTEMP= *//g')
MINSTART=`egrep '^MINSTART=.*$' $1 | sed -e 's/MINSTART= *//g'` MINSTART=$(egrep '^MINSTART=.*$' $1 | sed -e 's/MINSTART= *//g')
MINSTOP=`egrep '^MINSTOP=.*$' $1 | sed -e 's/MINSTOP= *//g'` MINSTOP=$(egrep '^MINSTOP=.*$' $1 | sed -e 's/MINSTOP= *//g')
MINPWM=`egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM= *//g'` MINPWM=$(egrep '^MINPWM=.*$' $1 | sed -e 's/MINPWM= *//g')
MAXPWM=`egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM= *//g'` MAXPWM=$(egrep '^MAXPWM=.*$' $1 | sed -e 's/MAXPWM= *//g')
# Check for configuration change # Check for configuration change
if ! ValidateDevices "$OLD_DEVPATH" "$OLD_DEVNAME" if ! ValidateDevices "$OLD_DEVPATH" "$OLD_DEVNAME"
@@ -712,7 +712,7 @@ function TestMinStop()
do do
pwmset $pwms $fanval pwmset $pwms $fanval
sleep $PDELAY sleep $PDELAY
fanspeed=`cat $faninput` fanspeed=$(cat $faninput)
if [ $fanspeed -gt $threshold ] if [ $fanspeed -gt $threshold ]
then then
echo " PWM $fanval -> $fanspeed RPM (probably incorrect)" echo " PWM $fanval -> $fanspeed RPM (probably incorrect)"
@@ -754,13 +754,13 @@ function RememberDevices()
for device in $DEVICES for device in $DEVICES
do do
device=`echo "$device" | sed -e 's/\/.*$//'` device=$(echo "$device" | sed -e 's/\/.*$//')
used=0 used=0
for entry in $1 $2 for entry in $1 $2
do do
pwmdev=`echo "$entry" | sed -e 's/\/.*$//'` pwmdev=$(echo "$entry" | sed -e 's/\/.*$//')
tempfandev=`echo "$entry" | sed -e 's/^[^=]*=//' -e 's/\/.*$//'` tempfandev=$(echo "$entry" | sed -e 's/^[^=]*=//' -e 's/\/.*$//')
if [ "$device" = "$pwmdev" -o "$device" = "$tempfandev" ] if [ "$device" = "$pwmdev" -o "$device" = "$tempfandev" ]
then then
@@ -775,7 +775,7 @@ function RememberDevices()
# Record the device path and name. This lets the fancontrol # Record the device path and name. This lets the fancontrol
# script check that they didn't change. If they did, then the # script check that they didn't change. If they did, then the
# configuration file can no longer be trusted. # configuration file can no longer be trusted.
path=`DevicePath "$device"` path=$(DevicePath "$device")
if [ -z "$DEVPATH" ] if [ -z "$DEVPATH" ]
then then
DEVPATH="$device=$path" DEVPATH="$device=$path"
@@ -783,7 +783,7 @@ function RememberDevices()
DEVPATH="$DEVPATH $device=$path" DEVPATH="$DEVPATH $device=$path"
fi fi
name=`DeviceName "$device"` name=$(DeviceName "$device")
if [ -z "$DEVNAME" ] if [ -z "$DEVNAME" ]
then then
DEVNAME="$device=$name" DEVNAME="$device=$name"
@@ -801,7 +801,7 @@ function SaveConfig()
echo echo
echo "Saving configuration to $FCCONFIG..." echo "Saving configuration to $FCCONFIG..."
tmpfile=`mktemp -t pwmcfg.XXXXXXXXXX` || { echo "$0: Cannot create temporary file" >&2; exit 1; } tmpfile=$(mktemp -t pwmcfg.XXXXXXXXXX) || { echo "$0: Cannot create temporary file" >&2; exit 1; }
trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15 trap " [ -f \"$tmpfile\" ] && /bin/rm -f -- \"$tmpfile\"" 0 1 2 3 13 15
echo "# Configuration file generated by pwmconfig, changes will be lost" >$tmpfile echo "# Configuration file generated by pwmconfig, changes will be lost" >$tmpfile
echo "INTERVAL=$INTERVAL" >>$tmpfile echo "INTERVAL=$INTERVAL" >>$tmpfile
@@ -863,22 +863,22 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
do do
echo echo
echo "Settings of ${pwmo}:" echo "Settings of ${pwmo}:"
echo " Depends on `filter_cfgvar "$FCTEMPS" "$pwmo"`" echo " Depends on $(filter_cfgvar "$FCTEMPS" "$pwmo")"
echo " Controls `filter_cfgvar "$FCFANS" "$pwmo"`" echo " Controls $(filter_cfgvar "$FCFANS" "$pwmo")"
echo " MINTEMP=`filter_cfgvar "$MINTEMP" $pwmo`" echo " MINTEMP=$(filter_cfgvar "$MINTEMP" $pwmo)"
echo " MAXTEMP=`filter_cfgvar "$MAXTEMP" "$pwmo"`" echo " MAXTEMP=$(filter_cfgvar "$MAXTEMP" "$pwmo")"
echo " MINSTART=`filter_cfgvar "$MINSTART" "$pwmo"`" echo " MINSTART=$(filter_cfgvar "$MINSTART" "$pwmo")"
echo " MINSTOP=`filter_cfgvar "$MINSTOP" "$pwmo"`" echo " MINSTOP=$(filter_cfgvar "$MINSTOP" "$pwmo")"
XMINP=`filter_cfgvar "$MINPWM" "$pwmo"` XMINP=$(filter_cfgvar "$MINPWM" "$pwmo")
[ -n "$XMINP" ] && echo " MINPWM=$XMINP" [ -n "$XMINP" ] && echo " MINPWM=$XMINP"
XMAXP=`filter_cfgvar "$MAXPWM" "$pwmo"` XMAXP=$(filter_cfgvar "$MAXPWM" "$pwmo")
[ -n "$XMAXP" ] && echo " MAXPWM=$XMAXP" [ -n "$XMAXP" ] && echo " MAXPWM=$XMAXP"
done done
echo echo
break ;; break ;;
"`echo ${pwmactive} |sed -e 's/ /\n/g' | egrep "${pwms}"`" ) "$(echo ${pwmactive} |sed -e 's/ /\n/g' | egrep "${pwms}")" )
pwmsed=`echo ${pwms} | sed -e 's/\//\\\\\//g'` #escape / for sed pwmsed=$(echo ${pwms} | sed -e 's/\//\\\\\//g') #escape / for sed
echo echo
echo 'Devices:' echo 'Devices:'
@@ -888,13 +888,13 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
echo 'Current temperature readings are as follows:' echo 'Current temperature readings are as follows:'
for j in $TEMPS for j in $TEMPS
do do
S=`cat $j` S=$(cat $j)
let S="$S / 1000" let S="$S / 1000"
echo "$j $S" echo "$j $S"
done done
FAN=`echo $fanactive|cut -d' ' -f$REPLY` FAN=$(echo $fanactive|cut -d' ' -f$REPLY)
FAN_MIN=`echo $fanactive_min|cut -d' ' -f$REPLY` FAN_MIN=$(echo $fanactive_min|cut -d' ' -f$REPLY)
FCFANS="`echo $FCFANS | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=$FAN" FCFANS=$(echo $FCFANS | sed -e "s/${pwmsed}[^ ]* *//g") ${pwms}=$FAN"
echo echo
echo "Select a temperature sensor as source for ${pwms}:" echo "Select a temperature sensor as source for ${pwms}:"
select tempss in $TEMPS "None (Do not affect this PWM output)"; do select tempss in $TEMPS "None (Do not affect this PWM output)"; do
@@ -907,7 +907,7 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
then then
FCTEMPS="${pwms}=${tempss}" FCTEMPS="${pwms}=${tempss}"
else else
FCTEMPS="`echo $FCTEMPS | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${tempss}" FCTEMPS="$(echo $FCTEMPS | sed -e "s/${pwmsed}[^ ]* *//g") ${pwms}=${tempss}"
fi fi
fi fi
echo echo
@@ -922,7 +922,7 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
then then
MINTEMP="${pwms}=${XMT}" MINTEMP="${pwms}=${XMT}"
else else
MINTEMP="`echo $MINTEMP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMT}" MINTEMP="$(echo $MINTEMP | sed -e "s/${pwmsed}[^ ]* *//g") ${pwms}=${XMT}"
fi fi
echo echo
echo 'Enter the high temperature (degree C)' echo 'Enter the high temperature (degree C)'
@@ -936,7 +936,7 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
then then
MAXTEMP="${pwms}=${XMT}" MAXTEMP="${pwms}=${XMT}"
else else
MAXTEMP="`echo $MAXTEMP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMT}" MAXTEMP="$(echo $MAXTEMP | sed -e "s/${pwmsed}[^ ]* *//g") ${pwms}=${XMT}"
fi fi
if [ $FAN_MIN -eq 0 ] if [ $FAN_MIN -eq 0 ]
@@ -962,7 +962,7 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
then then
MINSTOP="${pwms}=${XMSTOP}" MINSTOP="${pwms}=${XMSTOP}"
else else
MINSTOP="`echo $MINSTOP | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMSTOP}" MINSTOP="$(echo $MINSTOP | sed -e "s/${pwmsed}[^ ]* *//g") ${pwms}=${XMSTOP}"
fi fi
if [ $FAN_MIN -eq 0 ] if [ $FAN_MIN -eq 0 ]
@@ -988,7 +988,7 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
then then
MINSTART="${pwms}=${XMSTART}" MINSTART="${pwms}=${XMSTART}"
else else
MINSTART="`echo $MINSTART | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMSTART}" MINSTART="$(echo $MINSTART | sed -e "s/${pwmsed}[^ ]* *//g") ${pwms}=${XMSTART}"
fi fi
if [ $XMSTOP -gt 0 ] if [ $XMSTOP -gt 0 ]
@@ -1006,7 +1006,7 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
then then
MINPWM="${pwms}=${XMINP}" MINPWM="${pwms}=${XMINP}"
else else
MINPWM="`echo $MINPWM | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMINP}" MINPWM="$(echo $MINPWM | sed -e "s/${pwmsed}[^ ]* *//g") ${pwms}=${XMINP}"
fi fi
fi fi
echo echo
@@ -1019,7 +1019,7 @@ select pwms in $pwmactive "Change INTERVAL" "Just quit" "Save and quit" "Show co
then then
MAXPWM="${pwms}=${XMAXP}" MAXPWM="${pwms}=${XMAXP}"
else else
MAXPWM="`echo $MAXPWM | sed -e "s/${pwmsed}[^ ]* *//g"` ${pwms}=${XMAXP}" MAXPWM="$(echo $MAXPWM | sed -e "s/${pwmsed}[^ ]* *//g") ${pwms}=${XMAXP}"
fi fi
fi fi
echo echo