forked from open-learning-exchange/BeLL-Apps
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install_windows
142 lines (128 loc) · 4.27 KB
/
install_windows
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#!/usr/bin/env node
/**
* Module dependencies.
*/
var sys = require('sys')
var fs = require('fs')
var exec = require('child_process').exec;
var program = require('commander');
var databases = []
program
.version('0.0.2')
.parse(process.argv);
if (!program.args[0]) return console.log('No CouchDB URL provided. Quiting now.')
var couchUrl = program.args[0]
var nano = require('nano')(couchUrl)
function start() {
getListOfDatabases()
}
function getListOfDatabases() {
fs.readdir('./databases', function doneReadDir(err, files) {
files.forEach(function addFile(element, index, array) {
databases.push(element.substr(0, element.length - 3))
})
installDatabases()
})
}
var a = 0
function installDatabases() {
var database = databases[a]
if (a !== databases.length) {
console.log("creating database " + database)
nano.db.create(database, function(err, body) {
if (err && err.error !== "file_exists") console.log(err)
a++
return installDatabases()
})
} else {
return installDesignDocs()
}
}
var b = 0
function installDesignDocs() {
var database = databases[b]
if (b !== databases.length) {
if (database != "communities" && database != "languages" && database != "configurations") {
console.log("Inserting design docs for the " + database + " database");
var docToPush = 'databases\\' + database + '.js';
var targetDb = couchUrl + '/' + database;
exec('pushDocToDb.bat "' + docToPush + '" "' + targetDb + '"', function(error, stdout, stderr) {
if (error) console.log(error);
if (stderr) console.log(stderr);
console.log(stdout)
b++
installDesignDocs()
})
} else {
b++
installDesignDocs()
}
} else {
createDefaultAdminMember()
}
}
function createDefaultAdminMember() {
nano.db.get('members', function(err, body) {
if (err) console.log(err)
// Cancel if there are already members in the database
if (body.doc_count > 1) return done()
console.log('Creating a default admin member of admin:password')
var members = nano.db.use('members')
var defaultAdminMember = {
"login": "admin",
"kind": "Member",
"roles": ["Manager", "SuperManager"],
"firstName": "Default",
"lastName": "Admin",
"password": "password",
"Gender": "Male",
"status": "active",
"email": "[email protected]",
"visits": 0
}
members.insert(defaultAdminMember, function (err, res) {
if (err)
return console.log(err)
else {
var configurations = nano.db.use('configurations');
var configsDocPath = 'init_docs/ConfigurationsDoc-Nation.txt';
fs.readFile(configsDocPath, function (err, data) {
configurations.insert(data, function (err, res) {
if (err) {
console.log(err);
} else {
console.log("******************Going to insert document into languages database*******************************");
insertLanguageDocs();
}
done()
})
})
}
});
});
}
function insertLanguageDocs() {
var languages = nano.db.use('languages');
fs.readdir('./init_docs/languages', function doneReadDir(err, files) {
files.forEach(function (element) {
var langDocPath = './init_docs/languages/' + element;
console.log("Inserting " + element);
fs.readFile(langDocPath, function (err, data) {
languages.insert(data, function (err, res) {
if (err) {
console.log(err);
} else {
console.log(element + " doc inserted successfully.");
}
});
});
})
});
}
function done() {
console.log('done!')
}
//
// Trigger Start
//
start();