UNPKG

2.22 kBJavaScriptView Raw
1/*
2 Take input on the command-line a single parameter: Windows or Unix path, and convert into a linux path.
3 Then write that path to ../config.json under backupTo: as an entry in the array.
4
5
6*/
7
8var multiparty = require('multiparty');
9var http = require('http');
10var util = require('util');
11var path = require("path");
12var upath = require("upath");
13require("date-format-lite");
14var mv = require('mv');
15var fs = require('fs');
16var exec = require('child_process').exec;
17var drivelist = require('drivelist');
18var uuid = require('node-uuid');
19var fsExtra = require('fs-extra');
20var request = require("request");
21var needle = require('needle');
22
23
24
25var currentDisks = [];
26var configFile = '/../config.json';
27
28
29function updateConfig(newdir, cb) {
30 //Reads and updates config with a newdir in the output photos - this will overwrite all other entries there
31 //Returns cb(err) where err = null, or a string with the error
32
33
34 //Write to a json file with the current drive. This can be removed later manually by user, or added to
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 //Write the file nicely formatted again
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
67if(process.argv[2]) {
68
69 //Potentially there can be spaces in this path, which would be input as a different argument.
70 //Append them all into one single directory variable.
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 //path.posix.normalize(p)
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