retrieve a system id
authorHeiko Schlittermann <hs@schlittermann.de>
Sun, 17 Jan 2010 00:00:02 +0100
changeset 8 2a66bb6a6a6e
parent 5 0352bb49b838
child 9 1a6f6cfc46ea
retrieve a system id
SI/system.pm
si
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SI/system.pm	Sun Jan 17 00:00:02 2010 +0100
@@ -0,0 +1,20 @@
+package SI::system;
+
+use strict;
+use warnings;
+use if $ENV{DEBUG} ~~ qw(system) => "Smart::Comments";
+
+$ENV{LC_ALL} = "C";
+
+sub id($) {
+    my ($file) = @_;
+    open(my $f, ">$file") or die "Can't open $file: $!\n";
+    # hope it's eth*
+    local $_ = (sort grep { /^(eth|wlan)/ } `ifconfig -a`)[0];
+    return if not $_;
+    return if not /^(?<dev>\S+)\s.*HWaddr\s+(?<mac>[\da-f:]+)\s*$/i;
+    print $f "ethernet $+{dev} $+{mac}\n";
+}
+
+1;
+# vim:sts=4 sw=4 aw ai si:
--- a/si	Sat Jan 16 22:11:43 2010 +0100
+++ b/si	Sun Jan 17 00:00:02 2010 +0100
@@ -5,6 +5,7 @@
 use warnings;
 use if $ENV{DEBUG} => "Smart::Comments";
 
+use SI::system;
 use SI::ptable;
 use SI::blkid;
 use SI::lvm;
@@ -16,6 +17,7 @@
 
 my %devices;
 
+SI::system::id("$OUT/system");
 SI::ptable::info("$OUT/partitions.%s", %devices);
 SI::blkid::info("$OUT/blkid", %devices);
 SI::lvm::vg_info("$OUT/vg.%s", %devices);