summaryrefslogtreecommitdiffstats
path: root/perl-install/standalone/drakups
diff options
context:
space:
mode:
authorThierry Vignaud <tvignaud@mandriva.org>2003-10-31 13:07:54 +0000
committerThierry Vignaud <tvignaud@mandriva.org>2003-10-31 13:07:54 +0000
commit3f747ebc412e2aae4f9739cea2461f978f7a3e32 (patch)
tree46808b4099cc224ca9a5b93869859c9345e5acca /perl-install/standalone/drakups
parent19c5811d959822dd6fdb46713b2b03e7462b8930 (diff)
downloaddrakx-3f747ebc412e2aae4f9739cea2461f978f7a3e32.tar
drakx-3f747ebc412e2aae4f9739cea2461f978f7a3e32.tar.gz
drakx-3f747ebc412e2aae4f9739cea2461f978f7a3e32.tar.bz2
drakx-3f747ebc412e2aae4f9739cea2461f978f7a3e32.tar.xz
drakx-3f747ebc412e2aae4f9739cea2461f978f7a3e32.zip
auto config ups devices
Diffstat (limited to 'perl-install/standalone/drakups')
-rwxr-xr-xperl-install/standalone/drakups66
1 files changed, 66 insertions, 0 deletions
diff --git a/perl-install/standalone/drakups b/perl-install/standalone/drakups
new file mode 100755
index 000000000..3ae1bb2bd
--- /dev/null
+++ b/perl-install/standalone/drakups
@@ -0,0 +1,66 @@
+#!/usr/bin/perl
+
+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);
+}
+#------------------------------------------------------------------
+
+#------------------------------------------------------------------
+# UPS autoconfig:
+
+my $file = "/etc/ups/ups.conf";
+my ($sections, $sec_contents) = read_all_gnomekderc($file);
+
+my @ups_devices = map { $_->[0] } @$sections; #sort values %$sec_contents
+
+foreach my $ups_device (detect_devices::getUPS()) {
+ if (!member($ups_device, @ups_devices)) {
+ my $str = $ups_device->{description};
+ $str =~ s/ /_/g;
+ push @$sections, [ $str, [ qw(driver port) ] ];
+ $sec_contents->{$str} = {
+ port => 1,
+ driver => $ups_device->{bus} eq 'USB' ? "/dev/usb/hid/hiddev0" : $ups_device->{device},
+ };
+ }
+}
+
+update_all_gnomekderc($file, $sections, $sec_contents);