This repository was archived by the owner on Mar 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupdateChromium.js
More file actions
75 lines (59 loc) · 2.3 KB
/
updateChromium.js
File metadata and controls
75 lines (59 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var request = require('request');
var fs = require('fs');
var child_process = require('child_process');
var windowsVersion = "Win"; // Win_x64 for 64 bit
var getLatestRevision = function(callback){
request('http://chromium.woolyss.com/download/', function(err, res, body) {
if(err) throw err;
var findLatestRevisionRegEx = new RegExp('chromium-browser-continuous/'+windowsVersion+'/([a-z0-9]{1,})');
var match = body.match(findLatestRevisionRegEx);
if(match){
var revision = match[1];
callback(revision);
}
});
};
var installCheckRevision = function(revision, callback){
var installed = __dirname + '/INSTALLED'
if(fs.exists(installed, function(exists){
var saveCurrentRev = function(cb) {
fs.writeFile(installed, revision, cb);
};
if(!exists){
saveCurrentRev(function(){
callback(true);
});
} else {
fs.readFile(installed, function(err, data){
if(err) throw err;
var needsUpdate = data < revision;
if(needsUpdate) {
saveCurrentRev(function(){
callback(true);
})
} else {
callback(false);
}
});
}
}));
};
getLatestRevision(function(revision){
var installerUrl = 'https://commondatastorage.googleapis.com/chromium-browser-continuous/'+windowsVersion+'/'+revision+'/mini_installer.exe';
var filename = __dirname + '/' + revision + '_installer.exe';
installCheckRevision(revision, function(needsUpdate){
if(!needsUpdate){
console.log("Chromium is already up-to-date :)");
return;
}
console.log('Downloading installer ...');
request(installerUrl).pipe(fs.createWriteStream(filename)).on('finish', function() {
console.log('Installer saved!');
console.log("Updating to latest version ...");
var installProcess = child_process.spawn(filename);
installProcess.on('close', function(){
console.log('Chromium ist now up-to-date!');
});
});
})
});