forked from rubenv/node-apk-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
47 lines (42 loc) · 1.33 KB
/
Copy pathinstall.js
File metadata and controls
47 lines (42 loc) · 1.33 KB
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
var http = require('http');
var fs = require('fs');
var os = require('os');
var exec = require('child_process').exec;
var targetDir = __dirname + '/tools/';
try {
fs.statSync(targetDir);
} catch (e) {
fs.mkdirSync(targetDir);
}
var platform = null;
if (os.type() == 'Darwin') {
platform = 'macosx';
} else if (os.type() == 'Linux') {
platform = 'linux';
} else {
throw new Error('Unknown OS!');
}
function attemptDownload(attemptsLeft) {
var url = "http://dl-ssl.google.com/android/repository/platform-tools_r16-" + platform + ".zip";
var tempFile = "/tmp/platform-tools-" + (new Date().getTime()) + ".zip";
var file = fs.createWriteStream(tempFile);
var request = http.get(url, function(response) {
response.pipe(file);
response.on('end', function () {
exec("unzip -j -o " + tempFile + " platform-tools/aapt -d tools/", function (err) {
if (err) {
if (attemptsLeft === 0) {
throw err;
} else {
attemptDownload(attemptsLeft - 1);
return;
}
}
fs.chmodSync('tools/aapt', '755');
fs.unlinkSync(tempFile);
process.exit();
});
});
});
}
attemptDownload(3);