Jake: check the package's integrity with MD5

This commit is contained in:
Axel Isouard 2016-10-08 13:40:45 +02:00
parent aaa4bbc155
commit 063c82aab5
2 changed files with 45 additions and 10 deletions

View file

@ -1,5 +1,6 @@
'use strict'; 'use strict';
var crypto = require('crypto');
var download = require('download'); var download = require('download');
var fs = require('fs'); var fs = require('fs');
var getPackageName = require('./common').getPackageName; var getPackageName = require('./common').getPackageName;
@ -10,28 +11,50 @@ var WebRTCUrl = pkg.config.webrtc.url;
var WebRTCRev = pkg.config.webrtc.revision; var WebRTCRev = pkg.config.webrtc.revision;
var ChromiumUrl = pkg.config.chromium.url; var ChromiumUrl = pkg.config.chromium.url;
function checksum(bytes) {
return crypto
.createHash('md5')
.update(bytes, 'utf8')
.digest('hex')
}
namespace('fetch', function () { namespace('fetch', function () {
task('precompiled', {async: true}, function () { task('precompiled', ['check-file'], function () {
var packageName = getPackageName(); });
var url = pkg.config.url + '/' + pkg.version + '/' + packageName;
task('check-file', function () {
try {
var data = fs.readFileSync(getPackageName());
if (checksum(data) !== pkg.config.webrtc.checksum) {
throw new Error('Invalid checksum');
}
jake.Task['fetch:extract'].invoke();
} catch (e) {
jake.Task['fetch:download'].invoke();
}
});
task('download', {async: true}, function () {
var url = pkg.config.url + '/' + pkg.version + '/' + getPackageName();
console.log('Downloading', url); console.log('Downloading', url);
download(url, '.') download(url, '.')
.then(function () { .then(function () {
console.log('Extracting', packageName); var task = jake.Task['fetch:extract'];
jake.exec('tar xf ' + packageName, function () {
console.log('Deleting', packageName); task.addListener('complete', function () {
fs.unlinkSync(packageName);
console.log('Done');
complete(); complete();
}); });
task.invoke();
}) })
.catch(function (err) { .catch(function (err) {
var task = jake.Task['fetch:source']; var task = jake.Task['fetch:source'];
console.log('Failed, building libwebrtc from source.'); console.log('Failed, building libwebrtc from source.');
task.addListener('complete', function () { task.addListener('complete', function () {
console.log('Build done.');
complete(); complete();
}); });
@ -39,6 +62,17 @@ namespace('fetch', function () {
}); });
}); });
task('extract', {async: true}, function () {
var packageName = getPackageName();
console.log('Extracting', packageName);
jake.exec('tar xf ' + packageName, function () {
console.log('Deleting', packageName);
fs.unlinkSync(packageName);
complete();
});
});
task('gclient', {async: true}, function () { task('gclient', {async: true}, function () {
console.log('Updating submodules...'); console.log('Updating submodules...');
jake.exec(['git submodule init', 'git submodule update'], {printStdout: true}, function () { jake.exec(['git submodule init', 'git submodule update'], {printStdout: true}, function () {

View file

@ -8,7 +8,8 @@
"url": "https://github.com/aisouard/libwebrtc/releases/download", "url": "https://github.com/aisouard/libwebrtc/releases/download",
"webrtc": { "webrtc": {
"url": "https://chromium.googlesource.com/external/webrtc.git", "url": "https://chromium.googlesource.com/external/webrtc.git",
"revision": "7502401788fcba5c9f81a9e4701e2f0831e78698" "revision": "7502401788fcba5c9f81a9e4701e2f0831e78698",
"checksum": "9fc7a9b4c576278a328c276cfb233459"
}, },
"chromium": { "chromium": {
"url": "https://github.com/aisouard/libwebrtc-chromium-deps.git" "url": "https://github.com/aisouard/libwebrtc-chromium-deps.git"