forked from melma/c60-tweak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
c60-tweak.sh
executable file
·135 lines (114 loc) · 3.26 KB
/
c60-tweak.sh
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/bin/bash
defaultParameters="-p 0:0x22 -p 1:0x28,4 -p 2:0x2B"
tweakedParameters="-p 0:0x28 -p 1:0x28,3 -p 2:0x38"
startupScriptFileName="c60-tweak-startup.sh"
undervoltProgramPath=""
tweaked=0
requestSudo() {
sudo echo -n || {
exit 1
}
}
checkCpu() {
lscpu | grep -q "AMD C-60" || {
echo "This is intended only for AMD C-60 processors"
exit 2
}
}
checkUndervolt() {
type undervolt &> /dev/null || {
echo "Program 'undervolt' couldn't be found"
exit 3
}
undervoltProgramPath=`which undervolt`
}
checkMsr() {
lsmod | grep -q msr || {
sudo modprobe msr &> /dev/null || {
echo "MSR module couldn't be loaded"
exit 4
}
}
}
showOptions() {
echo "AMD C-60 Linux Tweak"
echo "1 - Check current status"
echo "2 - Undervolt and unlock turbo mode"
echo "3 - Enable on system startup"
echo "4 - Restore and disable"
echo "5 - Quit"
}
selectOption() {
while true; do
echo -n "Select an option: "; read option
case "$option" in
1) checkStatus;;
2) undervoltAndUnlockTurbo;;
3) enableOnStartup;;
4) restoreAndDisable;;
5) exit 0;;
*) echo "Unknown option";;
esac
done
}
checkStatus() {
checkMsr
if sudo undervolt -r | grep -zq ".*28.*28.*3\..*38.*"; then
echo "Voltage is lowered and turbo mode is unlocked"
else
echo "Voltage is default and turbo mode is locked"
fi
}
undervoltAndUnlockTurbo() {
checkMsr
if sudo undervolt $tweakedParameters &> /dev/null; then
echo "Lowered voltage and unlocked turbo mode"
tweaked=1
else
echo "Couldn't set new parameters"
exit 5
fi
}
enableOnStartup() {
if [ -f /etc/init.d/$startupScriptFileName ]; then
echo "It's already enabled on system startup"
elif [ $tweaked = 0 ]; then
echo "Use option no. 2 before enabling on system startup"
else
c="#!/bin/bash\n"
c=$c"### BEGIN INIT INFO\n"
c=$c"# Default-Start: 2 3 4 5\n"
c=$c"### END INIT INFO\n"
c=$c"modprobe msr\n"
c=$c"$undervoltProgramPath $tweakedParameters"
sudo bash -c "echo -e '$c' > /etc/init.d/$startupScriptFileName"
sudo chmod +x /etc/init.d/$startupScriptFileName
sudo update-rc.d $startupScriptFileName defaults > /dev/null 2>&1
sudo update-rc.d $startupScriptFileName enable > /dev/null 2>&1
echo "Enabled on system startup"
fi
}
restoreAndDisable() {
checkMsr
if sudo undervolt $defaultParameters &> /dev/null; then
echo "Restored voltages and turbo mode default behavior"
tweaked=0
else
echo "Couldn't restore voltages and turbo mode default behavior"
exit 5
fi
if [ -f /etc/init.d/$startupScriptFileName ]; then
sudo update-rc.d $startupScriptFileName disable > /dev/null 2>&1
sudo update-rc.d $startupScriptFileName remove > /dev/null 2>&1
sudo rm /etc/init.d/$startupScriptFileName
echo "Disabled on system startup"
else
echo "It's not enabled on system startup"
fi
}
requestSudo
checkCpu
checkUndervolt
checkMsr
showOptions
selectOption