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';
var crypto = require('crypto');
var download = require('download');
var fs = require('fs');
var getPackageName = require('./common').getPackageName;
@ -10,28 +11,50 @@ var WebRTCUrl = pkg.config.webrtc.url;
var WebRTCRev = pkg.config.webrtc.revision;
var ChromiumUrl = pkg.config.chromium.url;
function checksum(bytes) {
return crypto
.createHash('md5')
.update(bytes, 'utf8')
.digest('hex')
}
namespace('fetch', function () {
task('precompiled', {async: true}, function () {
var packageName = getPackageName();
var url = pkg.config.url + '/' + pkg.version + '/' + packageName;
task('precompiled', ['check-file'], function () {
});
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);
download(url, '.')
.then(function () {
console.log('Extracting', packageName);
jake.exec('tar xf ' + packageName, function () {
console.log('Deleting', packageName);
fs.unlinkSync(packageName);
console.log('Done');
var task = jake.Task['fetch:extract'];
task.addListener('complete', function () {
complete();
});
task.invoke();
})
.catch(function (err) {
var task = jake.Task['fetch:source'];
console.log('Failed, building libwebrtc from source.');
task.addListener('complete', function () {
console.log('Build done.');
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 () {
console.log('Updating submodules...');
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",
"webrtc": {
"url": "https://chromium.googlesource.com/external/webrtc.git",
"revision": "7502401788fcba5c9f81a9e4701e2f0831e78698"
"revision": "7502401788fcba5c9f81a9e4701e2f0831e78698",
"checksum": "9fc7a9b4c576278a328c276cfb233459"
},
"chromium": {
"url": "https://github.com/aisouard/libwebrtc-chromium-deps.git"