#!/usr/bin/perl

use strict;
use lib qw(/usr/lib/libDrakX);
use common;
use detect_devices;
use Libconf qw(:functions);
use Libconf::Glueconf::Ups;

#------------------------------------------------------------------
# UPS autoconfig:

my $file = "/etc/ups/ups.conf";

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->{name} || $ups_device->{DESCRIPTION};
    $str =~ s/ /_/g;

    if (!exists $struct->{$str}) { 
	    $struct->{$str}{port} = $ups_device->{port} || $ups_device->{DEVICE};
	    $struct->{$str}{driver} = $ups_device->{driver};
    }
}

$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);