Skip to content

Instantly share code, notes, and snippets.

@shillcock
Created March 10, 2010 19:32
Show Gist options
  • Select an option

  • Save shillcock/328251 to your computer and use it in GitHub Desktop.

Select an option

Save shillcock/328251 to your computer and use it in GitHub Desktop.
var
fs = require('fs'),
sys = require('sys'),
http = require('http'),
client = http.createClient(80, 'build.chromium.org'),
urlPath = '/buildbot/snapshots/chromium-rel-mac/',
filename = 'chrome-mac.zip',
dir = 'chrome-mac',
path = '/tmp/',
ext = '.zip',
hdrs = {'host': 'build.chromium.org'},
download,
unzip,
moving,
cleanup;
latest = function () {
var req = client.request('GET', urlPath + 'LATEST', hdrs);
req.addListener('response', function (res) {
var body = '';
sys.print('version: ');
res.setBodyEncoding('utf8');
res.addListener('data', function (chunk) {
body += chunk;
});
res.addListener('end', function () {
sys.puts(body);
download(body);
});
});
req.close();
};
download = function (version) {
fs.open(path + filename, 'w+', undefined, function (err, fd) {
if (err) throw err;
var req = client.request('GET', urlPath + version + '/' + filename, hdrs);
req.addListener('response', function (res) {
var
size = res.headers['content-length'],
written = 0,
state = 10;
sys.print('download: ');;
res.setBodyEncoding('binary');
res.addListener('data', function (chunk) {
// evil?
written += fs.writeSync(fd, chunk, null, 'binary');
if (~~(size / written) < state) {
sys.print('##');
state = state - 1;
}
});
res.addListener('end', function () {
sys.puts('## | done');
fs.close(fd, function (err) {
if (err) err;
unzip();
});
});
});
req.close();
});
};
unzip = function () {
sys.print('unzip: ');
sys.exec('unzip -q ' + path + filename + ' -d ' + path, function (err, stdout, stderr) {
if (err) throw err;
sys.puts('done');
moving();
});
};
moving = function () {
sys.print('moving: ');
sys.exec('rm -rf /Applications/Chromium.app', function (err) {
if (err) throw err;
fs.rename(path + dir + '/Chromium.app', '/Applications/Chromium.app', function (err) {
if (err) throw err;
sys.puts('done');
cleanup();
});
});
};
cleanup = function () {
sys.print('cleanup: ');
fs.unlink(path + filename, function (err) {
if (err) throw err;
fs.rmdir(path + dir, function (err) {
if (err) throw err;
sys.puts('done');
sys.exec('open /Applications/Chromium.app');
});
});
};
latest();
$ node chromium.js
version: 40876
download: #################### | done
unzip: done
moving: done
cleanup: done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment