@@ -13,7 +13,9 @@ internal enum Platform
13
13
Windows = 1 ,
14
14
Linux = 2 ,
15
15
Darwin = 3 ,
16
- FreeBSD = 4
16
+ FreeBSD = 4 ,
17
+ illumos = 5 ,
18
+ Solaris = 6
17
19
}
18
20
19
21
internal static class RuntimeEnvironment
@@ -36,15 +38,19 @@ private static string GetOSName()
36
38
switch ( GetOSPlatform ( ) )
37
39
{
38
40
case Platform . Windows :
39
- return " Windows" ;
41
+ return nameof ( Platform . Windows ) ;
40
42
case Platform . Linux :
41
- return GetDistroId ( ) ?? " Linux" ;
43
+ return GetDistroId ( ) ?? nameof ( Platform . Linux ) ;
42
44
case Platform . Darwin :
43
45
return "Mac OS X" ;
44
46
case Platform . FreeBSD :
45
- return "FreeBSD" ;
47
+ return nameof ( Platform . FreeBSD ) ;
48
+ case Platform . illumos :
49
+ return GetDistroId ( ) ?? nameof ( Platform . illumos ) ;
50
+ case Platform . Solaris :
51
+ return nameof ( Platform . Solaris ) ;
46
52
default :
47
- return " Unknown" ;
53
+ return nameof ( Platform . Unknown ) ;
48
54
}
49
55
}
50
56
@@ -55,11 +61,16 @@ private static string GetOSVersion()
55
61
case Platform . Windows :
56
62
return Environment . OSVersion . Version . ToString ( 3 ) ;
57
63
case Platform . Linux :
64
+ case Platform . illumos :
58
65
return GetDistroVersionId ( ) ?? string . Empty ;
59
66
case Platform . Darwin :
60
67
return Environment . OSVersion . Version . ToString ( 2 ) ;
61
68
case Platform . FreeBSD :
62
69
return GetFreeBSDVersion ( ) ?? string . Empty ;
70
+ case Platform . Solaris :
71
+ // RuntimeInformation.OSDescription example on Solaris 11.3: SunOS 5.11 11.3
72
+ // we only need the major version; 11
73
+ return RuntimeInformation . OSDescription . Split ( ' ' ) [ 2 ] . Split ( '.' ) [ 0 ] ;
63
74
default :
64
75
return string . Empty ;
65
76
}
@@ -98,6 +109,19 @@ private static string GetDistroVersionId()
98
109
}
99
110
100
111
private static DistroInfo LoadDistroInfo ( )
112
+ {
113
+ switch ( GetOSPlatform ( ) )
114
+ {
115
+ case Platform . Linux :
116
+ return LoadDistroInfoFromLinux ( ) ;
117
+ case Platform . illumos :
118
+ return LoadDistroInfoFromIllumos ( ) ;
119
+ }
120
+
121
+ return null ;
122
+ }
123
+
124
+ private static DistroInfo LoadDistroInfoFromLinux ( )
101
125
{
102
126
DistroInfo result = null ;
103
127
@@ -138,6 +162,36 @@ private static DistroInfo LoadDistroInfo()
138
162
return result ;
139
163
}
140
164
165
+ private static DistroInfo LoadDistroInfoFromIllumos ( )
166
+ {
167
+ DistroInfo result = null ;
168
+ // examples:
169
+ // on OmniOS
170
+ // SunOS 5.11 omnios-r151018-95eaa7e
171
+ // on OpenIndiana Hipster:
172
+ // SunOS 5.11 illumos-63878f749f
173
+ // on SmartOS:
174
+ // SunOS 5.11 joyent_20200408T231825Z
175
+ var versionDescription = RuntimeInformation . OSDescription . Split ( ' ' ) [ 2 ] ;
176
+ switch ( versionDescription )
177
+ {
178
+ case string version when version . StartsWith ( "omnios" ) :
179
+ result . Id = "OmniOS" ;
180
+ result . VersionId = version . Substring ( "omnios-r" . Length , 2 ) ; // e.g. 15
181
+ break ;
182
+ case string version when version . StartsWith ( "joyent" ) :
183
+ result . Id = "SmartOS" ;
184
+ result . VersionId = version . Substring ( "joyent_" . Length , 4 ) ; // e.g. 2020
185
+ break ;
186
+ case string version when version . StartsWith ( "illumos" ) :
187
+ result . Id = "OpenIndiana" ;
188
+ // version-less
189
+ break ;
190
+ }
191
+
192
+ return result ;
193
+ }
194
+
141
195
// For some distros, we don't want to use the full version from VERSION_ID. One example is
142
196
// Red Hat Enterprise Linux, which includes a minor version in their VERSION_ID but minor
143
197
// versions are backwards compatable.
@@ -179,10 +233,20 @@ private static Platform DetermineOSPlatform()
179
233
{
180
234
return Platform . Darwin ;
181
235
}
182
- if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Create ( "FREEBSD" ) ) )
236
+ #if NETCOREAPP
237
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . FreeBSD ) )
183
238
{
184
239
return Platform . FreeBSD ;
185
240
}
241
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Create ( "ILLUMOS" ) ) )
242
+ {
243
+ return Platform . illumos ;
244
+ }
245
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Create ( "SOLARIS" ) ) )
246
+ {
247
+ return Platform . Solaris ;
248
+ }
249
+ #endif
186
250
187
251
return Platform . Unknown ;
188
252
}
0 commit comments