wok-next view tazpanel-extra/stuff/powersaving.cgi @ rev 18245

Add tazpanel-extra
author Pascal Bellard <pascal.bellard@slitaz.org>
date Fri Jul 31 23:33:17 2015 +0200 (2015-07-31)
parents
children
line source
1 #!/bin/sh
2 #
3 # Hardware / power saving
4 #
5 # Copyright (C) 2011-2015 SliTaz GNU/Linux - BSD License
6 #
8 # Common functions from libtazpanel
9 . lib/libtazpanel
10 get_config
12 case "$1" in
13 menu)
14 cat <<EOT
15 <li><a data-icon="display" href="powersaving.cgi" data-root>$(_ 'Power saving')</a></li>
16 EOT
17 exit
18 esac
20 header
22 TITLE=$(_ 'Hardware')
24 xhtml_header "$(_ 'Power saving')"
26 ## DPMS ##
27 cat <<EOT
28 <section>
29 <header>
30 <span data-icon="display">DPMS (Display Power Management Signaling)</span>
31 </header>
33 <div>$(_ "DPMS enables power saving behaviour of monitors when the computer is not in use.")</div>
34 <form method="post" class="wide">
35 <input type="hidden" name="powersaving" value="set"/>
36 EOT
38 monitor_conf='/etc/X11/xorg.conf.d/50-Monitor.conf'
39 if [ ! -s "$monitor_conf" ]; then
40 # Config is absent, so create it
41 cat > "$monitor_conf" <<EOT
42 Section "Monitor"
43 Identifier "Monitor0"
44 VendorName "Monitor Vendor"
45 ModelName "Monitor Model"
46 Option "DPMS" "true"
47 EndSection
48 EOT
49 fi
51 cat <<EOT
52 <table class="wide zebra">
53 <thead>
54 <tr><td>$(_ 'Identifier')</td>
55 <td>$(_ 'Vendor name')</td>
56 <td>$(_ 'Model name')</td>
57 <td>$(_ 'DPMS enabled')</td>
58 </tr>
59 </thead>
60 EOT
62 awk -F\" '{
63 if ($1 ~ /^Section/) { I = V = M = D = ""; }
64 if ($1 ~ /Identifier/) { I = $2; }
65 if ($1 ~ /VendorName/) { V = $2; }
66 if ($1 ~ /ModelName/) { M = $2; }
67 if ($1 ~ /Option/ && $2 ~ /DPMS/) { D = $4; }
68 if ($1 ~ /EndSection/) {
69 if (D == "false") { D = ""; } else { D = "checked"; }
70 printf "<tr><td data-icon=\"display\">%s</td><td>%s</td><td>%s</td><td>", I, V, M;
71 printf "<label><input type=\"checkbox\" name=\"%s\" %s/>DPMS</label>", I, D;
72 printf "</td></tr>\n";
73 }
74 }' $monitor_conf
76 layout_conf='/etc/X11/xorg.conf.d/10-ServerLayout.conf'
78 cat <<EOT
79 </table>
80 <input type="hidden" name="ids" value="$(
81 awk -F\" '$1 ~ /Identifier/ { printf "%s ", $2; }' $monitor_conf)"/>
83 <table>
84 <tr><td>
85 <fieldset>
86 <legend>$(_ 'DPMS times (in minutes):')</legend>
87 <table>
88 <tr><td>Standby Time</td>
89 <td><input type="number" name="StandbyTime" value="10"/></td></tr>
90 <tr><td>Suspend Time</td>
91 <td><input type="number" name="SuspendTime" value="20"/></td></tr>
92 <tr><td>Off Time</td>
93 <td><input type="number" name="OffTime" value="30"/></td></tr>
94 </table>
95 </fieldset>
96 </td>
97 <td style="vertical-align: top">
98 <fieldset>
99 <legend>$(_ 'Manual edit')</legend>
100 <a data-icon="conf" href="index.cgi?file=$monitor_conf">$(basename $monitor_conf)</a><br/>
101 <a data-icon="conf" href="index.cgi?file=$layout_conf">$(basename $layout_conf)</a>
102 </fieldset>
103 <pre>$(for i in $(POST); do echo "$i: " $(POST $i); done)</pre>
104 </td>
105 </tr>
106 </table>
107 <footer>
108 <button type="submit" data-icon="ok">$(_ 'Change')</button>
109 </footer>
110 </form>
111 </section>
112 EOT
115 ## CPU ##
117 cpu=$(awk -F: '$1 ~ "model name" {
118 gsub(/\(TM\)/,"™",$2); gsub(/\(R\)/,"®",$2);
119 split($2,c,"@");
120 print "<span data-icon=\"cpu\">" c[1] "</span>";
121 }' /proc/cpuinfo)
122 multiplier=$(echo "$cpu" | wc -l)
123 [ "$multiplier" -ne 1 ] && cpu="$multiplier × $(echo "$cpu" | head -n1)"
125 freq=$(awk -F: 'BEGIN{N=0}$1~"MHz"{printf "%d:<b>%s</b>MHz ",N,$2; N++}' /proc/cpuinfo)
127 cat <<EOT
128 <section>
129 <header><span data-icon="cpu">$(_ 'CPU')</span></header>
131 <div>$(_ "CPU frequency scaling enables the operating system to scale the \
132 CPU frequency up or down in order to save power. CPU frequencies can be scaled \
133 automatically depending on the system load, in responce to ACPI events, or \
134 manually by userspace programs.")</div>
136 <table class="wide zebra">
137 <tr><td>$(_ 'Model name')</td><td>$cpu</td></tr>
138 <tr><td>$(_ 'Current frequency')</td><td>$freq</td></tr>
139 <tr><td>$(_ 'Current driver')</td><td>$(cat '/sys/devices/system/cpu/cpu0/cpufreq/scaling_driver')
140 <tr><td>$(_ 'Current governor')</td><td>$(cat '/sys/devices/system/cpu/cpu0/cpufreq/scaling_governor')
141 </table>
142 </section>
143 EOT
145 # As of Kernel 3.4, the native CPU module is loaded automatically.
146 if [ -d "/lib/modules/$(uname -r)/kernel/drivers/cpufreq" ]; then
147 cd /lib/modules/$(uname -r)/kernel/drivers/cpufreq
148 cat <<EOT
149 <section>
150 <header>$(_ 'Kernel modules')</header>
151 <table class="wide zebra summary">
152 <thead>
153 <tr><td>$(_ 'Module')</td>
154 <td>$(_ 'Description')</td>
155 </tr>
156 </thead>
157 EOT
158 lsmod="$(lsmod | awk '{printf "%s " $1}') "
160 for module in $(ls | grep -v 'mperf\|speedstep-lib'); do
161 module="${module%.ko.xz}"; module="${module//-/_}"
162 if echo $lsmod | grep -q " $module "; then icon='ok'; else icon='cancel'; fi
163 echo "<tr><td><span data-icon=\"$icon\">$module</span></td><td>"
164 modinfo $module | awk -F: '$1=="description"{
165 gsub(/\(TM\)/,"™",$2); gsub(/\(R\)/,"®",$2);
166 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);
167 print $2}'
168 echo "</td></tr>"
169 done
170 cat <<EOT
171 </table>
172 </section>
173 EOT
174 fi
176 xhtml_footer
177 exit 0