| | 542 | function DevicePath() |
| | 543 | { |
| | 544 | if [ -h "$1/device" ] |
| | 545 | then |
| | 546 | readlink -f "$1/device" | sed -e 's/^\/sys\///' |
| | 547 | fi |
| | 548 | } |
| | 549 | |
| | 550 | function DeviceName() |
| | 551 | { |
| | 552 | if [ -r "$1/name" ] |
| | 553 | then |
| | 554 | cat "$1/name" | sed -e 's/[[:space:]=]/_/g' |
| | 555 | elif [ -r "$1/device/name" ] |
| | 556 | then |
| | 557 | cat "$1/device/name" | sed -e 's/[[:space:]=]/_/g' |
| | 558 | fi |
| | 559 | } |
| | 560 | |
| | 561 | function ValidateDevices() |
| | 562 | { |
| | 563 | local OLD_DEVPATH="$1" OLD_DEVNAME="$2" outdated=0 |
| | 564 | local entry device name path |
| | 565 | |
| | 566 | for entry in $OLD_DEVPATH |
| | 567 | do |
| | 568 | device=`echo "$entry" | sed -e 's/=[^=]*$//'` |
| | 569 | path=`echo "$entry" | sed -e 's/^[^=]*=//'` |
| | 570 | |
| | 571 | if [ "`DevicePath "$device"`" != "$path" ] |
| | 572 | then |
| | 573 | echo "Device path of $device has changed" |
| | 574 | outdated=1 |
| | 575 | fi |
| | 576 | done |
| | 577 | |
| | 578 | for entry in $OLD_DEVNAME |
| | 579 | do |
| | 580 | device=`echo "$entry" | sed -e 's/=[^=]*$//'` |
| | 581 | name=`echo "$entry" | sed -e 's/^[^=]*=//'` |
| | 582 | |
| | 583 | if [ "`DeviceName "$device"`" != "$name" ] |
| | 584 | then |
| | 585 | echo "Device name of $device has changed" |
| | 586 | outdated=1 |
| | 587 | fi |
| | 588 | done |
| | 589 | |
| | 590 | return $outdated |
| | 591 | } |
| | 592 | |
| | 729 | # Remember the path and name of each device with at least one |
| | 730 | # reference (pwm, temp or fan) in the configuration file. |
| | 731 | # This function sets globals DEVPATH and DEVNAME as a side effect. |
| | 732 | function RememberDevices() |
| | 733 | { |
| | 734 | local used entry device name path tempfandev pwmdev |
| | 735 | DEVPATH="" |
| | 736 | DEVNAME="" |
| | 737 | |
| | 738 | for device in $DEVICES |
| | 739 | do |
| | 740 | device=`echo "$device" | sed -e 's/\/.*$//'` |
| | 741 | |
| | 742 | used=0 |
| | 743 | for entry in $1 $2 |
| | 744 | do |
| | 745 | pwmdev=`echo "$entry" | sed -e 's/\/.*$//'` |
| | 746 | tempfandev=`echo "$entry" | sed -e 's/^[^=]*=//' -e 's/\/.*$//'` |
| | 747 | |
| | 748 | if [ "$device" = "$pwmdev" -o "$device" = "$tempfandev" ] |
| | 749 | then |
| | 750 | used=1 |
| | 751 | fi |
| | 752 | done |
| | 753 | if [ "$used" -eq 0 ] |
| | 754 | then |
| | 755 | continue |
| | 756 | fi |
| | 757 | |
| | 758 | # Record the device path and name. This lets the fancontrol |
| | 759 | # script check that they didn't change. If they did, then the |
| | 760 | # configuration file can no longer be trusted. |
| | 761 | path=`DevicePath "$device"` |
| | 762 | if [ -z "$DEVPATH" ] |
| | 763 | then |
| | 764 | DEVPATH="$device=$path" |
| | 765 | else |
| | 766 | DEVPATH="$DEVPATH $device=$path" |
| | 767 | fi |
| | 768 | |
| | 769 | name=`DeviceName "$device"` |
| | 770 | if [ -z "$DEVNAME" ] |
| | 771 | then |
| | 772 | DEVNAME="$device=$name" |
| | 773 | else |
| | 774 | DEVNAME="$DEVNAME $device=$name" |
| | 775 | fi |
| | 776 | done |
| | 777 | } |
| | 778 | |