Skip to content

Commit 9be9001

Browse files
Update linux distro sniffing and OmniSharp download logic with new distros
1 parent bd6bf38 commit 9be9001

File tree

2 files changed

+60
-19
lines changed

2 files changed

+60
-19
lines changed

src/omnisharpDownload.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ export function getOmnisharpAssetName(): string {
3232
return `omnisharp-${OmniSharpVersion}-centos-x64-netcoreapp1.0.tar.gz`;
3333
case SupportedPlatform.Debian:
3434
return `omnisharp-${OmniSharpVersion}-debian-x64-netcoreapp1.0.tar.gz`;
35+
case SupportedPlatform.Fedora:
36+
return `omnisharp-${OmniSharpVersion}-fedora-x64-netcoreapp1.0.tar.gz`;
37+
case SupportedPlatform.OpenSUSE:
38+
return `omnisharp-${OmniSharpVersion}-opensuse-x64-netcoreapp1.0.tar.gz`;
3539
case SupportedPlatform.RHEL:
3640
return `omnisharp-${OmniSharpVersion}-rhel-x64-netcoreapp1.0.tar.gz`;
37-
case SupportedPlatform.Ubuntu:
38-
return `omnisharp-${OmniSharpVersion}-ubuntu-x64-netcoreapp1.0.tar.gz`;
41+
case SupportedPlatform.Ubuntu14:
42+
return `omnisharp-${OmniSharpVersion}-ubuntu14-x64-netcoreapp1.0.tar.gz`;
43+
case SupportedPlatform.Ubuntu16:
44+
return `omnisharp-${OmniSharpVersion}-ubuntu16-x64-netcoreapp1.0.tar.gz`;
3945

4046
default:
4147
if (process.platform === 'linux') {

src/utils.ts

Lines changed: 52 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ export enum SupportedPlatform {
1313
OSX,
1414
CentOS,
1515
Debian,
16+
Fedora,
17+
OpenSUSE,
1618
RHEL,
17-
Ubuntu
19+
Ubuntu14,
20+
Ubuntu16
1821
}
1922

2023
export function getSupportedPlatform() {
@@ -25,24 +28,56 @@ export function getSupportedPlatform() {
2528
return SupportedPlatform.OSX;
2629
}
2730
else if (process.platform === 'linux') {
28-
// Get the text of /etc/*-release to discover which Linux distribution we're running on.
29-
let release = child_process.execSync('cat /etc/os-release').toString().toLowerCase();
31+
// Get the text of /etc/os-release to discover which Linux distribution we're running on.
32+
// For details: https://www.freedesktop.org/software/systemd/man/os-release.html
33+
const text = child_process.execSync('cat /etc/os-release').toString();
34+
const lines = text.split('\n');
3035

31-
if (release.indexOf('ubuntu') >= 0) {
32-
return SupportedPlatform.Ubuntu;
33-
}
34-
else if (release.indexOf('centos') >= 0) {
35-
return SupportedPlatform.CentOS;
36-
}
37-
else if (release.indexOf('rhel') >= 0) {
38-
return SupportedPlatform.RHEL;
39-
}
40-
else if (release.indexOf('debian') >= 0) {
41-
return SupportedPlatform.Debian;
36+
function getValue(name: string) {
37+
for (let line of lines) {
38+
if (line.startsWith(name)) {
39+
const equalsIndex = line.indexOf('=');
40+
if (equalsIndex >= 0) {
41+
let value = line.substring(equalsIndex + 1);
42+
43+
// Strip double quotes if necessary
44+
if (value.length > 1 && value.startsWith('"') && value.endsWith('"')) {
45+
value = value.substring(1, value.length - 2);
46+
}
47+
48+
return value;
49+
}
50+
}
51+
}
52+
53+
return undefined;
4254
}
43-
else if (release.indexOf('oracle') >= 0) {
44-
// Oracle Linux is binary compatible with CentOS
45-
return SupportedPlatform.CentOS;
55+
56+
const id = getValue("ID");
57+
58+
switch (id)
59+
{
60+
case 'ubuntu':
61+
const versionId = getValue("VERSION_ID");
62+
if (versionId.startsWith("14")) {
63+
return SupportedPlatform.Ubuntu14;
64+
}
65+
else if (versionId.startsWith("16")) {
66+
return SupportedPlatform.Ubuntu16;
67+
}
68+
case 'centos':
69+
return SupportedPlatform.CentOS;
70+
case 'fedora':
71+
return SupportedPlatform.Fedora;
72+
case 'opensuse':
73+
return SupportedPlatform.OpenSUSE;
74+
case 'rehl':
75+
return SupportedPlatform.RHEL;
76+
case 'debian':
77+
return SupportedPlatform.Debian;
78+
case 'oracle':
79+
// Oracle Linux is binary compatible with CentOS
80+
return SupportedPlatform.CentOS;
4681
}
4782
}
4883

0 commit comments

Comments
 (0)