/
Distro.pm
93 lines (86 loc) · 2.85 KB
/
Distro.pm
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
92
93
# The Distro class and its methods, underlying $*DISTRO, are a work in progress.
# It is very hard to capture data about a changing universe in a stable API.
# If you find errors for your hardware or OS distribution, please report them
# with the values that you expected and how to get them in your situation.
class Distro does Systemic {
has Str $.release;
has Bool $.is-win;
has Str $.path-sep;
submethod BUILD (
:$name,
:$version,
:$!release,
:$!auth,
:$!path-sep,
:$!signature = Blob,
:$!desc = Str
--> Nil
) {
$!name = $name.lc; # lowercase
$!name ~~ s:g/" "//; # spaceless
$!version = Version.new($version);
$!is-win = so $!name eq any <mswin32 mingw msys cygwin>;
}
# This is a temporary migration method needed for installation
method cur-sep() { "," }
}
sub INITIALIZE-A-DISTRO-NOW() {
#?if jvm
my $properties := INITIALIZE-A-VM-NOW.properties;
my $name := $properties<os.name>;
my $version := $properties<os.version>;
my $path-sep := $properties<path.separator>;
#?endif
#?if !jvm
my $config := INITIALIZE-A-VM-NOW.config;
my $name := $config<osname>;
my $version := $config<osvers>;
my $path-sep := $name eq 'MSWin32' ?? ';' !! ':';
#?endif
my Str $release := "unknown";
my Str $auth := "unknown";
# darwin specific info
if $name eq 'darwin' {
if qx/sw_vers/ ~~ m/^
ProductName\: \s+ (<[\w\ ]>+) \s+
ProductVersion\: \s+ (<[\d\.]>+) \s+
BuildVersion\: \s+ (<[\w\d]>+)
/ {
$name := ~$0;
$version := ~$1;
$release := ~$2;
}
else {
$name := 'Mac OS X'; # we assume
$version := "unknown";
$release := qx/uname -r/.chomp;
}
$auth := 'Apple Computer, Inc.'; # presumably
}
elsif Rakudo::Internals.FILETEST-E('/etc/os-release') {
$_ := '/etc/os-release'.IO.slurp.subst(:g, '"','');
$auth := ~$0 if m/^^ HOME_URL \= (\N*) /;
$name := ~$0 if m/^^ ID \= (\N*) /;
$version := ~$0 if m/^^ VERSION \= (\N*) /;
$release := ~$0 if m/^^ VERSION_ID \= (\N*) /;
}
elsif $name eq 'linux' {
if try qx{lsb_release -a 2> /dev/null} ~~ m/
Distributor \s+ ID\: \s+ (<[\w\ ]>+) \s+
Description\: \s+ (<[\w\ ]>+) \s+ (<[\d\.]>+) \s+
Release\: \s+ (<[\d\.]>+)
/ {
$auth := ~$0;
$name := ~$1;
$version := ~$2;
$release := ~$3;
}
}
my $desc := DateTime.now.Str;
Distro.new(:$name, :$version, :$release, :$auth, :$path-sep, :$desc);
}
# set up $*DISTRO
Rakudo::Internals.REGISTER-DYNAMIC: '$*DISTRO', {
PROCESS::<$DISTRO> := INITIALIZE-A-DISTRO-NOW();
}
# vim: ft=perl6 expandtab sw=4