amdgpu-pro-fans.sh 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #!/usr/bin/env bash
  2. #####################################
  3. # AMDGPU-PRO LINUX UTILITIES SUITE #
  4. ######################################
  5. # Utility Name: AMDGPU-PRO-FANS
  6. # Version: 0.1.5
  7. # Version Name: MahiMahi
  8. # https://github.com/DominiLux/amdgpu-pro-fans
  9. # Licensed under the Apache License, Version 2.0 (the "License");
  10. # you may not use this file except in compliance with the License.
  11. # You may obtain a copy of the License at
  12. # http://www.apache.org/licenses/LICENSE-2.0
  13. # Unless required by applicable law or agreed to in writing, software
  14. # distributed under the License is distributed on an "AS IS" BASIS,
  15. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. # See the License for the specific language governing permissions and
  17. # limitations under the License.
  18. #####################################################################
  19. # *** IMPORTANT *** #
  20. # DO NOT MODIFY PAST THIS POINT IF YOU DONT KNOW WHAT YOUR DOING!!! #
  21. #####################################################################
  22. ############################
  23. # COMMAND PARSED VARIABLES #
  24. ############################
  25. adapter="all"
  26. targettemp=""
  27. fanpercent=""
  28. arguments="$@"
  29. ##################
  30. # USAGE FUNCTION #
  31. ##################
  32. usage ()
  33. {
  34. echo "* AMDGPU-PRO-FANS *"
  35. echo "error: invalid arguments"
  36. echo "usage: $0 [-h] for help..."
  37. exit
  38. }
  39. ###########################
  40. # SET FAN SPEED FUNCTIONS #
  41. ###########################
  42. set_all_fan_speeds ()
  43. {
  44. cardcount="0";
  45. for CurrentCard in /sys/class/drm/card?/ ; do
  46. for CurrentMonitor in "$CurrentCard"device/hwmon/hwmon?/ ; do
  47. cd $CurrentMonitor # &>/dev/null
  48. workingdir="`pwd`"
  49. fanmax=$(head -1 "$workingdir"/pwm1_max)
  50. if [ $fanmax -gt 0 ] ; then
  51. speed=$(( fanmax * fanpercent ))
  52. speed=$(( speed / 100 ))
  53. sudo chown $USER "$workingdir"/pwm1_enable
  54. sudo chown $USER "$workingdir"/pwm1
  55. sudo echo -n "1" >> $workingdir/pwm1_enable # &>/dev/null
  56. sudo echo -n "$speed" >> $workingdir/pwm1 # &>/dev/null
  57. speedresults=$(head -1 "$workingdir"/pwm1)
  58. if [ $(( speedresults - speed )) -gt 6 ] ; then
  59. echo "Error Setting Speed For Card$cardcount!"
  60. else
  61. echo "Card$cardcount Speed Set To $fanpercent %"
  62. fi
  63. else
  64. echo "Error: Unable To Determine Maximum Fan Speed For Card$cardcount!"
  65. fi
  66. done
  67. cardcount="$(($cardcount + 1))"
  68. done
  69. }
  70. set_fans_requested ()
  71. {
  72. if [ "$adapter"="all" ] ; then
  73. set_all_fan_speeds
  74. fi
  75. }
  76. #################################
  77. # PARSE COMMAND LINE PARAMETERS #
  78. #################################
  79. command_line_parser ()
  80. {
  81. parseline=`getopt -s bash -u -o a:s: -n '$0' -- "$arguments"`
  82. eval set -- "$parseline"
  83. while true ; do
  84. case "$1" in
  85. -a ) adapter="$2" ; shift 2 ;;
  86. -s ) fanpercent="$2" ; set_fans_requested ; break ;;
  87. --) break ;;
  88. *) usage ; exit 1 ;;
  89. esac
  90. done
  91. }
  92. #################
  93. # Home Function #
  94. #################
  95. command_line_parser
  96. exit;