tazpanel view powersaving.cgi @ rev 638

boot.iso: allow /dev/cdrom
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Jan 05 15:14:01 2022 +0000 (2022-01-05)
parents 4c4eaaf30902
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 for p in $(POST); do
21 case "$p" in
22 governor)
23 for i in /sys/devices/system/cpu/cpu*/cpufreq ; do
24 POST $p > $i/scaling_governor
25 done
26 esac
27 done
29 header
31 TITLE=$(_ 'Hardware')
33 xhtml_header "$(_ 'Power saving')"
35 ## DPMS ##
36 cat <<EOT
37 <section>
38 <header>
39 <span data-icon="@display@">DPMS (Display Power Management Signaling)</span>
40 </header>
42 <div>$(_ "DPMS enables power saving behaviour of monitors when the computer is not in use.")</div>
43 <form method="post" class="wide">
44 <input type="hidden" name="powersaving" value="set"/>
45 EOT
47 monitor_conf='/etc/X11/xorg.conf.d/50-Monitor.conf'
48 if [ ! -s "$monitor_conf" ]; then
49 # Config is absent, so create it
50 cat > "$monitor_conf" <<EOT
51 Section "Monitor"
52 Identifier "Monitor0"
53 VendorName "Monitor Vendor"
54 ModelName "Monitor Model"
55 Option "DPMS" "true"
56 EndSection
57 EOT
58 fi
60 cat <<EOT
61 <table class="wide zebra">
62 <thead>
63 <tr><td>$(_ 'Identifier')</td>
64 <td>$(_ 'Vendor name')</td>
65 <td>$(_ 'Model name')</td>
66 <td>$(_ 'DPMS enabled')</td>
67 </tr>
68 </thead>
69 EOT
71 awk -F\" '{
72 if ($1 ~ /^Section/) { I = V = M = D = ""; }
73 if ($1 ~ /Identifier/) { I = $2; }
74 if ($1 ~ /VendorName/) { V = $2; }
75 if ($1 ~ /ModelName/) { M = $2; }
76 if ($1 ~ /Option/ && $2 ~ /DPMS/) { D = $4; }
77 if ($1 ~ /EndSection/) {
78 if (D == "false") { D = ""; } else { D = "checked"; }
79 printf "<tr><td data-icon=\"@display@\">%s</td><td>%s</td><td>%s</td><td>", I, V, M;
80 printf "<label><input type=\"checkbox\" name=\"%s\" %s/>DPMS</label>", I, D;
81 printf "</td></tr>\n";
82 }
83 }' $monitor_conf
85 layout_conf='/etc/X11/xorg.conf.d/10-ServerLayout.conf'
87 cat <<EOT
88 </table>
89 <input type="hidden" name="ids" value="$(
90 awk -F\" '$1 ~ /Identifier/ { printf "%s ", $2; }' $monitor_conf)"/>
92 <table>
93 <tr><td>
94 <fieldset>
95 <legend>$(_ 'DPMS times (in minutes):')</legend>
96 <table>
97 <tr><td>Standby Time</td>
98 <td><input type="number" name="StandbyTime" value="10"/></td></tr>
99 <tr><td>Suspend Time</td>
100 <td><input type="number" name="SuspendTime" value="20"/></td></tr>
101 <tr><td>Off Time</td>
102 <td><input type="number" name="OffTime" value="30"/></td></tr>
103 </table>
104 </fieldset>
105 </td>
106 <td style="vertical-align: top">
107 <fieldset>
108 <legend>$(_ 'Manual edit')</legend>
109 <a data-icon="@conf@" href="index.cgi?file=$monitor_conf">$(basename $monitor_conf)</a><br/>
110 <a data-icon="@conf@" href="index.cgi?file=$layout_conf">$(basename $layout_conf)</a>
111 </fieldset>
112 <pre>$(for i in $(POST); do echo "$i: " $(POST $i); done)</pre>
113 </td>
114 </tr>
115 </table>
116 <footer>
117 <button type="submit" data-icon="@ok@">$(_ 'Change')</button>
118 </footer>
119 </form>
120 </section>
121 EOT
124 ## CPU ##
126 cpu=$(awk -F: '$1 ~ "model name" {
127 gsub(/\(TM\)/,"™",$2); gsub(/\(R\)/,"®",$2);
128 split($2,c,"@");
129 print "<span data-icon=\"@cpu@\">" c[1] "</span>";
130 }' /proc/cpuinfo)
131 multiplier=$(echo "$cpu" | wc -l)
132 [ "$multiplier" -ne 1 ] && cpu="$multiplier × $(echo "$cpu" | head -n1)"
134 freq=$(awk -F: 'BEGIN{N=0}$1~"MHz"{printf "%d:<b>%s</b>MHz ",N,$2; N++}' /proc/cpuinfo)
135 cpufreq=/sys/devices/system/cpu/cpu0/cpufreq
137 cat <<EOT
138 <section>
139 <header><span data-icon="@cpu@">$(_ 'CPU')</span></header>
141 <div>$(_ "CPU frequency scaling enables the operating system to scale the \
142 CPU frequency up or down in order to save power. CPU frequencies can be scaled \
143 automatically depending on the system load, in response to ACPI events, or \
144 manually by userspace programs.")</div>
146 <form method="post" class="wide">
148 <table class="wide zebra">
149 <tr><td>$(_ 'Model name')</td><td>$cpu</td></tr>
150 <tr><td>$(_ 'Current frequency')</td><td>$freq</td></tr>
151 <tr><td>$(_ 'Current driver')</td><td>$(cat "$cpufreq/scaling_driver")
152 <tr><td>$(_ 'Current governor')</td><td><select name="governor">
153 EOT
155 for i in $(cat "$cpufreq/scaling_available_governors"); do
156 sel=""; [ $i = $(cat "$cpufreq/scaling_governor") ] && sel=" selected"
157 echo " <option$sel>$i</option>"
158 done
160 cat <<EOT
161 </select></td></tr>
162 </table>
163 <footer>
164 <button type="submit" data-icon="@ok@">$(_ 'Change')</button>
165 </footer>
166 </form>
167 </section>
168 EOT
170 # As of Kernel 3.4, the native CPU module is loaded automatically.
171 if [ -d "/lib/modules/$(uname -r)/kernel/drivers/cpufreq" ]; then
172 cd /lib/modules/$(uname -r)/kernel/drivers/cpufreq
173 cat <<EOT
174 <section>
175 <header>$(_ 'Kernel modules')</header>
176 <table class="wide zebra summary">
177 <thead>
178 <tr><td>$(_ 'Module')</td>
179 <td>$(_ 'Description')</td>
180 </tr>
181 </thead>
182 EOT
183 lsmod="$(lsmod | awk '{printf "%s " $1}') "
185 for module in $(ls | grep -v 'mperf\|speedstep-lib'); do
186 module="${module%.ko.xz}"; module="${module//-/_}"
187 if echo $lsmod | grep -q " $module "; then icon='@ok@'; else icon='@cancel@'; fi
188 echo "<tr><td><span data-icon=\"$icon\">$module</span></td><td>"
189 modinfo $module | awk -F: '$1=="description"{
190 gsub(/\(TM\)/,"™",$2); gsub(/\(R\)/,"®",$2);
191 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);
192 print $2}'
193 echo "</td></tr>"
194 done
195 cat <<EOT
196 </table>
197 </section>
198 EOT
199 fi
201 xhtml_footer
202 exit 0