Skip to content

Commit faabdbd

Browse files
authored
Merge pull request #303 from sjanuary/add_extract_binaries
Add extract_all_binaries.js
2 parents 042c166 + 6c556aa commit faabdbd

File tree

1 file changed

+181
-0
lines changed

1 file changed

+181
-0
lines changed

extract_all_binaries.js

Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*******************************************************************************
2+
* Copyright 2015 IBM Corp.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*******************************************************************************/
16+
17+
var fs = require('fs');
18+
var util = require('util');
19+
var url = require('url');
20+
var path = require('path');
21+
var zlib = require('zlib');
22+
var tar = require('tar');
23+
24+
var OS = process.platform; // e.g. linux
25+
var ARCH = process.arch; // e.g. ia32
26+
var ENDIANNESS = process.config.variables.node_byteorder; // e.g. 'little'
27+
var INSTALL_DIR = process.cwd();
28+
var AGENTCORE_PLATFORMS = ['aix-ppc',
29+
'aix-ppc64',
30+
'darwin-ia32',
31+
'darwin-x64',
32+
'linux-ia32',
33+
'linux-ppc',
34+
'linux-ppc64',
35+
'linux-ppc64le',
36+
'linux-s390',
37+
'linux-s390x',
38+
'linux-x64',
39+
'win32-ia32',
40+
'win32-x64'];
41+
var AGENTCORE_VERSION = "3.0.9";
42+
var APPMETRICS_VERSION = "1.1.1";
43+
44+
var LOG_FILE = path.join(INSTALL_DIR, 'install.log');
45+
var logFileStream = fs.createWriteStream(LOG_FILE, {flags : 'a'});
46+
47+
console.log = function(info) { //
48+
logFileStream.write(util.format(info) + '\n');
49+
process.stdout.write(util.format(info) + '\n');
50+
};
51+
52+
var showLegalWarning = function() {
53+
/* Legal warning */
54+
console.log(new Date().toUTCString());
55+
console.log('********************************************************************************');
56+
console.log('You are installing the Node Application Metrics monitoring and profiling module.');
57+
console.log('Licensed under the Apache License, Version 2.0 (the "License")');
58+
console.log('you may not use this file except in compliance with the License.');
59+
console.log('You may obtain a copy of the License at');
60+
console.log('');
61+
console.log('http://www.apache.org/licenses/LICENSE-2.0');
62+
console.log('');
63+
console.log('Unless required by applicable law or agreed to in writing, software');
64+
console.log('distributed under the License is distributed on an "AS IS" BASIS,');
65+
console.log('WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.');
66+
console.log('See the License for the specific language governing permissions and');
67+
console.log('limitations under the License.');
68+
console.log('********************************************************************************');
69+
};
70+
71+
var getPlatform = function() {
72+
var platform;
73+
if (ARCH === 'ppc64' && ENDIANNESS === 'little') {
74+
platform = 'linux-ppc64le';
75+
} else {
76+
platform = OS + '-' + ARCH;
77+
}
78+
return platform;
79+
};
80+
81+
var ensureSupportedPlatformOrExit = function() {
82+
/*
83+
* Check up front for the platform-architectures for which there are
84+
* available Health Center core agent downloads.
85+
*/
86+
var platform = getPlatform();
87+
if (AGENTCORE_PLATFORMS.indexOf(platform) === -1) {
88+
console.log(platform + ' is not a currently supported platform. Exiting');
89+
process.exit(1);
90+
}
91+
};
92+
93+
var getSupportedNodeVersionOrExit = function() {
94+
if (process.version.indexOf('v0.10') === 0) {
95+
return '0.10';
96+
}
97+
if (process.version.indexOf('v0.12') === 0) {
98+
return '0.12';
99+
}
100+
if (process.version.indexOf('v2') === 0) {
101+
return '2';
102+
}
103+
if (process.version.indexOf('v4') === 0) {
104+
return '4';
105+
}
106+
if (process.version.indexOf('v5') === 0) {
107+
return '5';
108+
}
109+
if (process.version.indexOf('v6') === 0) {
110+
return '6';
111+
}
112+
console.log('Unsupported version ' + process.version + '. Exiting.');
113+
process.exit(1);
114+
};
115+
116+
var getAgentCorePlatformVersionDownloadURL = function() {
117+
return ['agentcore', AGENTCORE_VERSION, getPlatform()].join('-') + '.tgz';
118+
};
119+
120+
var getAppMetricsPlatformVersionDownloadURL = function() {
121+
return [getSupportedNodeVersionOrExit()+'/appmetrics', APPMETRICS_VERSION, getPlatform()].join('-') + '.tgz';
122+
};
123+
124+
var getWindowsRedisFiles = function() {
125+
return [getPlatform()].join('-') + '.tgz';
126+
};
127+
128+
var downloadAndExtractTGZ = function(filepath, destDir, agentCoreFlag) {
129+
if (agentCoreFlag) {
130+
fs.createReadStream('binaries/agentcore/tgz/'+filepath).pipe(zlib.createGunzip()).on('error', function(err) {
131+
console.log('ERROR: Failed to gunzip ' + filepath + ': ' + err.message);
132+
process.exit(1);
133+
})
134+
.pipe(tar.Extract({path: destDir})).on('error', function(err) {
135+
console.log('ERROR: Failed to untar ' + filepath + ': ' + err.message);
136+
process.exit(1);
137+
})
138+
.on('close', function() {
139+
console.log('Download and extract of ' + filepath + ' finished.');
140+
});
141+
} else {
142+
fs.createReadStream('binaries/appmetrics/tgz/'+filepath).pipe(zlib.createGunzip()).on('error', function(err) {
143+
console.log('ERROR: Failed to gunzip ' + filepath + ': ' + err.message);
144+
process.exit(1);
145+
})
146+
.pipe(tar.Extract({path: destDir})).on('error', function(err) {
147+
console.log('ERROR: Failed to untar ' + filepath + ': ' + err.message);
148+
process.exit(1);
149+
})
150+
.on('close', function() {
151+
console.log('Download and extract of ' + filepath + ' finished.');
152+
});
153+
}
154+
155+
};
156+
157+
var installWinRedis = function(filepath, destDir) {
158+
fs.createReadStream('binaries/winredis/'+filepath).pipe(zlib.createGunzip()).on('error', function(err) {
159+
console.log('ERROR: Failed to gunzip ' + filepath + ': ' + err.message);
160+
process.exit(1);
161+
})
162+
.pipe(tar.Extract({path: destDir})).on('error', function(err) {
163+
console.log('ERROR: Failed to untar ' + filepath + ': ' + err.message);
164+
process.exit(1);
165+
})
166+
.on('close', function() {
167+
console.log('Download and extract of ' + filepath + ' finished.');
168+
});
169+
};
170+
171+
/*
172+
* Start the download
173+
*/
174+
showLegalWarning();
175+
ensureSupportedPlatformOrExit();
176+
downloadAndExtractTGZ(getAgentCorePlatformVersionDownloadURL(), '.', true);
177+
downloadAndExtractTGZ(getAppMetricsPlatformVersionDownloadURL(), '.', false);
178+
if(OS === 'win32') {
179+
installWinRedis(getWindowsRedisFiles(), '.');
180+
}
181+

0 commit comments

Comments
 (0)