-
Notifications
You must be signed in to change notification settings - Fork 677
/
platform.ts
87 lines (76 loc) · 2.72 KB
/
platform.ts
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
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
'use strict';
import * as child_process from 'child_process';
export enum Platform {
Unknown,
Windows,
OSX,
CentOS,
Debian,
Fedora,
OpenSUSE,
RHEL,
Ubuntu14,
Ubuntu16
}
export function getCurrentPlatform() {
if (process.platform === 'win32') {
return Platform.Windows;
}
else if (process.platform === 'darwin') {
return Platform.OSX;
}
else if (process.platform === 'linux') {
// Get the text of /etc/os-release to discover which Linux distribution we're running on.
// For details: https://www.freedesktop.org/software/systemd/man/os-release.html
const text = child_process.execSync('cat /etc/os-release').toString();
const lines = text.split('\n');
function getValue(name: string) {
for (let line of lines) {
line = line.trim();
if (line.startsWith(name)) {
const equalsIndex = line.indexOf('=');
if (equalsIndex >= 0) {
let value = line.substring(equalsIndex + 1);
// Strip double quotes if necessary
if (value.length > 1 && value.startsWith('"') && value.endsWith('"')) {
value = value.substring(1, value.length - 1);
}
return value;
}
}
}
return undefined;
}
const id = getValue("ID");
switch (id)
{
case 'ubuntu':
const versionId = getValue("VERSION_ID");
if (versionId.startsWith("14")) {
// This also works for Linux Mint
return Platform.Ubuntu14;
}
else if (versionId.startsWith("16")) {
return Platform.Ubuntu16;
}
case 'centos':
return Platform.CentOS;
case 'fedora':
return Platform.Fedora;
case 'opensuse':
return Platform.OpenSUSE;
case 'rhel':
return Platform.RHEL;
case 'debian':
return Platform.Debian;
case 'ol':
// Oracle Linux is binary compatible with CentOS
return Platform.CentOS;
}
}
return Platform.Unknown;
}