1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 | var multiparty = require('multiparty');
|
9 | var http = require('http');
|
10 | var util = require('util');
|
11 | var path = require("path");
|
12 | var upath = require("upath");
|
13 | require("date-format-lite");
|
14 | var mv = require('mv');
|
15 | var fs = require('fs');
|
16 | var exec = require('child_process').exec;
|
17 | var drivelist = require('drivelist');
|
18 | var uuid = require('node-uuid');
|
19 | var fsExtra = require('fs-extra');
|
20 | var request = require("request");
|
21 | var needle = require('needle');
|
22 |
|
23 |
|
24 |
|
25 | var currentDisks = [];
|
26 | var configFile = '/../config.json';
|
27 |
|
28 |
|
29 | function updateConfig(newdir, cb) {
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 | fs.readFile(__dirname + configFile, function read(err, data) {
|
36 | if (err) {
|
37 | cb("Sorry, cannot read config file! " + err);
|
38 | } else {
|
39 | var content = JSON.parse(data);
|
40 |
|
41 | content.backupTo = [ newdir ];
|
42 |
|
43 |
|
44 | fs.writeFile(__dirname + configFile, JSON.stringify(content, null, 6), function(err) {
|
45 | if(err) {
|
46 | cb(err);
|
47 | }
|
48 |
|
49 |
|
50 |
|
51 | console.log("The config file was saved!");
|
52 |
|
53 |
|
54 | cb(null);
|
55 | });
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | };
|
61 | });
|
62 |
|
63 | }
|
64 |
|
65 |
|
66 |
|
67 | if(process.argv[2]) {
|
68 |
|
69 |
|
70 |
|
71 | var fullDir = process.argv[2];
|
72 | for(var argc = 3; argc < process.argv.length; argc++) {
|
73 | if(process.argv[argc]) {
|
74 | fullDir += " " + process.argv[argc];
|
75 | }
|
76 | }
|
77 |
|
78 | var photoDir = upath.normalize(fullDir);
|
79 |
|
80 | updateConfig(photoDir, function(err) {
|
81 | if(err) {
|
82 | console.log("Error:" + err);
|
83 | process.exit(1);
|
84 |
|
85 | } else {
|
86 | console.log("Set successfully.");
|
87 | process.exit(0);
|
88 | }
|
89 |
|
90 | })
|
91 |
|
92 | } else {
|
93 | console.log("Usage: node install.js imagedir");
|
94 |
|
95 | }
|
96 |
|
97 |
|