Last active
August 29, 2015 14:17
-
-
Save jonstorer/f46101469875e0583619 to your computer and use it in GitHub Desktop.
Update Firefox on Codeship
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env node | |
var locate = require('mozilla-get-url') | |
, child_process = require('child_process') | |
, ProgressBar = require('progress') | |
, async = require('async') | |
, chalk = require('chalk') | |
, request = require('request') | |
, fs = require('fs-extra') | |
, path = require('path'); | |
var fetchFirefoxUrl = function(done){ | |
var options = { os: 'linux-x86_64' }; | |
locate(options, function(err, url){ | |
done(err, { url: url }); | |
}); | |
}; | |
var tmpStorage = function(params, done){ | |
params.path = path.join(process.env.HOME, path.basename(params.url)); | |
done(null, params); | |
}; | |
var downloadFirefox = function(params, done){ | |
var bar; | |
request.get(params.url) | |
.on('data', function(data){ bar.tick(data.length); }) | |
.on('response', function(response){ | |
bar = new ProgressBar("downloading / :percent / :eta / [:bar] ", { total: +response.headers['content-length'] }) | |
response.on('end', function(err){ | |
done(err, params); | |
}); | |
}) | |
.pipe(fs.createWriteStream(params.path)); | |
}; | |
var unTarFirefox = function(params, done){ | |
var bar, task | |
, dataHandler = function(){ bar.tick(); } | |
, errorHandler = function(err){ done(new Error('eek ' + err)); } | |
, exitHandler = function(){ process.stdout.write("\n"); done(null, params); }; | |
bar = new ProgressBar("installing / :percent / :eta / [:bar] ", { total: 83 }) | |
task = child_process.spawn('tar', ['-xvf', params.path ], { cwd: process.env.HOME }); | |
task.stdout.on('data', dataHandler); | |
task.stderr.on('data', dataHandler); | |
task.on('error', errorHandler); | |
task.on('exit', exitHandler); | |
}; | |
var waterfall = [ fetchFirefoxUrl , tmpStorage , downloadFirefox , unTarFirefox ]; | |
async.waterfall(waterfall, function(err, params){ | |
process.exit(0); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment