Skip to content

Node.js based forum software built for the modern web

updated install

Baris Soner Usaklib215dbde1953
diff --git a/src/database/redis.js b/src/database/redis.js
index 6ce97d83cb..cfb34dad10 100644
--- a/src/database/redis.js
+++ b/src/database/redis.js
@@ -163,7 +163,7 @@
}
module.setObjectField = function(key, field, value, callback) {
- redisClient.hset(key, field, value, callback)
+ redisClient.hset(key, field, value, callback);
}
module.getObject = function(key, callback) {
diff --git a/src/install.js b/src/install.js
index ee1d3f08a7..22d00cfdd3 100644
--- a/src/install.js
+++ b/src/install.js
@@ -19,8 +19,8 @@ var async = require('async'),
name: 'port',
description: 'Port number of your NodeBB',
'default': nconf.get('port') || 4567,
- pattern: /[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]/,
- message: 'Please enter a value betweeen 1 and 65535'
+ pattern: /[0-9]{1,4}|[1-5][0-9]{4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-5]/,
+ message: 'Please enter a value betweeen 1 and 65535'
}, {
name: 'use_port',
description: 'Use a port number to access NodeBB?',
@@ -32,6 +32,15 @@ var async = require('async'),
description: 'Please enter a NodeBB secret',
'default': nconf.get('secret') || utils.generateUUID()
}, {
+ name: 'bind_address',
+ description: 'IP or Hostname to bind to',
+ 'default': nconf.get('bind_address') || '0.0.0.0'
+ }, {
+ name: 'database',
+ description: 'Which database to use',
+ 'default': nconf.get('database') || 'redis'
+ }],
+ redisQuestions : [{
name: 'redis:host',
description: 'Host IP or address of your Redis instance',
'default': nconf.get('redis:host') || '127.0.0.1'
@@ -46,11 +55,24 @@ var async = require('async'),
name: "redis:database",
description: "Which database to use (0..n)",
'default': nconf.get('redis:database') || 0
+ }],
+ mongoQuestions : [{
+ name: 'mongo:host',
+ description: 'Host IP or address of your MongoDB instance',
+ 'default': nconf.get('mongo:host') || '127.0.0.1'
}, {
- name: 'bind_address',
- description: 'IP or Hostname to bind to',
- 'default': nconf.get('bind_address') || '0.0.0.0'
+ name: 'mongo:port',
+ description: 'Host port of your MongoDB instance',
+ 'default': nconf.get('mongo:port') || 27017
+ }, {
+ name: 'mongo:password',
+ description: 'Password of your MongoDB database'
+ }, {
+ name: "mongo:database",
+ description: "Which database to use (0..n)",
+ 'default': nconf.get('mongo:database') || 0
}],
+
setup: function (callback) {
async.series([
function(next) {
@@ -74,7 +96,9 @@ var async = require('async'),
if (!setupVal['admin:email']) winston.error(' admin:email');
process.exit();
}
- } else next();
+ } else {
+ next();
+ }
},
function (next) {
var success = function(err, config) {
@@ -82,36 +106,54 @@ var async = require('async'),
return next(new Error('aborted'));
}
- // Translate redis properties into redis object
- config.redis = {
- host: config['redis:host'],
- port: config['redis:port'],
- password: config['redis:password'],
- database: config['redis:database']
- };
- delete config['redis:host'];
- delete config['redis:port'];
- delete config['redis:password'];
- delete config['redis:database'];
-
- // Add hardcoded values
- config.bcrypt_rounds = 12;
- config.upload_path = '/public/uploads';
- config.use_port = (config.use_port.slice(0, 1) === 'y') ? true : false;
-
- var urlObject = url.parse(config.base_url),
- relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '',
- host = urlObject.host,
- protocol = urlObject.protocol,
- server_conf = config,
- client_conf = {
- relative_path: relative_path
- };
-
- server_conf.base_url = protocol + '//' + host;
- server_conf.relative_path = relative_path;
-
- install.save(server_conf, client_conf, next);
+ function dbQuestionsSuccess(err, databaseConfig) {
+ if (!config) {
+ return next(new Error('aborted'));
+ }
+
+ // Translate redis properties into redis object
+ if(config.database === 'redis') {
+ config.redis = {
+ host: databaseConfig['redis:host'],
+ port: databaseConfig['redis:port'],
+ password: databaseConfig['redis:password'],
+ database: databaseConfig['redis:database']
+ };
+ } else if (config.database === 'mongo') {
+ config.mongo = {
+ host: databaseConfig['mongo:host'],
+ port: databaseConfig['mongo:port'],
+ password: databaseConfig['mongo:password'],
+ database: databaseConfig['mongo:database']
+ };
+ }
+
+ // Add hardcoded values
+ config.bcrypt_rounds = 12;
+ config.upload_path = '/public/uploads';
+ config.use_port = (config.use_port.slice(0, 1) === 'y') ? true : false;
+
+ var urlObject = url.parse(config.base_url),
+ relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '',
+ host = urlObject.host,
+ protocol = urlObject.protocol,
+ server_conf = config,
+ client_conf = {
+ relative_path: relative_path
+ };
+
+ server_conf.base_url = protocol + '//' + host;
+ server_conf.relative_path = relative_path;
+
+ install.save(server_conf, client_conf, function(err) {
+ require('./database').init(next);
+ });
+ }
+
+ if(config.database === 'redis')
+ prompt.get(install.redisQuestions, dbQuestionsSuccess);
+ else if(config.database === 'mongo')
+ prompt.get(install.mongoQuestions, dbQuestionsSuccess);
};
// prompt prepends "prompt: " to questions, let's clear that.
@@ -119,8 +161,9 @@ var async = require('async'),
prompt.message = '';
prompt.delimiter = '';
- if (!install.values) prompt.get(install.questions, success);
- else {
+ if (!install.values) {
+ prompt.get(install.questions, success);
+ } else {
// Use provided values, fall back to defaults
var config = {},
question, x, numQ;
@@ -176,6 +219,7 @@ var async = require('async'),
async.each(defaults, function (configObj, next) {
meta.configs.setOnEmpty(configObj.field, configObj.value, next);
}, function (err) {
+ console.log('calling meta.configs.init');
meta.configs.init(next);
});
},
@@ -343,8 +387,9 @@ var async = require('async'),
// Add the password questions
questions = questions.concat(passwordQuestions);
- if (!install.values) prompt.get(questions, success);
- else {
+ if (!install.values) {
+ prompt.get(questions, success);
+ } else {
var results = {
username: install.values['admin:username'],
email: install.values['admin:email'],
diff --git a/src/meta.js b/src/meta.js
index 8930c944ba..d75ce18d43 100644
--- a/src/meta.js
+++ b/src/meta.js
@@ -44,7 +44,7 @@ var fs = require('fs'),
db.getObjectFields('config', fields, callback);
},
set: function (field, value, callback) {
- db.setObjectField(field, value, function(err, res) {
+ db.setObjectField('config', field, value, function(err, res) {
if (callback) {
if(!err && Meta.config)
Meta.config[field] = value;
@@ -53,7 +53,7 @@ var fs = require('fs'),
});
},
setOnEmpty: function (field, value, callback) {
- this.get(field, function (err, curValue) {
+ Meta.configs.get(field, function (err, curValue) {
if (!curValue) {
Meta.configs.set(field, value, callback);
} else {
diff --git a/src/plugins.js b/src/plugins.js
index ea0e459980..ca7114da82 100644
--- a/src/plugins.js
+++ b/src/plugins.js
@@ -275,9 +275,9 @@ var fs = require('fs'),
}
// Reload meta data
- plugins.reload(function() {
+ Plugins.reload(function() {
// (De)activation Hooks
- plugins.fireHook('action:plugin.' + (active ? 'de' : '') + 'activate', id);
+ Plugins.fireHook('action:plugin.' + (active ? 'de' : '') + 'activate', id);
if (callback) {
callback({
@@ -326,7 +326,9 @@ var fs = require('fs'),
}
Plugins.isActive(config.id, function(err, active) {
- if (err) next(new Error('no-active-state'));
+ if (err) {
+ next(new Error('no-active-state'));
+ }
delete config.library;
delete config.hooks;