-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoccupy-install-node.js
84 lines (78 loc) · 2.28 KB
/
occupy-install-node.js
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
76
77
78
79
80
81
82
83
84
var request = require('request')
, once = require('once')
, uname = require('./occupy-uname')
;
function buildtools (seq, cb) {
var aptDeps = ['build-essential', 'openssl', 'libssl-dev', 'pkg-config', 'curl']
, aptCmd = 'apt-get -y --fix-missing install ' + aptDeps.join(' ')
, yumDeps = ['gcc-c++', 'make', 'openssl-devel', 'curl']
, yumCmd = cmd = 'yum -y install ' + yumDeps.join(' ')
;
uname(seq, function (e, _uname) {
if (_uname.indexOf('Linux') !== -1) {
seq('apt-get --help', function (e) {
if (!e) return seq(aptCmd, cb)
seq('yum --help', function (e) {
if (e) return cb(new Error('This Linux does not have apt or yum!'))
return seq(yumCmd, cb)
})
})
} else {
console.error('Do not know how to install on this operating system.')
return cb(e)
}
})
}
function nodeInstallSteps (version) {
var url = "http://nodejs.org/dist/" + version + "/node-" + version + ".tar.gz"
, cd = 'cd node-' + version + ' && '
, steps =
[ 'curl '+url+' | tar -zxf -'
, cd + './configure'
, cd + 'make'
, cd + 'make install'
, 'rm -rf node-'+version
, 'node --version'
]
;
return steps
}
function downloadAndCompile (seq, cb) {
request('http://nodejs.org/dist/latest/SHASUMS.txt', function (e, resp, txt) {
if (e) return cb(e)
if (resp.statusCode !== 200) return cb(new Error('Could not get SHASUMS.'))
var line = txt.split('\n')[0]
, i = line.indexOf('node-v') + 'node-'.length
, version = line.slice(i, line.indexOf('-', i+5))
, steps = nodeInstallSteps(version)
;
console.log('Stable release of node is '+version)
var s = seq()
s.on('error', cb)
s.on('end', function () {
console.log('Installed node', version)
cb()
})
steps.forEach(function (step) {
s.write(step)
})
s.on('cmd', console.log)
s.end()
})
}
function install (seq, cb) {
cb = once(cb)
buildtools(seq, function (e) {
if (e) return cb(e)
downloadAndCompile(seq, cb)
})
}
function installnode (seq, cb) {
seq('node --version', function (e, stdout) {
if (e) return install(seq, cb)
console.log('Has node '+stdout)
cb(null)
})
}
module.exports = installnode
module.exports.force = install