Skip to content

Commit dfed983

Browse files
committed
Updated behavior of the install system.
1 parent 9e3a805 commit dfed983

File tree

5 files changed

+35
-26
lines changed

5 files changed

+35
-26
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ node_js:
88
- "5"
99
- "4"
1010
install:
11-
- ./runMeFirst.bash
11+
- npm install
1212
script:
1313
- npm test

DontRunMe.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
'use strict';
22

3-
let crypto = require('crypto');
3+
let crypto = require('crypto'); // define crypto
4+
let fs = require('fs'); // define filesys
45

56
function randomValueHex (len) {
67
return crypto.randomBytes(Math.ceil(len/2))
78
.toString('hex') // convert to hexadecimal format
89
.slice(0,len); // return required number of characters
910
};
1011

11-
let a = randomValueHex(32);
12-
let b = randomValueHex(32);
13-
console.log("{\n \"key\": \"" + a + "\",\n \"hmac_key\": \"" + b + "\"\n}");
14-
setTimeout(function(){process.exit(0);}, 833);
12+
if (fs.existsSync("./config.js")) {
13+
return setTimeout(function(){
14+
process.exit(0); // exit script if config already exists
15+
}, 833);
16+
}
17+
18+
let key = randomValueHex(32); // create random hex val for enc key
19+
let hmac = randomValueHex(32); // create random hex val for hmac key
20+
let randFold = "./" + randomValueHex(32) + "/"; // create random hex val with filesys encoding for folder
21+
let randFile = randomValueHex(32) + ".json"; // create random hex val with .json ending for file
22+
let resSysop = randFold + randFile; // merge foldername and filename
23+
24+
fs.mkdirSync(randFold); // create folder
25+
fs.appendFileSync(resSysop, "{\n \"key\": \"" + key + "\",\n \"hmac_key\": \"" + hmac + "\"\n}\n"); // create file with keys necessary
26+
fs.appendFileSync("./config.js", "\'use strict\';\n\nvar k = require(\"" + resSysop + "\");\n\nmodule.exports = {\n k\n};\n\n"); // generate config file with necessary info
27+
28+
setTimeout(function(){process.exit(0);}, 2000); // exit script

basic256.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
'use strict';
2-
/* 5th line is reserved for the automated script to attach the keys necessary. */
2+
33
let crypto = require('crypto');
44

5+
function UserException(message) {
6+
this.message = message;
7+
this.name = 'UserException';
8+
}
9+
10+
11+
try {
12+
var savedKeys = require("./config.js").k;
13+
} catch (e) {
14+
throw new UserException('No Configuration Exists');
15+
}
516

617
var ALGORITHM, KEY, HMAC_ALGORITHM, HMAC_KEY;
718

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
"type": "git",
1212
"url": "git+https://github.com/linuxgemini/basic256.js.git"
1313
},
14-
"license": "Apache-2",
14+
"license": "Apache-2.0",
1515
"scripts": {
16-
"test": "node test.js"
16+
"install": "node ./DontRunMe.js; rm -rf ./node_modules/",
17+
"test": "node ./test.js"
1718
}
1819
}

runMeFirst.bash

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)