forked from TID-Lab/aggie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.js
55 lines (50 loc) · 1.63 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
// Performs some basic setup tasks. Should be run as part of deploy process.
var database = require('./lib/database');
var Report = require('./models/report');
var User = require('./models/user');
var config = require('./config/secrets').get();
var tasks = [];
// Enable full-text indexing for Reports
function enableIndexing(callback) {
// Wait for database connection
setTimeout(function() {
// Enable database-level text search
database.mongoose.connections[0].db.admin().command({setParameter: 1, textSearchEnabled: true}, function(err, res) {
if (err) console.error(err);
else console.log('Text search has been enabled for MongoDB.');
Report.ensureIndexes(function(err) {
if (err) console.error(err);
else console.log('Full-text indexing is enabled for Reports.')
callback();
});
});
}, 1000);
};
tasks.push(enableIndexing);
// Verify that an admin user exists
function createAdminUser(callback) {
User.findOne({role: 'admin'}, function(err, user) {
if (!user) {
var userData = {
provider: 'aggie',
email: config.fromEmail,
username: 'admin',
password: config.adminPassword,
role: 'admin'
};
// Create new admin user
User.create(userData, function(err, user) {
if (err) console.error(err);
else console.log('"admin" user created with password "' + config.adminPassword + '"');
callback();
});
} else callback();
});
};
tasks.push(createAdminUser);
var remaining = tasks.length;
tasks.forEach(function(task) {
task(function() {
if (--remaining === 0) process.exit();
});
});