Repository navigation
Expand file tree
/
Copy pathinstall.js
More file actions
91 lines (84 loc) · 2.48 KB
/
Copy pathinstall.js
File metadata and controls
91 lines (84 loc) · 2.48 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const fs = require('fs');
const config = require('./config');
function getCreate() {
return require('./db/create');
}
function getHelpers() {
return require('./helpers');
}
// 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)) {
const backupPath = `./db/til-${Date.now()}.db`;
if (mode === 'copy') {
fs.copyFile(config.dbpath, backupPath, (err) => {
if (err) {
console.log("Error Found:", err);
} else {
console.log(`Database backed up to ${backupPath}`);
}
});
} else if (mode === 'rename') {
fs.renameSync(config.dbpath, backupPath);
console.log(`Database renamed to ${backupPath}`);
}
} else {
console.log('No database found to back up.');
}
}
// Create a new database
function createDb() {
backupDb('rename');
getCreate().newDb();
}
// Refresh the tags in a database
function refreshTags() {
backupDb('copy');
getHelpers().refreshTags();
}
// CLI
const command = process.argv.slice(2)[0];
if (command === 'createdb') {
createDb();
}
else if (command === 'populatedb') {
getCreate().populateDb();
}
else if (command === 'backupdb') {
backupDb('copy');
}
else if (command === 'adduser') {
getHelpers().addUser(process.argv.slice(2)[1], process.argv.slice(2)[2]);
}
else if (command === 'setuserpassword') {
getHelpers().changeUserPassword(process.argv.slice(2)[1], process.argv.slice(2)[2]);
}
else if (command === 'listusers') {
getHelpers().listUsers();
}
else if (command === 'refreshtags') {
refreshTags();
}
else if (command === 'showtil') {
getHelpers().showTil(process.argv.slice(2)[1] || 1);
}
else if (command === 'generatetils') {
const count = parseInt(process.argv.slice(2)[1]) || 10;
getHelpers().generateRandomTils(count);
}
else if (command === 'fixnulldates') {
getHelpers().fixNullDates();
}
else if (command === 'setadmin') {
getHelpers().setAdmin(process.argv.slice(2)[1], true);
}
else if (command === 'removeadmin') {
getHelpers().setAdmin(process.argv.slice(2)[1], false);
}
else if (command === 'rebuildfts') {
getHelpers().rebuildFts();
}
else {
console.log('install.js createdb|populatedb|backupdb|adduser|listusers|setuserpassword|refreshtags|rebuildfts|showtil|generatetils|fixnulldates|setadmin|removeadmin');
}