Guest User

Untitled

a guest
Aug 9th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.61 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # This script is the result for removing many stuff from pwmconfig.
  4. # It won't do anything besides activating the fans of my Tonga XT / Amethyst XT [Radeon R9 380X / R9 M295X]
  5. # Pwmconfig does something which as a side effect turns my video card fans on, avoiding overheating.
  6. #
  7.  
  8. REVISION=$(echo '$Revision: 6243 $' | cut -d' ' -f2)
  9. REVDATE=$(echo '$Date: 2014-03-20 11:23:35 +0100 (jeu. 20 mars 2014) $' | cut -d' ' -f2)
  10. PIDFILE="/var/run/fancontrol.pid"
  11.  
  12. if [ -f "$PIDFILE" ]
  13. then
  14. echo "File $PIDFILE exists. This typically means that the"
  15. echo "fancontrol deamon is running. You should stop it before running pwmconfig."
  16. echo "If you are certain that fancontrol is not running, then you can delete"
  17. echo "$PIDFILE manually."
  18. exit 1
  19. fi
  20.  
  21. if [ "`id -u`" != "0" ]
  22. then
  23. echo "You need to be root to run this script."
  24. exit 1
  25. fi
  26.  
  27. echo 'We will attempt to briefly stop each fan using the pwm controls.'
  28. echo 'The program will attempt to restore each fan to full speed'
  29. echo 'after testing. However, it is ** very important ** that you'
  30. echo 'physically verify that the fans have been to full speed'
  31. echo 'after the program has completed.'
  32. echo
  33.  
  34. DELAY=5 # 3 seconds delay is too short for large fans, thus I increased it to 5
  35. MAX=255
  36.  
  37. if [ -d "/sys/class/hwmon" ]
  38. then
  39. SYSFS=2
  40. DIR="/sys/class/hwmon"
  41. PREFIX='hwmon*'
  42. elif [ -d "/sys/bus/i2c/devices" ]
  43. then
  44. SYSFS=1
  45. DIR="/sys/bus/i2c/devices"
  46. PREFIX='*-*'
  47. else
  48. echo $0: 'No sensors found! (modprobe sensor modules?)'
  49. exit 1
  50. fi
  51.  
  52. cd $DIR
  53. DEVICES=`echo $PREFIX`
  54. if [ "$PREFIX" = "$DEVICES" ]
  55. then
  56. echo $0: 'No sensors found! (modprobe sensor modules?)'
  57. exit 1
  58. fi
  59.  
  60. # We may need to adjust the device path
  61. if [ "$SYSFS" = "2" ]
  62. then
  63. OLD_DEVICES="$DEVICES"
  64. DEVICES=""
  65.  
  66. for device in $OLD_DEVICES
  67. do
  68. if [ ! -r "$device/name" ]
  69. then
  70. device="$device/device"
  71. fi
  72.  
  73. DEVICES="$DEVICES $device"
  74. done
  75. fi
  76.  
  77.  
  78. for device in $DEVICES
  79. do
  80. # Find available fan control outputs
  81. MATCH=$device/'pwm[1-9]'
  82. device_pwm=`echo $MATCH`
  83. if [ "$SYSFS" = "1" -a "$MATCH" = "$device_pwm" ]
  84. then
  85. # Deprecated naming scheme (used in kernels 2.6.5 to 2.6.9)
  86. MATCH=$device/'fan[1-9]_pwm'
  87. device_pwm=`echo $MATCH`
  88. fi
  89. if [ "$MATCH" != "$device_pwm" ]
  90. then
  91. PWM="$PWM $device_pwm"
  92. fi
  93.  
  94. # Find available fan monitoring inputs
  95. MATCH=$device/'fan[1-9]_input'
  96. device_fan=`echo $MATCH`
  97. if [ "$MATCH" != "$device_fan" ]
  98. then
  99. FAN="$FAN $device_fan"
  100. fi
  101. done
  102.  
  103. if [ -z "$PWM" ]
  104. then
  105. echo $0: 'There are no pwm-capable sensor modules installed'
  106. exit 1
  107. fi
  108. if [ -z "$FAN" ]
  109. then
  110. echo $0: 'There are no fan-capable sensor modules installed'
  111. exit 1
  112. fi
  113.  
  114. # $1 = padding
  115. function print_devices()
  116. {
  117. local name device
  118.  
  119. for device in $DEVICES
  120. do
  121. name=`cat $device/name 2> /dev/null`
  122. [ -z "$name" ] && name="unknown (no name attribute)"
  123. echo "$1$device is $name"
  124. done
  125. }
  126.  
  127. # $1 = pwm file name
  128. function is_pwm_auto()
  129. {
  130. local ENABLE=${1}_enable
  131.  
  132. if [ -f $ENABLE ]
  133. then
  134. if [ "`cat $ENABLE`" -gt 1 ]
  135. then
  136. return 0
  137. fi
  138. fi
  139.  
  140. return 1
  141. }
  142.  
  143. # $1 = pwm file name
  144. function pwmdisable()
  145. {
  146. local ENABLE=${1}_enable
  147.  
  148. # No enable file? Just set to max
  149. if [ ! -f $ENABLE ]
  150. then
  151. echo $MAX > $1
  152. return 0
  153. fi
  154.  
  155. # Try pwmN_enable=0
  156. echo 0 2>/dev/null > $ENABLE
  157. if [ "`cat $ENABLE`" -eq 0 ]
  158. then
  159. # Success
  160. return 0
  161. fi
  162.  
  163. # It didn't work, try pwmN_enable=1 pwmN=255
  164. echo 1 2>/dev/null > $ENABLE
  165. if [ "`cat $ENABLE`" -ne 1 ]
  166. then
  167. echo "$ENABLE stuck to `cat $ENABLE`" >&2
  168. return 1
  169. fi
  170.  
  171. echo $MAX > $1
  172. if [ "`cat $1`" -ge 190 ]
  173. then
  174. # Success
  175. return 0
  176. fi
  177.  
  178. # Nothing worked
  179. echo "$1 stuck to `cat $1`" >&2
  180. return 1
  181. }
  182.  
  183. # $1 = pwm file name
  184. function pwmenable()
  185. {
  186. local ENABLE=${1}_enable
  187.  
  188. if [ -w $ENABLE ]
  189. then
  190. echo 1 2>/dev/null > $ENABLE
  191. if [ $? -ne 0 ]
  192. then
  193. return 1
  194. fi
  195. fi
  196. echo $MAX > $1
  197. }
  198.  
  199. # $1 = pwm file name; $2 = pwm value 0-255
  200. function pwmset()
  201. {
  202. echo $2 > $1
  203. }
  204.  
  205. echo 'Found the following devices:'
  206. print_devices " "
  207. echo
  208.  
  209. echo 'Found the following PWM controls:'
  210. for i in $PWM
  211. do
  212. P=`cat $i`
  213. echo " $i current value: $P"
  214. if [ -w $i ]
  215. then
  216. # First check if PWM output is in automatic mode
  217. if is_pwm_auto $i
  218. then
  219. echo "$i is currently setup for automatic speed control."
  220. fi
  221.  
  222. pwmdisable $i # THE SIDE EFFECT HAPPENS HERE
  223. if [ $? -ne 0 ]
  224. then
  225. echo "Manual control mode not supported, skipping $i."
  226. elif [ "$GOODPWM" = "" ]
  227. then
  228. GOODPWM=$i
  229. else
  230. GOODPWM="$GOODPWM $i"
  231. fi
  232. else
  233. echo "Can't write to $i, skipping."
  234. fi
  235. done
Add Comment
Please, Sign In to add comment