Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdavies authored and kobelb committed Oct 30, 2018
1 parent 7a8bba6 commit 9c34306
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
20 changes: 9 additions & 11 deletions x-pack/plugins/reporting/server/browsers/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@

import fs from 'fs';
import path from 'path';
import { promisify } from 'bluebird';
import { extract } from './extract';
import { promisify } from 'util';
import { BROWSERS_BY_TYPE } from './browsers';
import { extract } from './extract';
import { md5 } from './download/checksum';

const fsp = {
access: promisify(fs.access, fs),
chmod: promisify(fs.chmod, fs),
};
const chmod = promisify(fs.chmod);

/**
* "install" a browser by type into installs path by extracting the downloaded
Expand All @@ -32,13 +30,13 @@ export async function installBrowser(logger, browserConfig, browserType, install
}

const binaryPath = path.join(installsPath, pkg.binaryRelativePath);
try {
await fsp.access(binaryPath, fs.X_OK);
} catch (accessErr) {
// error here means the binary does not exist, so install it
const rawChecksum = await md5(binaryPath).catch(() => '');

if (rawChecksum !== pkg.rawChecksum) {
logger.debug(`Extracting ${browserType} to ${binaryPath}`);
const archive = path.join(browser.paths.archivesPath, pkg.archiveFilename);
await extract(archive, installsPath);
await fsp.chmod(binaryPath, '755');
await chmod(binaryPath, '755');
}

return browser.createDriverFactory(binaryPath, logger, browserConfig);
Expand Down
3 changes: 3 additions & 0 deletions x-pack/plugins/reporting/server/browsers/phantom/paths.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ export const paths = {
platforms: ['darwin', 'freebsd', 'openbsd'],
archiveFilename: 'phantomjs-2.1.1-macosx.zip',
archiveChecksum: 'b0c038bd139b9ecaad8fd321070c1651',
rawChecksum: 'bbebe2381435309431c9d4e989aefdeb',
binaryRelativePath: 'phantomjs-2.1.1-macosx/bin/phantomjs',
}, {
platforms: ['linux'],
archiveFilename: 'phantomjs-2.1.1-linux-x86_64.tar.bz2',
archiveChecksum: '1c947d57fce2f21ce0b43fe2ed7cd361',
rawChecksum: '3f4bbbe5acd45494d8e52941936235f2',
binaryRelativePath: 'phantomjs-2.1.1-linux-x86_64/bin/phantomjs'
}, {
platforms: ['win32'],
archiveFilename: 'phantomjs-2.1.1-windows.zip',
archiveChecksum: '4104470d43ddf2a195e8869deef0aa69',
rawChecksum: '339f74c735e683502c43512a508e53d6',
binaryRelativePath: 'phantomjs-2.1.1-windows\\bin\\phantomjs.exe'
}]
};

0 comments on commit 9c34306

Please sign in to comment.