forked from Osndok/ElasticWolf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
s3upload
executable file
·65 lines (56 loc) · 1.88 KB
/
s3upload
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
#!/usr/bin/env node
var s3 = require('aws2js').load('s3');
var fs = require('fs');
var path = require('path');
if (process.argv.length < 4) {
console.log(process.argv[1], "bucketPath file");
process.exit(0);
}
var bucket = process.argv[2].split("/")[0];
var dir = process.argv[2].split("/").slice(1).join("/");
var file = process.argv[3];
s3.setCredentials(process.env.AWS_ACCESS_KEY_ID, process.env.AWS_SECRET_ACCESS_KEY);
s3.setBucket(bucket);
// Update index.html with new version
if (dir == "index.html") {
var index = "";
s3.get(dir, 'stream', function (err, res) {
if (err) {
console.log(err);
return;
}
res.on('data', function(buf) {
index += buf.toString();
});
res.on('end', function() {
// file must contain new version, replace for all platforms
index = index.replace(/ElasticWolf-(osx|win|linux)-[0-9\.]+zip/g, 'ElasticWolf-$1-' + file + '.zip');
index = index.replace(/ElasticWolf-[0-9\.]+xpi/g, 'ElasticWolf-' + file + '.xpi');
index = index.replace(/ElasticWolf version [0-9\.]+/g, 'ElasticWolf version ' + file);
// Upload modified index to back into S3 bucket
s3.putBuffer(dir, new Buffer(index), 'public-read', {'content-type':'text/html'}, function (err, res) {
if (err) console.log(err);
process.exit(0);
});
})
});
} else {
// Upload file into S3 bucket
var type = 'application/zip';
switch (path.extname(file)) {
case '.md5':
type = "text/plain";
break;
case '.xpi':
type = "application/x-xpinstall";
break;
case ".html":
case ".htm":
type = "text/html";
break;
}
s3.putFile(dir, file, 'public-read', {'content-type':type}, function (err, res) {
if (err) console.log(err);
process.exit(0);
});
}