Guest User

Untitled

a guest
Apr 25th, 2018
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. GOVERNOR_AC=performance # CPU governor when charging
  4. GOVERNOR_DC=powersave # CPU governor when not charging
  5. LOOP_FREQ=5 # Delay on AC status checking
  6.  
  7. function getAC { # Returns AC status (1=charging, 0=discharging)
  8. echo $(cat /sys/class/power_supply/AC0/online)
  9. }
  10.  
  11. function setGovernor { # Set CPU governor to $1
  12. echo "$1" | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
  13. echo "CPU Governor set to $1"
  14. }
  15.  
  16. function setGovernorCharge { # Set governor for charging
  17. setGovernor $GOVERNOR_AC
  18. }
  19.  
  20. function setGovernorDischarge { # Set governor for discharging
  21. setGovernor $GOVERNOR_DC
  22. }
  23.  
  24. function main { # Main loop
  25. prev=100
  26. while true; do
  27. ac="$(getAC)"
  28. if [ ! $ac -eq $prev ]; # AC state changed
  29. then
  30. if [ $ac -eq 1 ];
  31. then # Charging
  32. setGovernorCharge
  33. elif [ $ac -eq 0 ];
  34. then # Discharging
  35. setGovernorDischarge
  36. fi
  37. prev=$ac
  38. fi
  39. sleep $LOOP_FREQ
  40. done
  41. }
  42.  
  43. main # Run the loop
Add Comment
Please, Sign In to add comment