From 777a698b8d7898e7bd10d2dc86ea0b3e34b5748b Mon Sep 17 00:00:00 2001 From: Thierry Vignaud Date: Wed, 26 Nov 2003 16:39:04 +0000 Subject: - configure properly usb & serial connected mge devices - use perl-Libconf to shrink down the code size and better respect the user config file (keep important comments and the like - thx dam's for his support) --- perl-install/standalone/drakups | 66 +++++++++++------------------------------ 1 file changed, 17 insertions(+), 49 deletions(-) (limited to 'perl-install') diff --git a/perl-install/standalone/drakups b/perl-install/standalone/drakups index bb65aae02..08a3008c6 100755 --- a/perl-install/standalone/drakups +++ b/perl-install/standalone/drakups @@ -4,63 +4,31 @@ use strict; use lib qw(/usr/lib/libDrakX); use common; use detect_devices; - -#------------------------------------------------------------------ -# to be moved in MDK::Common as a generalisation of (read|update)_gnomekderc -# once cooker is unfrozen and major releases are allowed again. -# -# but there's a "bug" that prevent factorization: current -# (read|update)_gnomekderc keep comments ... and minimize intrusions - -sub read_all_gnomekderc { - my ($file) = @_; - my (@a, %h); - my ($section, @section); - foreach (MDK::Common::File::cat_($file)) { - s/#.*//; - if (/^\s*\[(.*)\]/) { - # remove all "if $section" tests if options out of sections is needed - push @a, [ $section, [ @section ] ] if $section; - $section = $1; - $h{$section} = { }; - @section = (); - } elsif (/^\s*(.*?)=(.*)/) { - push @section, $1; - $h{$section}{$1} = $2; - } - } - push @a, [ $section, [ @section ] ] if $section; - \@a, \%h; -} - -# lost comment but keep sections & options order: -sub update_all_gnomekderc { - my ($file, $list, $hvalues) = @_; - output($file, map { - my ($section, $items) = @$_; - "\n[$section]\n", map { $_ . "=" . $hvalues->{$section}{$_} . "\n" } @$items; - } @$list); -} -#------------------------------------------------------------------ +use Libconf qw(:functions); +use Libconf::Glueconf::Ups; #------------------------------------------------------------------ # UPS autoconfig: my $file = "/etc/ups/ups.conf"; -my ($sections, $sec_contents) = read_all_gnomekderc($file); -my @ups_devices = sort values %$sec_contents; +my $struct = Libconf::Glueconf::Ups->new('ups.conf'); #Libconf::Glueconf::ups->new($file, 'ups', ''); + +detect_devices::probeSerialDevices(); foreach my $ups_device (detect_devices::getUPS()) { - my $str = $ups_device->{description}; - if (!find { $str eq $_->{port} } @ups_devices) { - $str =~ s/ /_/g; - push @$sections, [ $str, [ qw(driver port) ] ]; - $sec_contents->{$str} = { - port => $ups_device->{bus} eq 'USB' ? "/dev/usb/hid/hiddev0" : $ups_device->{device}, - driver => $ups_device->{bus} eq 'USB' ? "hidups" : "", - }; + my $str = $ups_device->{name} || $ups_device->{DESCRIPTION}; + + if (!exists $struct->{$str}) { + $struct->{$str}{port} = $ups_device->{port} || $ups_device->{DEVICE}; + $struct->{$str}{driver} = $ups_device->{driver}; } } -update_all_gnomekderc($file, $sections, $sec_contents); +$struct->writeConf($file); + +my $drivers_table = glob("/usr/share/doc/nut-*/docs/driver.list"); + +# driver list from nutupsdrv(8) +my @drivers = qw(apcsmart bcmxcp belkin bestferrups801-807 bestfortress bestuferrups bestups cyberpower dummycons etapro everups fentonups genericups hidups hp isbmex liebert masterguard mge-shut mge-utalk microdowell newapc oneac powercom powernet sec sms snmp-ups tripplite tripplitesu victronups); + -- cgit v1.2.1