root/lm-sensors/tags/V3-0-1/etc/sensors-conf-convert

Revision 4990, 13.3 kB (checked in by khali, 1 year ago)

Use /etc/sensors3.conf as the default configuration file. If it can't
be found, fallback to /etc/sensors.conf. This allows for an old
libsensors and a new libsensors to be installed in parallel, and each
one has its own configuration file.

One important change here is that the default configuration file will
be installed as /etc/sensors3.conf by "make install".

  • Property svn:executable set to *
Line 
1 #!/usr/bin/perl -w -pi.old
2
3 # Convert a sensors.conf file from the old (Linux 2.4, lm-sensors 2)
4 # symbol names to the new (Linux 2.6, lm-sensors 3) symbol names.
5 #
6 # Copyright (C) 2007  Jean Delvare <khali@linux-fr.org>
7 #
8 # This program is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU General Public License
10 # as published by the Free Software Foundation; either version 2
11 # of the License, or (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
21 # MA 02110-1301, USA.
22
23 # Implemented conversions:
24 # * The "algorithm name" part of bus statements is removed.
25 # * Bus statements for the ISA bus are removed.
26 # * Chip names containing dashes are removed.
27 # * Label, ignore, set and compute statements referencing features
28 #   which are not part of the new interface are removed.
29 # * Label, ignore, set and compute statements referencing features
30 #   which have been renamed are updated. This includes both general
31 #   feature name changes and chip-specific feature name changes.
32 #
33 # Note that we have to look at the commented out lines too, so that
34 # the user doesn't have a bad surprise when uncommenting them.
35
36 use strict;
37 use vars qw($debug $chip %trans @delete %chip_trans %chip_delete);
38
39 BEGIN
40 {
41         $debug = 0;
42
43         %trans = (
44                 qr/\bvid\b/                     => sub { "cpu0_vid" },
45                 qr/\bremote_temp\b/             => sub { "temp2" },
46                 qr/\bremote_temp_hyst\b/        => sub { "temp2_max_hyst" },
47                 qr/\bremote_temp_low\b/         => sub { "temp2_min" },
48                 qr/\bremote_temp_over\b/        => sub { "temp2_max" },
49                 qr/\btemp\b/                    => sub { "temp1" },
50                 qr/\btemp_hyst\b/               => sub { "temp1_max_hyst" },
51                 qr/\btemp_low\b/                => sub { "temp1_min" },
52                 qr/\btemp_over\b/               => sub { "temp1_max" },
53                 qr/\btemp_high\b/               => sub { "temp1_max" },
54                 qr/\btemp_crit\b/               => sub { "temp1_crit" },
55
56                 qr/\bvin(\d+)_max\b/            => sub { "in$1_max" },
57                 qr/\bvin(\d+)_min\b/            => sub { "in$1_min" },
58                 qr/\bvin(\d+)\b/                => sub { "in$1" },
59                 qr/\btemp(\d+)_over\b/          => sub { "temp$1_max" },
60                 qr/\btemp(\d+)_hyst\b/          => sub { "temp$1_max_hyst" },
61                 qr/\btemp(\d+)_high\b/          => sub { "temp$1_max" },
62                 qr/\btemp(\d+)_low\b/           => sub { "temp$1_min" },
63                 qr/\bsensor(\d+)\b/             => sub { "temp$1_type" },
64         );
65
66         @delete = (
67                 qr/\balarms\b/,
68                 qr/\bbeeps\b/,
69                 qr/\bpwm\d*\b/,
70                 qr/\bpwm\d+_enable\b/,
71                 qr/\b(in|temp|fan)\d+_(state|status)\b/,
72                 qr/\banalog_out\b/,
73                 qr/\balarms_(in|temp|fan)\b/,
74         );
75
76         %chip_trans = (
77                 "gl518sm" => {
78                         qr/\bvdd\b/                     => sub { "in0" },
79                         qr/\bvdd_min\b/                 => sub { "in0_min" },
80                         qr/\bvdd_max\b/                 => sub { "in0_max" },
81                 },
82                 "gl520sm" => {
83                         qr/\bvdd\b/                     => sub { "in0" },
84                         qr/\bvdd_min\b/                 => sub { "in0_min" },
85                         qr/\bvdd_max\b/                 => sub { "in0_max" },
86                 },
87                 "lm80" => {
88                         qr/\btemp_hot_hyst\b/           => sub { "temp1_max_hyst" },
89                         qr/\btemp_hot_max\b/            => sub { "temp1_max" },
90                         qr/\btemp_os_hyst\b/            => sub { "temp1_crit_hyst" },
91                         qr/\btemp_os_max\b/             => sub { "temp1_crit" },
92                 },
93                 "lm83" => {
94                         qr/\btcrit\b/                   => sub { "temp3_crit" },
95                 },
96                 "lm90" => {
97                         qr/\btcrit(\d)\b/               => sub { "temp$1_crit" },
98                         qr/\bhyst(\d)\b/                => sub { "temp$1_crit_hyst" },
99                 },
100                 "adm1032" => {
101                         qr/\btcrit(\d)\b/               => sub { "temp$1_crit" },
102                         qr/\bhyst(\d)\b/                => sub { "temp$1_crit_hyst" },
103                 },
104                 "lm86" => {
105                         qr/\btcrit(\d)\b/               => sub { "temp$1_crit" },
106                         qr/\bhyst(\d)\b/                => sub { "temp$1_crit_hyst" },
107                 },
108                 "lm99" => {
109                         qr/\btcrit(\d)\b/               => sub { "temp$1_crit" },
110                         qr/\bhyst(\d)\b/                => sub { "temp$1_crit_hyst" },
111                 },
112                 "adt7461" => {
113                         qr/\btcrit(\d)\b/               => sub { "temp$1_crit" },
114                         qr/\bhyst(\d)\b/                => sub { "temp$1_crit_hyst" },
115                 },
116                 "max6657" => {
117                         qr/\btcrit(\d)\b/               => sub { "temp$1_crit" },
118                         qr/\bhyst(\d)\b/                => sub { "temp$1_crit_hyst" },
119                 },
120                 "max6680" => {
121                         qr/\btcrit(\d)\b/               => sub { "temp$1_crit" },
122                         qr/\bhyst(\d)\b/                => sub { "temp$1_crit_hyst" },
123                 },
124                 "lm93" => {
125                         qr/\bvid([12])\b/                       => sub { "cpu".($1-1)."_vid" },
126                 },
127                 "adm9240" => {
128                         qr/"2\.5V(|_min|_max)"/         => sub { "in0$1" },
129                         qr/\bVccp1(|_min|_max)\b/       => sub { "in1$1" },
130                         qr/"3\.3V(|_min|_max)"/         => sub { "in2$1" },
131                         qr/"5V(|_min|_max)"/            => sub { "in3$1" },
132                         qr/"12V(|_min|_max)"/           => sub { "in4$1" },
133                         qr/\bVccp2(|_min|_max)\b/       => sub { "in5$1" },
134                 },
135                 "lm81" => {
136                         qr/"2\.5V(|_min|_max)"/         => sub { "in0$1" },
137                         qr/\bVccp1(|_min|_max)\b/       => sub { "in1$1" },
138                         qr/"3\.3V(|_min|_max)"/         => sub { "in2$1" },
139                         qr/"5V(|_min|_max)"/            => sub { "in3$1" },
140                         qr/"12V(|_min|_max)"/           => sub { "in4$1" },
141                         qr/\bVccp2(|_min|_max)\b/       => sub { "in5$1" },
142                 },
143                 "ds1780" => {
144                         qr/"2\.5V(|_min|_max)"/         => sub { "in0$1" },
145                         qr/\bVccp1(|_min|_max)\b/       => sub { "in1$1" },
146                         qr/"3\.3V(|_min|_max)"/         => sub { "in2$1" },
147                         qr/"5V(|_min|_max)"/            => sub { "in3$1" },
148                         qr/"12V(|_min|_max)"/           => sub { "in4$1" },
149                         qr/\bVccp2(|_min|_max)\b/       => sub { "in5$1" },
150                 },
151                 "adm1024" => {
152                         qr/"2\.5V(|_min|_max)"/         => sub { "in0$1" },
153                         qr/\bVccp1(|_min|_max)\b/       => sub { "in1$1" },
154                         qr/"3\.3V(|_min|_max)"/         => sub { "in2$1" },
155                         qr/"5V(|_min|_max)"/            => sub { "in3$1" },
156                         qr/"12V(|_min|_max)"/           => sub { "in4$1" },
157                         qr/\bVccp2(|_min|_max)\b/       => sub { "in5$1" },
158                         qr/\btemp_hyst\b/               => sub { "temp1_min" },
159                         qr/\btemp(\d)\b/                => sub { "temp".($1+1) },
160                         qr/\btemp(\d)_hyst\b/           => sub { "temp".($1+1)."_min" },
161                         qr/\btemp(\d)_over\b/           => sub { "temp".($1+1)."_max" },
162                 },
163                 "maxilife" => {
164                         qr/\bvid(\d)(|_min|_max)\b/     => sub { "in".($1-1).$2 },
165                 },
166                 "thmc50" => {
167                         qr/\btemp_hyst\b/               => sub { "temp1_min" },
168                         qr/\bremote_temp_hyst\b/        => sub { "temp2_min" },
169                         qr/\bremote_temp2\b/            => sub { "temp3" },
170                         qr/\bremote_temp2_hyst\b/       => sub { "temp3_min" },
171                         qr/\bremote_temp2_over\b/       => sub { "temp3_max" },
172                 },
173                 "adm1022" => {
174                         qr/\btemp_hyst\b/               => sub { "temp1_min" },
175                         qr/\bremote_temp_hyst\b/        => sub { "temp2_min" },
176                         qr/\bremote_temp2\b/            => sub { "temp3" },
177                         qr/\bremote_temp2_hyst\b/       => sub { "temp3_min" },
178                         qr/\bremote_temp2_over\b/       => sub { "temp3_max" },
179                 },
180                 "adm1026" => {
181                         qr/\bfan(\d)(|_div|_min)\b/     => sub { "fan".($1+1).$2 },
182                         qr/\btemp(\d)_therm\b/          => sub { "temp$1_crit" },
183                 },
184                 "via686a" => {
185                         qr/"2\.0V"/                     => sub { "in0" },
186                         qr/"2\.5V"/                     => sub { "in1" },
187                         qr/"3\.3V"/                     => sub { "in2" },
188                         qr/"5\.0V"/                     => sub { "in3" },
189                         qr/"12V"/                       => sub { "in4" },
190                 },
191                 "lm87" => {
192                         qr/"2\.5V(|_min|_max)"/         => sub { "in0$1" },
193                         qr/\bVccp1(|_min|_max)\b/       => sub { "in1$1" },
194                         qr/"3\.3V(|_min|_max)"/         => sub { "in2$1" },
195                         qr/"5V(|_min|_max)"/            => sub { "in3$1" },
196                         qr/"12V(|_min|_max)"/           => sub { "in4$1" },
197                         qr/\bVccp2(|_min|_max)\b/       => sub { "in5$1" },
198                         qr/\bAIN1(|_min|_max)\b/        => sub { "in6$1" },
199                         qr/\bAIN2(|_min|_max)\b/        => sub { "in7$1" },
200                         qr/\bCPU_Temp\b/                => sub { "temp2" },
201                 },
202                 "fscpos" => {
203                         qr/\bvolt12\b/                  => sub { "in0" },
204                         qr/\bvolt5\b/                   => sub { "in1" },
205                         qr/\bvoltbatt\b/                => sub { "in2" },
206                 },
207                 "fscscy" => {
208                         qr/\bvolt12\b/                  => sub { "in0" },
209                         qr/\bvolt5\b/                   => sub { "in1" },
210                         qr/\bvoltbatt\b/                => sub { "in2" },
211                 },
212                 "pcf8591" => {
213                         qr/\bch(\d)\b/                  => sub { "in$1" },
214                 },
215                 "smsc47m192" => {
216                         qr/\btemp(\d)_input_fault\b/    => sub { "temp$1_fault" },
217                 },
218                 "lm92" => {
219                         qr/\btemp_hyst\b/               => sub { "temp1_crit_hyst" },
220                 },
221                 "max1619" => {
222                         qr/\btemp2_hyst\b/              => sub { "temp2_crit_hyst" },
223                 },
224                 "lm78" => {
225                         qr/\bin([56])_(min|max)\b/      => sub { "in$1_".($2 eq "max" ? "min" : "max") },
226                 },
227                 "lm79" => {
228                         qr/\bin([56])_(min|max)\b/      => sub { "in$1_".($2 eq "max" ? "min" : "max") },
229                 },
230                 "w83781d" => {
231                         qr/\bin([56])_(min|max)\b/      => sub { "in$1_".($2 eq "max" ? "min" : "max") },
232                 },
233                 "as99127f" => {
234                         qr/\bin([56])_(min|max)\b/      => sub { "in$1_".($2 eq "max" ? "min" : "max") },
235                 },
236         );
237
238         %chip_delete = (
239                 "adm1021" => [
240                         qr/\bdie_code\b/,
241                 ],
242                 "lm84" => [
243                         qr/\bdie_code\b/,
244                 ],
245                 "gl523" => [
246                         qr/\bdie_code\b/,
247                 ],
248                 "thmc10" => [
249                         qr/\bdie_code\b/,
250                 ],
251                 "gl518sm" => [
252                         qr/\bfan1_off\b/,
253                         qr/\bfan1_off_pin\b/,
254                         qr/\biterate\b/,
255                 ],
256                 "gl520sm" => [
257                         qr/\bfan1_off\b/,
258                         qr/\btwo_temps\b/,
259                 ],
260                 "w83792d" => [
261                         qr/\bchassis\b/,
262                 ],
263                 "w83793" => [
264                         qr/\bchassis\b/,
265                 ],
266                 "maxilife" => [
267                         qr/\bpll(|_min|_max)\b/,
268                 ],
269                 "thmc50" => [
270                         qr/\banalog output\b/,
271                         qr/\binterrupts\b/,
272                         qr/\binterrupt mask\b/,
273                         qr/\bdie_code\b/,
274                 ],
275                 "adm1022" => [
276                         qr/\banalog output\b/,
277                         qr/\binterrupts\b/,
278                         qr/\binterrupt mask\b/,
279                         qr/\bdie_code\b/,
280                 ],
281                 "adm1026" => [
282                         qr/\balarm_mask\b/,
283                         qr/\bgpio\b/,
284                         qr/\bgpio_mask\b/,
285                         qr/\bafc_pwm\b/,
286                         qr/\bafc_analog_out\b/,
287                         qr/\btemp\d_tmin\b/,
288                 ],
289                 "lm85" => [
290                         qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/,
291                         qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/,
292                         qr/\bfan\d_(tach_mode|ppr)\b/,
293                 ],
294                 "lm85b" => [
295                         qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/,
296                         qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/,
297                         qr/\bfan\d_(tach_mode|ppr)\b/,
298                 ],
299                 "lm85c" => [
300                         qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/,
301                         qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/,
302                         qr/\bfan\d_(tach_mode|ppr)\b/,
303                 ],
304                 "emc6d100" => [
305                         qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/,
306                         qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/,
307                         qr/\bfan\d_(tach_mode|ppr)\b/,
308                 ],
309                 "emc6d102" => [
310                         qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/,
311                         qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/,
312                         qr/\bfan\d_(tach_mode|ppr)\b/,
313                 ],
314                 "adm1027" => [
315                         qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/,
316                         qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/,
317                         qr/\bfan\d_(tach_mode|ppr)\b/,
318                 ],
319                 "adt7473" => [
320                         qr/\bpwm\d_(spinup|min|freq|min_ctl|zone|spinup_ctl)\b/,
321                         qr/\bzone\d_(limit|hyst|range|critical|smooth)\b/,
322                         qr/\bfan\d_(tach_mode|ppr)\b/,
323                 ],
324                 "fscpos" => [
325                         qr/\brev\b/,
326                         qr/\bevent\b/,
327                         qr/\bcontrol\b/,
328                         qr/\bfan\d_ripple\b/,
329                         qr/\bwdog_(preset|state|control)\b/,
330                 ],
331                 "fscscy" => [
332                         qr/\brev\b/,
333                         qr/\bevent\b/,
334                         qr/\bcontrol\b/,
335                         qr/\btemp\d_lim\b/,
336                         qr/\bfan\d_ripple\b/,
337                         qr/\bwdog_(preset|state|control)\b/,
338                 ],
339                 "fscher" => [
340                         qr/\brev\b/,
341                         qr/\bevent\b/,
342                         qr/\bcontrol\b/,
343                         qr/\bfan\d_ripple\b/,
344                         qr/\bwdog_(preset|state|control)\b/,
345                 ],
346                 "pcf8591" => [
347                         qr/\bain_conf\b/,
348                         qr/\baout_enable\b/,
349                         qr/\baout\b/,
350                 ],
351                 "vt1211" => [
352                         qr/\bconfig\b/,
353                 ],
354                 "vt8231" => [
355                         qr/\bconfig\b/,
356                 ],
357                 "max6650" => [
358                         qr/\bspeed\b/,
359                 ],
360                 "max6651" => [
361                         qr/\bspeed\b/,
362                 ],
363                 "applesmc" => [
364                         qr/\bfan\d_(max|safe)\b/,
365                 ],
366         );
367
368         if (defined $ARGV[0] && ($ARGV[0] eq '-h' || $ARGV[0] eq '--help')) {
369                 print "Convert sensors.conf from lm-sensors 2 format to lm-sensors 3 format\n",
370                       "Typical usage: sensors-conf-convert < /etc/sensors.conf > /etc/sensors3.conf\n";
371                 exit 0;
372         }
373 }
374
375 if ($. == 1) {
376         print "# Converted by sensors-conf-convert on ".localtime()."\n";
377 }
378
379 sub substitute_line($$)
380 {
381         my ($chip, $line) = @_;
382
383         # First the chip-specific ones
384         if ($chip && exists $chip_trans{$chip}) {
385                 foreach my $t (keys %{$chip_trans{$chip}}) {
386                         $line =~ s/$t/$chip_trans{$chip}->{$t}->()/ge;
387                 }
388         }
389
390         # Then the general substitutions
391         foreach my $t (keys %trans) {
392                 # Kudos to the nice folks in #perl on freenode :)
393                 $line =~ s/$t/$trans{$t}->()/ge;
394         }
395
396         return $line;
397 }
398
399 sub delete_line($)
400 {
401         my $feature = shift;
402
403         # First the general deletions
404         foreach my $t (@delete) {
405                 return 1 if $feature =~ m/$t/;
406         }
407
408         # Then the chip-specific ones
409         if ($chip && exists $chip_delete{$chip}) {
410                 foreach my $t (@{$chip_delete{$chip}}) {
411                         return 1 if $feature =~ m/$t/;
412                 }
413         }
414
415         return 0;
416 }
417
418 if (m/^# Converted by sensors-conf-convert/) {
419         print STDERR "WARNING: Converting an already converted file!\n";
420         print STDERR "         Result will be incorrect for some chip types.\n";
421 }
422
423 # Bus statements
424 if (m/^([\s#]*bus\s+"?i2c-\d+"?\s+"([^"]+)")\s+"[^"]*"/) {
425         print STDERR "Processing bus statement: $2\n" if $debug;
426
427         if ($2 eq "ISA main adapter") {
428                 $_ = '';        # Drop entirely
429         } else {
430                 $_ = "$1\n";    # Drop algorithm name
431         }
432 }
433
434 # Chip statements
435 elsif (m/^[\s#]*chip\s+"([\w\d*-]+)"/) {
436         # We only remember the first chip name, assuming that all chips
437         # in a given "chip" statement need the same specific processing
438         $chip = $1;
439         $chip =~ s/-.*//;
440         undef $chip if $chip eq "*";
441
442         # Remove dashes from chip names, as this is no longer allowed
443         s/(\s+"lm78-)j-/$1/g;
444         s/(\s+"maxilife-)(cg|co|as|nba)-/$1/g;
445         # Simplify possible duplicates
446         s/("lm78-\*")(\s+"lm78-\*")+/$1/g;
447         s/("maxilife-\*")(\s+"maxilife-\*")+/$1/g;
448
449         # "*" is no longer a valid chip name
450         s/"\*"/"\*-\*"/g;
451
452         print STDERR "Processing chip section: $chip\n" if $chip and $debug;
453 }
454
455 # Drop references to lm78-j
456 elsif (m/^\s*#+.*lm78-?j/i) {
457         s/(lm78), lm78-?j/$1/gi;
458         s/(lm78)-?j/$1/gi;
459 }
460
461 # Drop references to vrm
462 elsif (m/^[\s#]*set\s+vrm\s/i
463     || m/^\s*#+\s*adjust this if your vid is wrong/i
464     || m/^\s*#+\s*Also, one should set vrm prior to using vid in any formula/) {
465         $_ = '';
466 }
467
468 # Drop references to pwm
469 elsif (m/^\s*#+\s*PWM Output/i) {
470         $_ = '';
471 }
472
473 # Feature name substitution
474 elsif (m/^[\s#]*(?:label|ignore|set|compute)\s+(\S+)\s/) {
475         if (delete_line($1)) {
476                 # Delete references to features that are now gone
477                 $_ = '';
478         } else {
479                 # Substitute feature names
480                 $_ = substitute_line($chip, $_);
481         }
482 }
Note: See TracBrowser for help on using the browser.