Skip to content

Commit bbe7dbe

Browse files
authored
feat(installer): start downloadinb Ubuntu 20.04 builds (#3126)
Start auto-detecting Ubuntu 20.04 and downloading custom webkit build for it. References #2745
1 parent 0b9c647 commit bbe7dbe

File tree

4 files changed

+72
-37
lines changed

4 files changed

+72
-37
lines changed

src/helper.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,14 @@
1818
import * as crypto from 'crypto';
1919
import { EventEmitter } from 'events';
2020
import * as fs from 'fs';
21+
import * as os from 'os';
2122
import * as removeFolder from 'rimraf';
2223
import * as util from 'util';
2324
import * as types from './types';
2425
import { Progress } from './progress';
2526

2627
const removeFolderAsync = util.promisify(removeFolder);
28+
const readFileAsync = util.promisify(fs.readFile.bind(fs));
2729

2830
export type RegisteredListener = {
2931
emitter: EventEmitter;
@@ -325,6 +327,45 @@ class Helper {
325327
}
326328
}
327329

330+
export async function getUbuntuVersion(): Promise<string> {
331+
if (os.platform() !== 'linux')
332+
return '';
333+
const osReleaseText = await readFileAsync('/etc/os-release', 'utf8').catch(e => '');
334+
if (!osReleaseText)
335+
return '';
336+
return getUbuntuVersionInternal(osReleaseText);
337+
}
338+
339+
export function getUbuntuVersionSync(): string {
340+
if (os.platform() !== 'linux')
341+
return '';
342+
try {
343+
const osReleaseText = fs.readFileSync('/etc/os-release', 'utf8');
344+
if (!osReleaseText)
345+
return '';
346+
return getUbuntuVersionInternal(osReleaseText);
347+
} catch (e) {
348+
return '';
349+
}
350+
}
351+
352+
function getUbuntuVersionInternal(osReleaseText: string): string {
353+
const fields = new Map();
354+
for (const line of osReleaseText.split('\n')) {
355+
const tokens = line.split('=');
356+
const name = tokens.shift();
357+
let value = tokens.join('=').trim();
358+
if (value.startsWith('"') && value.endsWith('"'))
359+
value = value.substring(1, value.length - 1);
360+
if (!name)
361+
continue;
362+
fields.set(name.toLowerCase(), value);
363+
}
364+
if (!fields.get('name') || fields.get('name').toLowerCase() !== 'ubuntu')
365+
return '';
366+
return fields.get('version_id') || '';
367+
}
368+
328369
export function assert(value: any, message?: string): asserts value {
329370
if (!value)
330371
throw new Error(message);

src/install/browserFetcher.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ const ENV_DOWNLOAD_HOSTS: { [key: string]: string } = {
5858
function getDownloadUrl(browserName: BrowserName, revision: number, platform: BrowserPlatform): string | undefined {
5959
if (browserName === 'chromium') {
6060
return new Map<BrowserPlatform, string>([
61-
['linux', '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip'],
61+
['ubuntu18.04', '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip'],
62+
['ubuntu20.04', '%s/chromium-browser-snapshots/Linux_x64/%d/chrome-linux.zip'],
6263
['mac10.13', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
6364
['mac10.14', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
6465
['mac10.15', '%s/chromium-browser-snapshots/Mac/%d/chrome-mac.zip'],
@@ -71,15 +72,17 @@ function getDownloadUrl(browserName: BrowserName, revision: number, platform: Br
7172
const FIREFOX_RENAME_LINUX_TO_UBUNTU_REVISION = 1139;
7273
return revision < FIREFOX_RENAME_LINUX_TO_UBUNTU_REVISION ?
7374
new Map<BrowserPlatform, string>([
74-
['linux', '%s/builds/firefox/%s/firefox-linux.zip'],
75+
['ubuntu18.04', '%s/builds/firefox/%s/firefox-linux.zip'],
76+
['ubuntu20.04', '%s/builds/firefox/%s/firefox-linux.zip'],
7577
['mac10.13', '%s/builds/firefox/%s/firefox-mac.zip'],
7678
['mac10.14', '%s/builds/firefox/%s/firefox-mac.zip'],
7779
['mac10.15', '%s/builds/firefox/%s/firefox-mac.zip'],
7880
['win32', '%s/builds/firefox/%s/firefox-win32.zip'],
7981
['win64', '%s/builds/firefox/%s/firefox-win64.zip'],
8082
]).get(platform) :
8183
new Map<BrowserPlatform, string>([
82-
['linux', '%s/builds/firefox/%s/firefox-ubuntu-18.04.zip'],
84+
['ubuntu18.04', '%s/builds/firefox/%s/firefox-ubuntu-18.04.zip'],
85+
['ubuntu20.04', '%s/builds/firefox/%s/firefox-ubuntu-18.04.zip'],
8386
['mac10.13', '%s/builds/firefox/%s/firefox-mac.zip'],
8487
['mac10.14', '%s/builds/firefox/%s/firefox-mac.zip'],
8588
['mac10.15', '%s/builds/firefox/%s/firefox-mac.zip'],
@@ -92,15 +95,17 @@ function getDownloadUrl(browserName: BrowserName, revision: number, platform: Br
9295
const WEBKIT_RENAME_LINUX_TO_UBUNTU_REVISION = 1315;
9396
return revision < WEBKIT_RENAME_LINUX_TO_UBUNTU_REVISION ?
9497
new Map<BrowserPlatform, string | undefined>([
95-
['linux', '%s/builds/webkit/%s/minibrowser-gtk-wpe.zip'],
98+
['ubuntu18.04', '%s/builds/webkit/%s/minibrowser-gtk-wpe.zip'],
99+
['ubuntu20.04', '%s/builds/webkit/%s/minibrowser-gtk-wpe.zip'],
96100
['mac10.13', undefined],
97101
['mac10.14', '%s/builds/webkit/%s/minibrowser-mac-10.14.zip'],
98102
['mac10.15', '%s/builds/webkit/%s/minibrowser-mac-10.15.zip'],
99103
['win32', '%s/builds/webkit/%s/minibrowser-win64.zip'],
100104
['win64', '%s/builds/webkit/%s/minibrowser-win64.zip'],
101105
]).get(platform) :
102106
new Map<BrowserPlatform, string | undefined>([
103-
['linux', '%s/builds/webkit/%s/minibrowser-gtk-wpe-ubuntu-18.04.zip'],
107+
['ubuntu18.04', '%s/builds/webkit/%s/minibrowser-gtk-wpe-ubuntu-18.04.zip'],
108+
['ubuntu20.04', '%s/builds/webkit/%s/minibrowser-gtk-wpe-ubuntu-20.04.zip'],
104109
['mac10.13', undefined],
105110
['mac10.14', '%s/builds/webkit/%s/minibrowser-mac-10.14.zip'],
106111
['mac10.15', '%s/builds/webkit/%s/minibrowser-mac-10.15.zip'],

src/install/browserPaths.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,13 @@
1818
import { execSync } from 'child_process';
1919
import * as os from 'os';
2020
import * as path from 'path';
21-
import { getFromENV } from '../helper';
21+
import { getFromENV, getUbuntuVersionSync } from '../helper';
2222

2323
export type BrowserName = 'chromium'|'webkit'|'firefox';
24-
export type BrowserPlatform = 'win32'|'win64'|'mac10.13'|'mac10.14'|'mac10.15'|'linux';
24+
export type BrowserPlatform = 'win32'|'win64'|'mac10.13'|'mac10.14'|'mac10.15'|'ubuntu18.04'|'ubuntu20.04';
2525
export type BrowserDescriptor = {
26-
name: BrowserName,
27-
revision: string
26+
name: BrowserName,
27+
revision: string
2828
};
2929

3030
export const hostPlatform = ((): BrowserPlatform => {
@@ -33,8 +33,14 @@ export const hostPlatform = ((): BrowserPlatform => {
3333
const macVersion = execSync('sw_vers -productVersion').toString('utf8').trim().split('.').slice(0, 2).join('.');
3434
return `mac${macVersion}` as BrowserPlatform;
3535
}
36-
if (platform === 'linux')
37-
return 'linux';
36+
if (platform === 'linux') {
37+
const ubuntuVersion = getUbuntuVersionSync();
38+
if (ubuntuVersion === '20.04')
39+
return 'ubuntu20.04';
40+
// For the sake of downloading logic, consider any other Linux distribution
41+
// to be "ubuntu18.04".
42+
return 'ubuntu18.04';
43+
}
3844
if (platform === 'win32')
3945
return os.arch() === 'x64' ? 'win64' : 'win32';
4046
return platform as BrowserPlatform;
@@ -58,7 +64,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):
5864
let tokens: string[] | undefined;
5965
if (browser.name === 'chromium') {
6066
tokens = new Map<BrowserPlatform, string[]>([
61-
['linux', ['chrome-linux', 'chrome']],
67+
['ubuntu18.04', ['chrome-linux', 'chrome']],
68+
['ubuntu20.04', ['chrome-linux', 'chrome']],
6269
['mac10.13', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
6370
['mac10.14', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
6471
['mac10.15', ['chrome-mac', 'Chromium.app', 'Contents', 'MacOS', 'Chromium']],
@@ -69,7 +76,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):
6976

7077
if (browser.name === 'firefox') {
7178
tokens = new Map<BrowserPlatform, string[]>([
72-
['linux', ['firefox', 'firefox']],
79+
['ubuntu18.04', ['firefox', 'firefox']],
80+
['ubuntu20.04', ['firefox', 'firefox']],
7381
['mac10.13', ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox']],
7482
['mac10.14', ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox']],
7583
['mac10.15', ['firefox', 'Nightly.app', 'Contents', 'MacOS', 'firefox']],
@@ -80,7 +88,8 @@ export function executablePath(browserPath: string, browser: BrowserDescriptor):
8088

8189
if (browser.name === 'webkit') {
8290
tokens = new Map<BrowserPlatform, string[] | undefined>([
83-
['linux', ['pw_run.sh']],
91+
['ubuntu18.04', ['pw_run.sh']],
92+
['ubuntu20.04', ['pw_run.sh']],
8493
['mac10.13', undefined],
8594
['mac10.14', ['pw_run.sh']],
8695
['mac10.15', ['pw_run.sh']],

src/server/validateDependencies.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ import * as fs from 'fs';
1717
import * as util from 'util';
1818
import * as path from 'path';
1919
import * as os from 'os';
20-
import {spawn} from 'child_process';
21-
import {linuxLddDirectories, BrowserDescriptor} from '../install/browserPaths.js';
20+
import { spawn } from 'child_process';
21+
import { getUbuntuVersion } from '../helper';
22+
import { linuxLddDirectories, BrowserDescriptor } from '../install/browserPaths.js';
2223

2324
const accessAsync = util.promisify(fs.access.bind(fs));
2425
const checkExecutable = (filePath: string) => accessAsync(filePath, fs.constants.X_OK).then(() => true).catch(e => false);
2526
const statAsync = util.promisify(fs.stat.bind(fs));
2627
const readdirAsync = util.promisify(fs.readdir.bind(fs));
27-
const readFileAsync = util.promisify(fs.readFile.bind(fs));
2828

2929
export async function validateDependencies(browserPath: string, browser: BrowserDescriptor) {
3030
// We currently only support Linux.
@@ -122,26 +122,6 @@ function lddAsync(filePath: string): Promise<{stdout: string, stderr: string, co
122122
});
123123
}
124124

125-
async function getUbuntuVersion(): Promise<string> {
126-
const osRelease = await readFileAsync('/etc/os-release', 'utf8').catch(e => '');
127-
if (!osRelease)
128-
return '';
129-
const fields = new Map();
130-
for (const line of osRelease.split('\n')) {
131-
const tokens = line.split('=');
132-
const name = tokens.shift();
133-
let value = tokens.join('=').trim();
134-
if (value.startsWith('"') && value.endsWith('"'))
135-
value = value.substring(1, value.length - 1);
136-
if (!name)
137-
continue;
138-
fields.set(name.toLowerCase(), value);
139-
}
140-
if (!fields.get('name') || fields.get('name').toLowerCase() !== 'ubuntu')
141-
return '';
142-
return fields.get('version_id') || '';
143-
}
144-
145125
// This list is generated with https://gist.github.com/aslushnikov/2766200430228c3700537292fccad064
146126
const LIBRARY_TO_PACKAGE_NAME_UBUNTU_18_04: { [s: string]: string} = {
147127
'libEGL.so.1': 'libegl1',

0 commit comments

Comments
 (0)