| 1 | 1 | simandl | #!/usr/bin/env perl |
| 2 | | | |
| 3 | | | # $Id: setup.pl,v 1.19 2004/08/27 09:58:33 laggyluke Exp $ |
| 4 | | | |
| 5 | | | # include PERL libraries |
| 6 | | | use strict; |
| 7 | | | use warnings; |
| 8 | | | use diagnostics; |
| 9 | | | |
| 10 | | | # include HotSaNIC libraries |
| 11 | | | use lib "../../lib"; |
| 12 | | | use lib "./platform"; |
| 13 | | | use HotSaNICparser; |
| 14 | | | use HotSaNICshellio; |
| 15 | | | use HotSaNIClog; |
| 16 | | | use common; |
| 17 | | | |
| 18 | | | $|=1; |
| 19 | | | |
| 20 | | | (my $VERSION = '$Revision: 1.19 $') =~ s/.*(\d+\.\d+).*/$1/; |
| 21 | | | (my $IDENTIFIER = '$Id: setup.pl,v 1.19 2004/08/27 09:58:33 laggyluke Exp $') =~ s/.*,v (.*) \$/$1/; |
| 22 | | | |
| 23 | | | my $MODNAME=HotSaNICparser::get_module_name(); |
| 24 | | | my %MODCONF=HotSaNICmod::common::configure(); |
| 25 | | | my $OUTFILE="settings.new"; |
| 26 | | | if ( ! -e "settings" ) { $OUTFILE="settings"; } |
| 27 | | | open OUTFILE,">$OUTFILE" || die "could not open ".HotSaNICparser::get_module_name()." settings file for writing.\n"; |
| 28 | | | |
| 29 | | | if (! @{$MODCONF{SENSOR}}) { @{$MODCONF{SENSOR}}=get_sensors(); } |
| 30 | | | if (@{$MODCONF{SENSOR}}) { $MODCONF{SENSOR}="SENSOR=\"".join("\"\nSENSOR=\"",@{$MODCONF{SENSOR}})."\""; } |
| 31 | | | else { $MODCONF{SENSOR}=""; } |
| 32 | | | |
| 33 | | | print OUTFILE "# SHORT DESCRIPTION |
| 34 | | | # |
| 35 | | | # all entries have to be of the form: |
| 36 | | | # SENSOR=<device-file>,<dbname>,<description>,<entry>,<scale-factor>,<add>,<unit>,<min>,<max> |
| 37 | | | # |
| 38 | | | # <device-file> path to the file under /proc which holds the device-data |
| 39 | | | # You may also enter a binary here, followed by a pipe symbol (|) |
| 40 | | | # |
| 41 | | | # <dbname> an unique filename for the database |
| 42 | | | # |
| 43 | | | # <description> a brief description for the webpage |
| 44 | | | # |
| 45 | | | # <entry> 2 for fan-speed and 3 for temperature and voltage |
| 46 | | | # this represents the position of the value in the |
| 47 | | | # proc-file |
| 48 | | | # |
| 49 | | | # <scale-factor> correction-factor to scale the data correctly |
| 50 | | | # ( to understand this look at the lm_sensors howto ) |
| 51 | | | # |
| 52 | | | # <add> value to add to shift the data correctly |
| 53 | | | # ( for e.g. +12V - see lm_sensors howto ) |
| 54 | | | # |
| 55 | | | # <unit> unit to be shown in diagrams and on webpage |
| 56 | | | # ( for example °C, V, Volts, RPM etc... ) |
| 57 | | | # |
| 58 | | | # <min>,<max> allowed value for this sensor |
| 59 | | | # these should be set according to the sensors warning levels |
| 60 | | | # the min/max range is shown in the diagrams by pink lines |
| 61 | | | # |
| 62 | | | # Examples: |
| 63 | | | # |
| 64 | | | # SENSOR=/proc/sys/dev/sensors/gl518sm-i2c-0-2d/temp,temp,CPU temp,3,1,0,°C,50,60 |
| 65 | | | # |
| 66 | | | # SENSOR=\"/usr/sbin/hddtemp -n /dev/hda |\",hda,HDD1,1,1,0,°C,40,60 |
| 67 | | | # |
| 68 | | | # |
| 69 | | | # FreeBSD and NetBSD Users: |
| 70 | | | # The fields are the same as above but the folowing with a different meaning: |
| 71 | | | # |
| 72 | | | # <device-file> use 'mbmon' if you want to read date from it, be sure to have it installed, |
| 73 | | | # or fill in the path to a program. |
| 74 | | | # and one value per line |
| 75 | | | # |
| 76 | | | # <dbname> an unique filename for the database and for mbmon it is the Data line to |
| 77 | | | # store - check output from 'mbmon -rc1'. It's case sensitive. |
| 78 | | | # |
| 79 | | | # <entry> entry isn't used by mbmon. If you have configured another program, entry |
| 80 | | | # is the line where your data is. |
| 81 | | | # |
| 82 | | | # Example: |
| 83 | | | # SENSOR=mbmon,TEMP0,Temperature 0,0,1,0,°C,0,50 |
| 84 | | | # SENSOR=\"/usr/sbin/hddtemp -n /dev/hda |\",hda,HDD1,1,1,0,°C,40,60 |
| 85 | | | # |
| 86 | | | $MODCONF{SENSOR} |
| 87 | | | "; |
| 88 | | | |
| 89 | | | close OUTFILE; |
| 90 | | | |
| 91 | | | if ($OUTFILE eq "settings.new") { |
| 92 | | | HotSaNICparser::backup_file("settings"); |
| 93 | | | rename "settings.new","settings"; |
| 94 | | | } |
| 95 | | | |
| 96 | | | if ($^O eq "freebsd" || $^O eq "netbsd" ) { |
| 97 | | | my $mbmon=`which mbmon`; |
| 98 | | | chomp $mbmon; |
| 99 | | | if ( ! $mbmon ) { |
| 100 | | | print "sensor module on ",$^O," needs mbmon to work propperly.\n"; |
| 101 | | | print "look out for mbmon in your package/ports-tree "; |
| 102 | | | print "or\n http://www.nt.phys.kyushu-u.ac.jp/shimizu/download/download.html. \n"; |
| 103 | | | print "Please ensure you have this installed and rerun setup.pl\n\n"; |
| 104 | | | exit 0; |
| 105 | | | } else { |
| 106 | | | open FILE,">> settings" |
| 107 | | | or die "cant open settings: $!"; |
| 108 | | | print FILE "SENSOR=mbmon,TEMP0,Temperature 0,0,1,0,°C,0,50\n"; |
| 109 | | | close FILE; |
| 110 | | | } |
| 111 | | | } |
| 112 | | | |
| 113 | | | print "Please check the settings file and adapt it to satisfy your needs. |
| 114 | | | for your info: this configuration is a bit tricky\n"; |
| 115 | | | |
| 116 | | | |
| 117 | | | sub get_sensors { |
| 118 | | | my @files=(); |
| 119 | | | if ( -e "/proc/sys/dev/sensors") { |
| 120 | | | require File::Find; |
| 121 | | | $File::Find::name=""; # suppress stupid warning... |
| 122 | | | File::Find::find( {wanted => sub { lstat($_) && -f _ && push @files, $File::Find::name; } }, "/proc/sys/dev/sensors"); |
| 123 | | | } |
| 124 | | | |
| 125 | | | print "\n"; |
| 126 | | | |
| 127 | | | my @sensors=(); |
| 128 | | | for my $file (@files) { |
| 129 | | | if ( $file !~ /sensors\/(eeprom|chips)/ ) { |
| 130 | | | print $file,":\n"; |
| 131 | | | open FILE,$file; |
| 132 | | | my $line=<FILE> || ""; |
| 133 | | | chomp $line; |
| 134 | | | print " ",$line,"\n"; |
| 135 | | | close FILE; |
| 136 | | | my $input=HotSaNICshellio::askyesno("Do you want to use this file","n"); |
| 137 | | | if ($input eq "y") { |
| 138 | | | # configure sensor |
| 139 | | | # |
| 140 | | | my @entries=split /\s/,$line; |
| 141 | | | (my $dbname=$file) =~ s/.*\///g; |
| 142 | | | my $descr="value"; |
| 143 | | | my $unit="units"; |
| 144 | | | my $device="some"; |
| 145 | | | my $entry=$#entries+1; |
| 146 | | | my $min=(shift @entries)*1; # *1 to eliminate zeros after decimal point |
| 147 | | | my $max=$min; |
| 148 | | | if ($entry > 2) { $max=(shift @entries)*1; } |
| 149 | | | if ($min > $max) { ($min,$max)=($max,$min); } |
| 150 | | | if ( $dbname =~ /temp/ ) { $unit="°C"; $descr="temperature"; } |
| 151 | | | elsif ( $dbname =~ /v/ ) { $unit="Volts"; $descr="voltage"; } |
| 152 | | | elsif ( $dbname =~ /fan/ ) { $unit="RPM"; $descr="speed"; } |
| 153 | | | if ( $dbname =~ /vdd/) { $device="CPU"; } |
| 154 | | | push @sensors,"$file,$dbname,$device $descr,$entry,1,0,$unit,$min,$max" |
| 155 | | | } |
| 156 | | | } |
| 157 | | | print "\n"; |
| 158 | | | } |
| 159 | | | return @sensors; |
| 160 | | | } |
| 161 | | | |