-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpowersaving.cgi
executable file
·202 lines (175 loc) · 5.38 KB
/
powersaving.cgi
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/sh
#
# Hardware / power saving
#
# Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
#
# Common functions from libtazpanel
. ./lib/libtazpanel
get_config
case "$1" in
menu)
cat <<EOT
<li><a data-icon="@display@" href="powersaving.cgi" data-root>$(_ 'Power saving')</a></li>
EOT
exit
esac
for p in $(POST); do
case "$p" in
governor)
for i in /sys/devices/system/cpu/cpu*/cpufreq ; do
POST $p > $i/scaling_governor
done
esac
done
header
TITLE=$(_ 'Hardware')
xhtml_header "$(_ 'Power saving')"
## DPMS ##
cat <<EOT
<section>
<header>
<span data-icon="@display@">DPMS (Display Power Management Signaling)</span>
</header>
<div>$(_ "DPMS enables power saving behaviour of monitors when the computer is not in use.")</div>
<form method="post" class="wide">
<input type="hidden" name="powersaving" value="set"/>
EOT
monitor_conf='/etc/X11/xorg.conf.d/50-Monitor.conf'
if [ ! -s "$monitor_conf" ]; then
# Config is absent, so create it
cat > "$monitor_conf" <<EOT
Section "Monitor"
Identifier "Monitor0"
VendorName "Monitor Vendor"
ModelName "Monitor Model"
Option "DPMS" "true"
EndSection
EOT
fi
cat <<EOT
<table class="wide zebra">
<thead>
<tr><td>$(_ 'Identifier')</td>
<td>$(_ 'Vendor name')</td>
<td>$(_ 'Model name')</td>
<td>$(_ 'DPMS enabled')</td>
</tr>
</thead>
EOT
awk -F\" '{
if ($1 ~ /^Section/) { I = V = M = D = ""; }
if ($1 ~ /Identifier/) { I = $2; }
if ($1 ~ /VendorName/) { V = $2; }
if ($1 ~ /ModelName/) { M = $2; }
if ($1 ~ /Option/ && $2 ~ /DPMS/) { D = $4; }
if ($1 ~ /EndSection/) {
if (D == "false") { D = ""; } else { D = "checked"; }
printf "<tr><td data-icon=\"@display@\">%s</td><td>%s</td><td>%s</td><td>", I, V, M;
printf "<label><input type=\"checkbox\" name=\"%s\" %s/>DPMS</label>", I, D;
printf "</td></tr>\n";
}
}' $monitor_conf
layout_conf='/etc/X11/xorg.conf.d/10-ServerLayout.conf'
cat <<EOT
</table>
<input type="hidden" name="ids" value="$(
awk -F\" '$1 ~ /Identifier/ { printf "%s ", $2; }' $monitor_conf)"/>
<table>
<tr><td>
<fieldset>
<legend>$(_ 'DPMS times (in minutes):')</legend>
<table>
<tr><td>Standby Time</td>
<td><input type="number" name="StandbyTime" value="10"/></td></tr>
<tr><td>Suspend Time</td>
<td><input type="number" name="SuspendTime" value="20"/></td></tr>
<tr><td>Off Time</td>
<td><input type="number" name="OffTime" value="30"/></td></tr>
</table>
</fieldset>
</td>
<td style="vertical-align: top">
<fieldset>
<legend>$(_ 'Manual edit')</legend>
<a data-icon="@conf@" href="index.cgi?file=$monitor_conf">$(basename $monitor_conf)</a><br/>
<a data-icon="@conf@" href="index.cgi?file=$layout_conf">$(basename $layout_conf)</a>
</fieldset>
<pre>$(for i in $(POST); do echo "$i: " $(POST $i); done)</pre>
</td>
</tr>
</table>
<footer>
<button type="submit" data-icon="@ok@">$(_ 'Change')</button>
</footer>
</form>
</section>
EOT
## CPU ##
cpu=$(awk -F: '$1 ~ "model name" {
gsub(/\(TM\)/,"™",$2); gsub(/\(R\)/,"®",$2);
split($2,c,"@");
print "<span data-icon=\"@cpu@\">" c[1] "</span>";
}' /proc/cpuinfo)
multiplier=$(echo "$cpu" | wc -l)
[ "$multiplier" -ne 1 ] && cpu="$multiplier × $(echo "$cpu" | head -n1)"
freq=$(awk -F: 'BEGIN{N=0}$1~"MHz"{printf "%d:<b>%s</b>MHz ",N,$2; N++}' /proc/cpuinfo)
cpufreq=/sys/devices/system/cpu/cpu0/cpufreq
cat <<EOT
<section>
<header><span data-icon="@cpu@">$(_ 'CPU')</span></header>
<div>$(_ "CPU frequency scaling enables the operating system to scale the \
CPU frequency up or down in order to save power. CPU frequencies can be scaled \
automatically depending on the system load, in response to ACPI events, or \
manually by userspace programs.")</div>
<form method="post" class="wide">
<table class="wide zebra">
<tr><td>$(_ 'Model name')</td><td>$cpu</td></tr>
<tr><td>$(_ 'Current frequency')</td><td>$freq</td></tr>
<tr><td>$(_ 'Current driver')</td><td>$(cat "$cpufreq/scaling_driver")
<tr><td>$(_ 'Current governor')</td><td><select name="governor">
EOT
for i in $(cat "$cpufreq/scaling_available_governors"); do
sel=""; [ $i = $(cat "$cpufreq/scaling_governor") ] && sel=" selected"
echo " <option$sel>$i</option>"
done
cat <<EOT
</select></td></tr>
</table>
<footer>
<button type="submit" data-icon="@ok@">$(_ 'Change')</button>
</footer>
</form>
</section>
EOT
# As of Kernel 3.4, the native CPU module is loaded automatically.
if [ -d "/lib/modules/$(uname -r)/kernel/drivers/cpufreq" ]; then
cd /lib/modules/$(uname -r)/kernel/drivers/cpufreq
cat <<EOT
<section>
<header>$(_ 'Kernel modules')</header>
<table class="wide zebra summary">
<thead>
<tr><td>$(_ 'Module')</td>
<td>$(_ 'Description')</td>
</tr>
</thead>
EOT
lsmod="$(lsmod | awk '{printf "%s " $1}') "
for module in $(ls | grep -v 'mperf\|speedstep-lib'); do
module="${module%.ko.xz}"; module="${module//-/_}"
if echo $lsmod | grep -q " $module "; then icon='@ok@'; else icon='@cancel@'; fi
echo "<tr><td><span data-icon=\"$icon\">$module</span></td><td>"
modinfo $module | awk -F: '$1=="description"{
gsub(/\(TM\)/,"™",$2); gsub(/\(R\)/,"®",$2);
gsub(/VIA|C7|Cyrix|MediaGX|NatSemi|Geode|Transmeta|Crusoe|Efficeon|Pentium™ 4|Xeon™|AMD|K6-2\+|K6-3\+|K7|Athlon 64|Opteron|Intel/,"<b>&</b>",$2);
print $2}'
echo "</td></tr>"
done
cat <<EOT
</table>
</section>
EOT
fi
xhtml_footer
exit 0