-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinstall.js
60 lines (55 loc) · 1.59 KB
/
install.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
60
var create = require('./db/create');
var helpers = require('./helpers');
const fs = require('fs');
var config = require('./config.json');
// Create a backup of the current database and rename it based on the current datetime
function backupDb(mode='copy') {
// Backup old database
if (fs.existsSync(config.dbpath)) {
if (mode == 'copy') {
fs.copyFile(config.dbpath, `./db/til-${Date.now()}.db`, (err) => {
if (err) {
console.log("Error Found:", err);
}
});
} else if (mode == 'rename') {
fs.renameSync(config.dbpath, `./db/til-${Date.now()}.db`);
}
}
}
// Create a new database
function createDb() {
backupDb('rename');
create.newDb();
}
// Refresh the tags in a database
function refreshTags() {
backupDb('copy');
helpers.refreshTags();
}
// CLI
command = process.argv.slice(2)[0]
if (command == 'createdb') {
createDb();
}
else if (command == 'populatedb') {
create.populateDb();
}
else if (command == 'backupdb') {
backupDb('copy');
}
else if (command == 'adduser') {
helpers.addUser(process.argv.slice(2)[1], process.argv.slice(2)[2])
}
else if (command == 'setuserpassword') {
helpers.changeUserPassword(process.argv.slice(2)[1], process.argv.slice(2)[2])
}
else if (command == 'listusers') {
helpers.listUsers()
}
else if (command == 'refreshtags') {
refreshTags();
}
else {
console.log('install.js createdb|populatedb|backupdb|adduser|listusers|setuserpassword|refreshtags');
}