-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
phnz
committed
Dec 16, 2014
0 parents
commit 292b03f
Showing
6 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
bin/open* |
Empty file.
Empty file.
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
(function() { | ||
var config, configureRequest, loadNpm, npm, request; | ||
|
||
request = require('request'); | ||
|
||
|
||
configureRequest = function(requestOptions, callback) { | ||
requestOptions.headers = {}; | ||
}; | ||
|
||
module.exports = { | ||
get: function(requestOptions, callback) { | ||
return request.get(requestOptions, callback); | ||
}, | ||
createReadStream: function(requestOptions, callback) { | ||
return callback(request.get(requestOptions)); | ||
} | ||
}; | ||
|
||
}).call(this); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"name": "node-builder", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"mv": "^2.0.3", | ||
"request": "^2.51.0", | ||
"runas": "^1.0.1", | ||
"tar": "^1.0.3", | ||
"temp": "^0.8.1" | ||
} | ||
} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#!/usr/bin/env node | ||
|
||
var fs = require('fs'); | ||
var mv = require('mv'); | ||
var zlib = require('zlib'); | ||
var path = require('path'); | ||
|
||
var request = null; | ||
request = require('../lib/request'); | ||
|
||
var tar = require('tar'); | ||
var temp = require('temp'); | ||
|
||
temp.track(); | ||
|
||
// OpenVPN Download Link | ||
var config = { | ||
win: { | ||
x86: '', | ||
x64: '', | ||
} | ||
} | ||
|
||
var downloadFileToLocation = function (url, filename, callback) { | ||
var stream = fs.createWriteStream(filename); | ||
stream.on('end', callback); | ||
stream.on('error', callback); | ||
request.createReadStream({ | ||
url: url | ||
}, function (requestStream) { | ||
requestStream.pipe(stream); | ||
}); | ||
}; | ||
|
||
var downloadTarballAndExtract = function (url, location, callback) { | ||
var tempPath = temp.mkdirSync('vpnht-openvpn-'); | ||
var stream = tar.Extract({ | ||
path: tempPath | ||
}); | ||
stream.on('end', callback.bind(this, tempPath)); | ||
stream.on('error', callback); | ||
request.createReadStream({ | ||
url: url | ||
}, function (requestStream) { | ||
requestStream.pipe(zlib.createGunzip()).pipe(stream); | ||
}); | ||
}; | ||
|
||
var copyToLocation = function (callback, version, targetFilename, fromDirectory) { | ||
var arch = process.arch === 'ia32' ? 'x86' : process.arch; | ||
var subDir = "node-" + version + "-" + process.platform + "-" + arch; | ||
var fromPath = path.join(fromDirectory, subDir, 'bin', 'node'); | ||
return mv(fromPath, targetFilename, function (err) { | ||
if (err) { | ||
callback(err); | ||
return; | ||
} | ||
fs.chmod(targetFilename, "755", callback); | ||
}); | ||
}; | ||
|
||
var downloadOpenVPN = function (version, done) { | ||
var arch, downloadURL, filename; | ||
arch = process.arch === 'ia32' ? 'x86' : process.arch; | ||
|
||
if (process.platform === 'win32') { | ||
downloadURL = "http://nodejs.org/dist/" + version + "/" + arch + "node.exe"; | ||
filename = path.join('bin', "openvpn.exe"); | ||
} else { | ||
downloadURL = "http://nodejs.org/dist/" + version + "/node-" + version + "-" + process.platform + "-" + arch + ".tar.gz"; | ||
filename = path.join('bin', "openvpn"); | ||
} | ||
|
||
var downloadFile = function () { | ||
// it's a EXE | ||
if (process.platform === 'win32') { | ||
downloadFileToLocation(downloadURL, filename, done); | ||
} else if (process.platform === 'linux') { | ||
var next = copyToLocation.bind(this, done, version, filename); | ||
downloadTarballAndExtract(downloadURL, filename, next); | ||
} else { | ||
var next = copyToLocation.bind(this, done, version, filename); | ||
downloadTarballAndExtract(downloadURL, filename, next); | ||
} | ||
}; | ||
|
||
downloadFile(); | ||
}; | ||
|
||
downloadOpenVPN('v0.10.33', function (error) { | ||
if (error != null) { | ||
console.error('Failed to download node', error); | ||
return process.exit(1); | ||
} else { | ||
return process.exit(0); | ||
} | ||
}); |