SI/system.pm
changeset 17 d4942418a9ea
parent 16 fd87c1e3b451
child 19 d12753b246fd
equal deleted inserted replaced
16:fd87c1e3b451 17:d4942418a9ea
     7 use SI::tools;
     7 use SI::tools;
     8 
     8 
     9 $ENV{LC_ALL} = "C";
     9 $ENV{LC_ALL} = "C";
    10 
    10 
    11 sub id() {
    11 sub id() {
       
    12 
    12     # hope it's eth* or wlan*
    13     # hope it's eth* or wlan*
    13     local $_ = (sort grep { /^(eth|wlan)/ } `ifconfig -a`)[0];
    14     local $_ = (sort grep { /^(eth|wlan)/ } `ifconfig -a`)[0];
    14     /^(?<dev>\S+)\s.*HWaddr\s+(?<mac>[\da-f:]+)\s*$/i
    15     /^(?<dev>\S+)\s.*HWaddr\s+(?<mac>[\da-f:]+)\s*$/i
    15     	and return $+{mac};
    16       and return $+{mac};
    16     die "ERR: Can't get system identification (MAC address)\n";
    17     die "ERR: Can't get system identification (MAC address)\n";
    17 }
    18 }
    18 
    19 
    19 sub hostname(\%) {
    20 sub hostname(\%) {
    20 	my $devs = shift;
    21     my $devs = shift;
    21 	my $mnt = tempdir(CLEANUP => 1);
    22     my $mnt = tempdir(CLEANUP => 1);
    22 	my $r;
    23     my $r;
    23 
    24 
    24 	foreach my $fs (grep { $devs->{volume}{$_}{type} =~ /^ext/i } 
    25     foreach my $fs (
    25 		grep { exists $devs->{volume}{$_}{type} }
    26         grep { $devs->{volume}{$_}{type} =~ /^ext/i }
    26 		keys %{$devs->{volume}}) {
    27         grep { exists $devs->{volume}{$_}{type} }
    27 		run("mount -r $fs $mnt");
    28         keys %{ $devs->{volume} }
    28 		if (-f "$mnt/etc/hostname") {
    29       )
    29 			die "ERR: found 2nd hostname" if defined $r;
    30     {
    30 			chomp($r = cat("$mnt/etc/hostname"));
    31         run("mount -r $fs $mnt");
    31 		}
    32         if (-f "$mnt/etc/hostname") {
    32 		run("umount $mnt");
    33             die "ERR: found 2nd hostname" if defined $r;
    33 	}
    34             chomp($r = cat("$mnt/etc/hostname"));
       
    35         }
       
    36         run("umount $mnt");
       
    37     }
    34 
    38 
    35 	return $r;
    39     return $r;
    36 }
    40 }
    37 
    41 
    38 1;
    42 1;
       
    43 
    39 # vim:sts=4 sw=4 aw ai si:
    44 # vim:sts=4 sw=4 aw ai si: