closes #382 - install script can be run via command line

v1.18.x
Julian Lam 11 years ago
parent 57465eb277
commit 42067ce53c

@ -53,13 +53,30 @@ var async = require('async'),
}], }],
setup: function (callback) { setup: function (callback) {
async.series([ async.series([
function (next) { function(next) {
// prompt prepends "prompt: " to questions, let's clear that. // Check if the `--setup` flag contained values we can work with
prompt.start(); var setupVal;
prompt.message = ''; try {
prompt.delimiter = ''; setupVal = JSON.parse(nconf.get('setup'));
} catch (e) {
setupVal = undefined;
}
prompt.get(install.questions, function (err, config) { if (setupVal && setupVal instanceof Object) {
if (setupVal['admin:username'] && setupVal['admin:password'] && setupVal['admin:email']) {
install.values = setupVal;
next();
} else {
winston.error('Required values are missing for automated setup:');
if (!setupVal['admin:username']) winston.error(' admin:username');
if (!setupVal['admin:password']) winston.error(' admin:password');
if (!setupVal['admin:email']) winston.error(' admin:email');
process.exit();
}
} else next();
},
function (next) {
var success = function(err, config) {
if (!config) { if (!config) {
return next(new Error('aborted')); return next(new Error('aborted'));
} }
@ -94,7 +111,24 @@ var async = require('async'),
server_conf.relative_path = relative_path; server_conf.relative_path = relative_path;
install.save(server_conf, client_conf, next); install.save(server_conf, client_conf, next);
}); };
// prompt prepends "prompt: " to questions, let's clear that.
prompt.start();
prompt.message = '';
prompt.delimiter = '';
if (!install.values) prompt.get(install.questions, success);
else {
// Use provided values, fall back to defaults
var config = {},
question, x, numQ;
for(x=0,numQ=install.questions.length;x<numQ;x++) {
question = install.questions[x];
config[question.name] = install.values[question.name] || question['default'] || '';
}
success(null, config);
}
}, },
function (next) { function (next) {
// Applying default database configs // Applying default database configs
@ -222,49 +256,56 @@ var async = require('async'),
winston.warn('No administrators have been detected, running initial user setup'); winston.warn('No administrators have been detected, running initial user setup');
var questions = [{ var questions = [{
name: 'username', name: 'username',
description: 'Administrator username', description: 'Administrator username',
required: true, required: true,
type: 'string' type: 'string'
}, { }, {
name: 'email', name: 'email',
description: 'Administrator email address', description: 'Administrator email address',
pattern: /.+@.+/, pattern: /.+@.+/,
required: true required: true
}, { }, {
name: 'password', name: 'password',
description: 'Password', description: 'Password',
required: true, required: true,
hidden: true, hidden: true,
type: 'string' type: 'string'
}], }],
getAdminInfo = function (callback) { success = function(err, results) {
prompt.get(questions, function (err, results) { if (!results) {
if (!results) { return callback(new Error('aborted'));
return callback(new Error('aborted')); }
nconf.set('bcrypt_rounds', 12);
User.create(results.username, results.password, results.email, function (err, uid) {
if (err) {
winston.warn(err.message + ' Please try again.');
return getAdminInfo();
} }
nconf.set('bcrypt_rounds', 12); Groups.getGidFromName('Administrators', function (err, gid) {
User.create(results.username, results.password, results.email, function (err, uid) { if (gid) {
if (err) { Groups.join(gid, uid, callback);
winston.warn(err.message + ' Please try again.'); } else {
return getAdminInfo(); Groups.create('Administrators', 'Forum Administrators', function (err, groupObj) {
Groups.join(groupObj.gid, uid, callback);
});
} }
Groups.getGidFromName('Administrators', function (err, gid) {
if (gid) {
Groups.join(gid, uid, callback);
} else {
Groups.create('Administrators', 'Forum Administrators', function (err, groupObj) {
Groups.join(groupObj.gid, uid, callback);
});
}
});
}); });
}); });
}; };
getAdminInfo(callback); if (!install.values) prompt.get(questions, success);
else {
var results = {
username: install.values['admin:username'],
email: install.values['admin:email'],
password: install.values['admin:password']
};
success(null, results);
}
}, },
save: function (server_conf, client_conf, callback) { save: function (server_conf, client_conf, callback) {
// Server Config // Server Config

Loading…
Cancel
Save