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