-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
hotdog-generateDiskMenu.pl~freebsd
executable file
·92 lines (76 loc) · 2.16 KB
/
hotdog-generateDiskMenu.pl~freebsd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#!/usr/bin/env perl
@lines = `geom disk list`;
chomp @lines;
%disks = ();
%diskmediasize = ();
%diskdescr = ();
$name = '';
foreach $line (@lines) {
if ($line =~ m/^\d+\.\s+Name:\s+(.+)$/) {
$name = $1;
$disks{$name} = $name;
} elsif ($name) {
if ($line =~ m/^\s+Mediasize:\s+\d+\s+\(([^\)]+)\)/) {
$diskmediasize{$name} = $1;
} elsif ($line =~ m/^\s+descr:\s+(.*)/) {
$diskdescr{$name} = $1;
}
}
}
@lines = `geom part list`;
chomp @lines;
$geomname = '';
$scheme = '';
$name = '';
$mediasize = '';
$type = '';
print sprintf("%-12.12s %-8.8s %-20.20s %-8.8s %-8.8s %s\n", 'NAME', 'TYPE', 'LABEL', 'SIZE', 'USED', 'MOUNTPOINT');
sub print_elt
{
if ($name) {
@dflines = `df /dev/$name 2>/dev/null`;
chomp @dflines;
shift @dflines;
$mountpoint = shift @dflines;
$mountpoint =~ s/^\S+\s+//;
$mountpoint =~ s/^\S+\s+//;
$mountpoint =~ s/^\S+\s+//;
$mountpoint =~ s/^\S+\s+//;
$capacity = '';
if ($mountpoint =~ s/^(\S+)\s+//) {
$capacity = $1;
}
$mountpoint =~ s/([%\s])/sprintf '%%%02x', ord $1/eg;
print sprintf(" %-10.10s %-8.8s %-20.20s %-8.8s %-8.8s %s\n", $name, $type, '', $mediasize, $capacity, $mountpoint);
}
$name = '';
$mediasize = '';
$type = '';
}
$providers = 0;
foreach $line (@lines) {
if ($line =~ m/^Providers:/) {
$providers = 1;
} elsif ($line =~ m/^Consumers:/) {
$providers = 0;
} elsif ($line =~ m/^Geom name:\s+(.+)/) {
$geomname = $1;
if ($disks{$geomname}) {
print sprintf("%-12.12s %-8.8s %-20.20s %s\n", $geomname, '', $diskdescr{$geomname}, $diskmediasize{$geomname});
}
} elsif ($line =~ m/^\d+\.\s+Name:\s+(.+)$/) {
$newName = $1;
print_elt();
if ($newName =~ m/^diskid\//) {
} elsif ($providers) {
$name = $newName;
}
} elsif ($name) {
if ($line =~ m/^\s+Mediasize:\s+\d+\s+\(([^\)]+)\)/) {
$mediasize = $1;
} elsif ($line =~ m/^\s+type:\s+(.*)/) {
$type = $1;
}
}
}
exit 0;