1 | 1 | simandl | #!/usr/bin/env perl |
2 | | | |
3 | | | use warnings; |
4 | | | use diagnostics; |
5 | | | |
6 | | | use lib "../../lib"; |
7 | | | use HotSaNICparser; |
8 | | | use HotSaNICshellio; |
9 | | | |
10 | | | my @CONFmod=HotSaNICparser::read_settings(".",$MODNAME); |
11 | | | |
12 | | | if ( ! -e "settings" ) { $OUTFILE="settings"; } else { $OUTFILE="settings.new"; } |
13 | | | |
14 | | | open OUTFILE,">$OUTFILE" || die "could not open $MODNAME settings file for writing.\n"; |
15 | | | |
16 | | | print OUTFILE "# SHORT DESCRIPTION |
17 | | | # |
18 | | | # all entries have to be of the form: |
19 | | | # SENSOR=<device-file>,<dbname>,<description>,<entry>,<scale-factor>,<add>,<unit> |
20 | | | # |
21 | | | # <device-file> path to the file under /proc which holds the device-data |
22 | | | # |
23 | | | # <dbname> an unique filename for the database |
24 | | | # |
25 | | | # <description> a brief description for the webpage |
26 | | | # |
27 | | | # <entry> 2 for fan-speed and 3 for temperature and voltage |
28 | | | # this represents the position of the value in the |
29 | | | # proc-file |
30 | | | # |
31 | | | # <scale-factor> correction-factor to scale the data correctly |
32 | | | # ( to understand this look at the lm_sensors howto ) |
33 | | | # |
34 | | | # <add> value to add to shift the data correctly |
35 | | | # ( for e.g. +12V - see lm_sensors howto ) |
36 | | | # |
37 | | | # <unit> unit to be shown in diagrams and on webpage |
38 | | | # ( for example °C, V, Volts, RPM etc... ) |
39 | | | # |
40 | | | # Example: |
41 | | | # |
42 | | | # SENSOR=/proc/sys/dev/sensors/gl518sm-i2c-0-2d/temp,temp,CPU temp,3,1,0,°C |
43 | | | # |
44 | | | # |
45 | | | # |
46 | | | # FreeBSD Users: |
47 | | | # The only fields required are: |
48 | | | # <dbname> which is an item from the left column in 'mbmon -rc1' |
49 | | | # <description> as above |
50 | | | # <unit> as above |
51 | | | # |
52 | | | # Example: |
53 | | | # SENSOR=,TEMP0,Motherboard Temp,,,,C |
54 | | | "; |
55 | | | |
56 | | | if ($OUTFILE eq "settings.new") { |
57 | | | for (@CONFmod) { print OUTFILE $_,"\n" if /^SENSOR *=/; } |
58 | | | } |
59 | | | else { |
60 | | | my @files=(); |
61 | | | if ( -e "/proc/sys/dev/sensors") { |
62 | | | require File::Find; |
63 | | | $File::Find::name=""; # suppress stupid warning... |
64 | | | File::Find::find( {wanted => sub { lstat($_) && -f _ && push @files, $File::Find::name; } }, "/proc/sys/dev/sensors"); |
65 | | | } |
66 | | | |
67 | | | print "\n"; |
68 | | | |
69 | | | for $file (@files) { |
70 | | | if ( $file !~ /sensors\/(eeprom|chips)/ ) { |
71 | | | print $file,":\n"; |
72 | | | open FILE,$file; |
73 | | | $line=<FILE> || ""; |
74 | | | chomp $line; |
75 | | | print " ",$line,"\n"; |
76 | | | close FILE; |
77 | | | $input=HotSaNICshellio::askyesno("Do you want to use this file","n"); |
78 | | | if ($input eq "y") { |
79 | | | # configure sensor |
80 | | | # |
81 | | | @entries=split /\s/,$line; |
82 | | | ($dbname=$file) =~ s/.*\///g; |
83 | | | $descr="value"; |
84 | | | $unit="units"; |
85 | | | $device="some"; |
86 | | | if ( $dbname =~ /temp/ ) { $unit="°C"; $descr="temperature"; } |
87 | | | elsif ( $dbname =~ /v/ ) { $unit="Volts"; $descr="voltage"; } |
88 | | | elsif ( $dbname =~ /fan/ ) { $unit="RPM"; $descr="speed"; } |
89 | | | if ( $dbname =~ /vdd/) { $device="CPU"; } |
90 | | | print "SENSOR=$file,$dbname,$device $descr,".($#entries+1).",1,0,$unit\n" |
91 | | | } |
92 | | | } |
93 | | | print "\n"; |
94 | | | } |
95 | | | } |
96 | | | |
97 | | | close OUTFILE; |
98 | | | |
99 | | | if ($OUTFILE eq "settings.new") { |
100 | | | HotSaNICparser::backup_file("settings"); |
101 | | | rename "settings.new","settings"; |
102 | | | } |
103 | | | |
104 | | | if ($^O eq "freebsd") { |
105 | | | print "FreeBSD support is ONLY via xmbmon |
106 | | | (http://www.nt.phys.kyushu-u.ac.jp/shimizu/download/) version 2.0 or greater. |
107 | | | Please ensure you have this installed. |
108 | | | "; |
109 | | | } |
110 | | | |
111 | | | print "Please check the settings file and adapt it to satisfy your needs. |
112 | | | for your info: this configuration is a bit tricky\n"; |
113 | | | |
114 | | | |
115 | | | |