updated install

v1.18.x
Baris Soner Usakli 11 years ago
parent 1325e4c501
commit b215dbde19

@ -163,7 +163,7 @@
} }
module.setObjectField = function(key, field, value, callback) { module.setObjectField = function(key, field, value, callback) {
redisClient.hset(key, field, value, callback) redisClient.hset(key, field, value, callback);
} }
module.getObject = function(key, callback) { module.getObject = function(key, callback) {

@ -19,8 +19,8 @@ var async = require('async'),
name: 'port', name: 'port',
description: 'Port number of your NodeBB', description: 'Port number of your NodeBB',
'default': nconf.get('port') || 4567, '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]/, 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' message: 'Please enter a value betweeen 1 and 65535'
}, { }, {
name: 'use_port', name: 'use_port',
description: 'Use a port number to access NodeBB?', description: 'Use a port number to access NodeBB?',
@ -32,6 +32,15 @@ var async = require('async'),
description: 'Please enter a NodeBB secret', description: 'Please enter a NodeBB secret',
'default': nconf.get('secret') || utils.generateUUID() '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', name: 'redis:host',
description: 'Host IP or address of your Redis instance', description: 'Host IP or address of your Redis instance',
'default': nconf.get('redis:host') || '127.0.0.1' 'default': nconf.get('redis:host') || '127.0.0.1'
@ -46,11 +55,24 @@ var async = require('async'),
name: "redis:database", name: "redis:database",
description: "Which database to use (0..n)", description: "Which database to use (0..n)",
'default': nconf.get('redis:database') || 0 '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', name: 'mongo:port',
description: 'IP or Hostname to bind to', description: 'Host port of your MongoDB instance',
'default': nconf.get('bind_address') || '0.0.0.0' '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) { setup: function (callback) {
async.series([ async.series([
function(next) { function(next) {
@ -74,7 +96,9 @@ var async = require('async'),
if (!setupVal['admin:email']) winston.error(' admin:email'); if (!setupVal['admin:email']) winston.error(' admin:email');
process.exit(); process.exit();
} }
} else next(); } else {
next();
}
}, },
function (next) { function (next) {
var success = function(err, config) { var success = function(err, config) {
@ -82,36 +106,54 @@ var async = require('async'),
return next(new Error('aborted')); return next(new Error('aborted'));
} }
// Translate redis properties into redis object function dbQuestionsSuccess(err, databaseConfig) {
config.redis = { if (!config) {
host: config['redis:host'], return next(new Error('aborted'));
port: config['redis:port'], }
password: config['redis:password'],
database: config['redis:database'] // Translate redis properties into redis object
}; if(config.database === 'redis') {
delete config['redis:host']; config.redis = {
delete config['redis:port']; host: databaseConfig['redis:host'],
delete config['redis:password']; port: databaseConfig['redis:port'],
delete config['redis:database']; password: databaseConfig['redis:password'],
database: databaseConfig['redis:database']
// Add hardcoded values };
config.bcrypt_rounds = 12; } else if (config.database === 'mongo') {
config.upload_path = '/public/uploads'; config.mongo = {
config.use_port = (config.use_port.slice(0, 1) === 'y') ? true : false; host: databaseConfig['mongo:host'],
port: databaseConfig['mongo:port'],
var urlObject = url.parse(config.base_url), password: databaseConfig['mongo:password'],
relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '', database: databaseConfig['mongo:database']
host = urlObject.host, };
protocol = urlObject.protocol, }
server_conf = config,
client_conf = { // Add hardcoded values
relative_path: relative_path config.bcrypt_rounds = 12;
}; config.upload_path = '/public/uploads';
config.use_port = (config.use_port.slice(0, 1) === 'y') ? true : false;
server_conf.base_url = protocol + '//' + host;
server_conf.relative_path = relative_path; var urlObject = url.parse(config.base_url),
relative_path = (urlObject.pathname && urlObject.pathname.length > 1) ? urlObject.pathname : '',
install.save(server_conf, client_conf, next); 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. // prompt prepends "prompt: " to questions, let's clear that.
@ -119,8 +161,9 @@ var async = require('async'),
prompt.message = ''; prompt.message = '';
prompt.delimiter = ''; prompt.delimiter = '';
if (!install.values) prompt.get(install.questions, success); if (!install.values) {
else { prompt.get(install.questions, success);
} else {
// Use provided values, fall back to defaults // Use provided values, fall back to defaults
var config = {}, var config = {},
question, x, numQ; question, x, numQ;
@ -176,6 +219,7 @@ var async = require('async'),
async.each(defaults, function (configObj, next) { async.each(defaults, function (configObj, next) {
meta.configs.setOnEmpty(configObj.field, configObj.value, next); meta.configs.setOnEmpty(configObj.field, configObj.value, next);
}, function (err) { }, function (err) {
console.log('calling meta.configs.init');
meta.configs.init(next); meta.configs.init(next);
}); });
}, },
@ -343,8 +387,9 @@ var async = require('async'),
// Add the password questions // Add the password questions
questions = questions.concat(passwordQuestions); questions = questions.concat(passwordQuestions);
if (!install.values) prompt.get(questions, success); if (!install.values) {
else { prompt.get(questions, success);
} else {
var results = { var results = {
username: install.values['admin:username'], username: install.values['admin:username'],
email: install.values['admin:email'], email: install.values['admin:email'],

@ -44,7 +44,7 @@ var fs = require('fs'),
db.getObjectFields('config', fields, callback); db.getObjectFields('config', fields, callback);
}, },
set: function (field, value, callback) { set: function (field, value, callback) {
db.setObjectField(field, value, function(err, res) { db.setObjectField('config', field, value, function(err, res) {
if (callback) { if (callback) {
if(!err && Meta.config) if(!err && Meta.config)
Meta.config[field] = value; Meta.config[field] = value;
@ -53,7 +53,7 @@ var fs = require('fs'),
}); });
}, },
setOnEmpty: function (field, value, callback) { setOnEmpty: function (field, value, callback) {
this.get(field, function (err, curValue) { Meta.configs.get(field, function (err, curValue) {
if (!curValue) { if (!curValue) {
Meta.configs.set(field, value, callback); Meta.configs.set(field, value, callback);
} else { } else {

@ -275,9 +275,9 @@ var fs = require('fs'),
} }
// Reload meta data // Reload meta data
plugins.reload(function() { Plugins.reload(function() {
// (De)activation Hooks // (De)activation Hooks
plugins.fireHook('action:plugin.' + (active ? 'de' : '') + 'activate', id); Plugins.fireHook('action:plugin.' + (active ? 'de' : '') + 'activate', id);
if (callback) { if (callback) {
callback({ callback({
@ -326,7 +326,9 @@ var fs = require('fs'),
} }
Plugins.isActive(config.id, function(err, active) { 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.library;
delete config.hooks; delete config.hooks;

Loading…
Cancel
Save