This repository has been archived by the owner on May 26, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
update-self.js
59 lines (47 loc) · 1.7 KB
/
update-self.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
var request = require("request"),
logger = require(__dirname+'/logger.js'),
fs = require("fs"),
AdmZip = require("adm-zip"),
ncp = require('ncp').ncp;
ncp.limit = 16;
logger.info("update-ccu.io started");
var url = "https://github.com/hobbyquaker/ccu.io/archive/master.zip",
tmpDir = "ccu.io-master",
tmpFile = __dirname+"/tmp/master.zip";
logger.info("update-ccu.io download and unzip "+url);
// Download and Unzip
// reading archives
request(url).pipe(fs.createWriteStream(tmpFile)).on("close", function () {
var zip = new AdmZip(tmpFile);
zip.extractAllTo(__dirname+"/tmp", true);
logger.info("update-ccu.io unzip done");
var source = __dirname+"/tmp/"+tmpDir,
destination = __dirname;
logger.info("update-ccu.io copying "+source+" to "+destination);
ncp(source, destination, function (err) {
if (err) {
logger.error(err);
return
}
setTimeout(function () {
// Ordner im tmp Verzeichnis löschen
logger.info('update-ccu.io delete tmp folder '+__dirname+"/tmp/"+tmpDir);
deleteFolderRecursive(__dirname+"/tmp/"+tmpDir);
logger.info('update-ccu.io done');
process.exit(0);
}, 2000);
});
});
var deleteFolderRecursive = function(path) {
if( fs.existsSync(path) ) {
fs.readdirSync(path).forEach(function(file,index){
var curPath = path + "/" + file;
if(fs.statSync(curPath).isDirectory()) { // recurse
deleteFolderRecursive(curPath);
} else { // delete file
fs.unlinkSync(curPath);
}
});
fs.rmdirSync(path);
}
};