hotsanic |
Subversion Repositories: |
Compare with Previous - Blame - Download
#!/usr/bin/env perl
# $Id: setup.pl,v 1.19 2004/08/27 09:58:33 laggyluke Exp $
# include PERL libraries
use strict;
use warnings;
use diagnostics;
# include HotSaNIC libraries
use lib "../../lib";
use lib "./platform";
use HotSaNICparser;
use HotSaNICshellio;
use HotSaNIClog;
use common;
$|=1;
(my $VERSION = '$Revision: 1.19 $') =~ s/.*(\d+\.\d+).*/$1/;
(my $IDENTIFIER = '$Id: setup.pl,v 1.19 2004/08/27 09:58:33 laggyluke Exp $') =~ s/.*,v (.*) \$/$1/;
my $MODNAME=HotSaNICparser::get_module_name();
my %MODCONF=HotSaNICmod::common::configure();
my $OUTFILE="settings.new";
if ( ! -e "settings" ) { $OUTFILE="settings"; }
open OUTFILE,">$OUTFILE" || die "could not open ".HotSaNICparser::get_module_name()." settings file for writing.\n";
if (! @{$MODCONF{SENSOR}}) { @{$MODCONF{SENSOR}}=get_sensors(); }
if (@{$MODCONF{SENSOR}}) { $MODCONF{SENSOR}="SENSOR=\"".join("\"\nSENSOR=\"",@{$MODCONF{SENSOR}})."\""; }
else { $MODCONF{SENSOR}=""; }
print OUTFILE "# SHORT DESCRIPTION
#
# all entries have to be of the form:
# SENSOR=<device-file>,<dbname>,<description>,<entry>,<scale-factor>,<add>,<unit>,<min>,<max>
#
# <device-file> path to the file under /proc which holds the device-data
# You may also enter a binary here, followed by a pipe symbol (|)
#
# <dbname> an unique filename for the database
#
# <description> a brief description for the webpage
#
# <entry> 2 for fan-speed and 3 for temperature and voltage
# this represents the position of the value in the
# proc-file
#
# <scale-factor> correction-factor to scale the data correctly
# ( to understand this look at the lm_sensors howto )
#
# <add> value to add to shift the data correctly
# ( for e.g. +12V - see lm_sensors howto )
#
# <unit> unit to be shown in diagrams and on webpage
# ( for example °C, V, Volts, RPM etc... )
#
# <min>,<max> allowed value for this sensor
# these should be set according to the sensors warning levels
# the min/max range is shown in the diagrams by pink lines
#
# Examples:
#
# SENSOR=/proc/sys/dev/sensors/gl518sm-i2c-0-2d/temp,temp,CPU temp,3,1,0,°C,50,60
#
# SENSOR=\"/usr/sbin/hddtemp -n /dev/hda |\",hda,HDD1,1,1,0,°C,40,60
#
#
# FreeBSD and NetBSD Users:
# The fields are the same as above but the folowing with a different meaning:
#
# <device-file> use 'mbmon' if you want to read date from it, be sure to have it installed,
# or fill in the path to a program.
# and one value per line
#
# <dbname> an unique filename for the database and for mbmon it is the Data line to
# store - check output from 'mbmon -rc1'. It's case sensitive.
#
# <entry> entry isn't used by mbmon. If you have configured another program, entry
# is the line where your data is.
#
# Example:
# SENSOR=mbmon,TEMP0,Temperature 0,0,1,0,°C,0,50
# SENSOR=\"/usr/sbin/hddtemp -n /dev/hda |\",hda,HDD1,1,1,0,°C,40,60
#
$MODCONF{SENSOR}
";
close OUTFILE;
if ($OUTFILE eq "settings.new") {
HotSaNICparser::backup_file("settings");
rename "settings.new","settings";
}
if ($^O eq "freebsd" || $^O eq "netbsd" ) {
my $mbmon=`which mbmon`;
chomp $mbmon;
if ( ! $mbmon ) {
print "sensor module on ",$^O," needs mbmon to work propperly.\n";
print "look out for mbmon in your package/ports-tree ";
print "or\n http://www.nt.phys.kyushu-u.ac.jp/shimizu/download/download.html. \n";
print "Please ensure you have this installed and rerun setup.pl\n\n";
exit 0;
} else {
open FILE,">> settings"
or die "cant open settings: $!";
print FILE "SENSOR=mbmon,TEMP0,Temperature 0,0,1,0,°C,0,50\n";
close FILE;
}
}
print "Please check the settings file and adapt it to satisfy your needs.
for your info: this configuration is a bit tricky\n";
sub get_sensors {
my @files=();
if ( -e "/proc/sys/dev/sensors") {
require File::Find;
$File::Find::name=""; # suppress stupid warning...
File::Find::find( {wanted => sub { lstat($_) && -f _ && push @files, $File::Find::name; } }, "/proc/sys/dev/sensors");
}
print "\n";
my @sensors=();
for my $file (@files) {
if ( $file !~ /sensors\/(eeprom|chips)/ ) {
print $file,":\n";
open FILE,$file;
my $line=<FILE> || "";
chomp $line;
print " ",$line,"\n";
close FILE;
my $input=HotSaNICshellio::askyesno("Do you want to use this file","n");
if ($input eq "y") {
# configure sensor
#
my @entries=split /\s/,$line;
(my $dbname=$file) =~ s/.*\///g;
my $descr="value";
my $unit="units";
my $device="some";
my $entry=$#entries+1;
my $min=(shift @entries)*1; # *1 to eliminate zeros after decimal point
my $max=$min;
if ($entry > 2) { $max=(shift @entries)*1; }
if ($min > $max) { ($min,$max)=($max,$min); }
if ( $dbname =~ /temp/ ) { $unit="°C"; $descr="temperature"; }
elsif ( $dbname =~ /v/ ) { $unit="Volts"; $descr="voltage"; }
elsif ( $dbname =~ /fan/ ) { $unit="RPM"; $descr="speed"; }
if ( $dbname =~ /vdd/) { $device="CPU"; }
push @sensors,"$file,$dbname,$device $descr,$entry,1,0,$unit,$min,$max"
}
}
print "\n";
}
return @sensors;
}