This repository has been archived by the owner on Dec 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcpumode
51 lines (45 loc) · 1.76 KB
/
cpumode
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/bin/bash
# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4 foldmethod=marker
# ----------------------------------------------------------------------
# Author: DeaDSouL (Mubarak Alrashidi)
# URL: https://unix.cafe/wp/en/2020/07/toggle-between-cpu-powersave-and-performance-in-linux/
# GitLab: https://gitlab.com/unix.cafe/cpumode
# Twitter: https://twitter.com/_DeaDSouL_
# License: GPLv3
# ----------------------------------------------------------------------
# usage menu
function show_usage() { #{{{
echo -e "USAGE:\t$0 powersave|performance|current"
echo -e "\t\tpowersave\tSet CPU in power-saving mode."
echo -e "\t\tperformance\tSet CPU in performance mode."
echo -e "\t\tcurrent\t\tShow the current CPU mode."
echo -e "\t\thelp\t\tShow this menu."
exit 1
} #}}}
# our error exit function
function ee() { #{{{
echo "$1"; exit 1
} #}}}
# get cpu mode
function getcpumode() { #{{{
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
} #}}}
# set cpu mode
function setcpumode() { #{{{
[ $1 != 'powersave' -a $1 != 'performance' ] && ee 'Invalid given value..'
[ $(getcpumode) == $1 ] && ee "It's already in '$1' mode"
echo $1 | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
} #}}}
# make sure we have root's power
if [ $UID -ne 0 ]; then #{{{
echo 'Script should be executed by "root"'
ee 'Or prefixed with "sudo".'
fi #}}}
# get & set actions
case "$1" in #{{{
performance) setcpumode performance; exit 0 ;;
powersave) setcpumode powersave; exit 0 ;;
current|get) getcpumode; exit 0 ;;
help) show_usage ;;
*) ee "Try: $0 help" ;;
esac #}}}