From ed34456717aa8cc2cca325d480c4f315adcdf2df Mon Sep 17 00:00:00 2001 From: pr0chin Date: Fri, 27 Oct 2017 10:37:02 +0545 Subject: [PATCH] [#1022] Added install_windows --- install_windows | 145 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 install_windows diff --git a/install_windows b/install_windows new file mode 100644 index 000000000..f61bc331b --- /dev/null +++ b/install_windows @@ -0,0 +1,145 @@ +#!/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": "admin.somalia@olebell.org", + "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 langList = ['Arabic.txt', 'English.txt', 'Nepali.txt', 'Spanish.txt', 'Urdu (Pakistan).txt']; + if (langList.indexOf(element) > -1) { + 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();