#!/bin/bash
#######################################################################
#                                                                     #
#  Whats-in-hwmon shows how many temps or fanspeeds are in each       #
#  /sys/class/hwmon/hwmonX folder.                                    #
#                                                                     #
#  whats-in-hwmon "temp"  shows tempX_input files and temps           #
#  whats-in-hwmon "fan"   shows fanX_input files and fanspeeds        #
#  whats-in-hwmon "in"    shows inX_input files and voltages          #
#                                                                     #
#  Made by Koentje (remon@cobrasoft.nl)                               #
#                                                                     #
#######################################################################

check_hwmon () {
 arr=$(ls /sys/class/hwmon)
 echo -e "\n------------[  What's in HWMON  ]-------------"

 for v in ${arr[@]}
 do
     hwmon=$v
     name=$(cat /sys/class/hwmon/$hwmon/name)
     path="/sys/class/hwmon/$hwmon"

     echo
     echo "$v  ($(cat $path/name))"

      arr2=$(ls $path/$1*_input 2>/dev/null)
      for y in ${arr2[@]}
      do
         echo "  $y  $(cat $y)"
      done
 done
 echo -e "\n----------------------------------------------\n"
}


if [ "$1" = "temp" ]; then
  check_hwmon temp
elif [ "$1" = "fan" ]; then
  check_hwmon fan
elif [ "$1" = "in" ]; then
  check_hwmon in
else
  echo -e "\n Usage:  whats-in-hwmon [temp|fan|in]\n"
fi
