diff --git a/app.js b/app.js index 66f16da88c..70f6e7f0a8 100644 --- a/app.js +++ b/app.js @@ -227,15 +227,35 @@ function setup() { var install = require('./src/install'); - winston.info('Welcome to NodeBB!'); - winston.info('This looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.'); - winston.info('Press enter to accept the default setting (shown in brackets).'); + process.stdout.write('\nWelcome to NodeBB!\n'); + process.stdout.write('\nThis looks like a new installation, so you\'ll have to answer a few questions about your environment before we can proceed.\n'); + process.stdout.write('Press enter to accept the default setting (shown in brackets).\n'); + + install.setup(function (err, data) { + var separator = ' '; + if (process.stdout.columns > 10) { + for(var x=0,cols=process.stdout.columns-10;x 0) { - winston.info('Administrator found, skipping Admin setup'); + process.stdout.write('Administrator found, skipping Admin setup\n'); next(); } else { createAdmin(next); @@ -279,9 +289,10 @@ function createAdministrator(next) { function createAdmin(callback) { var User = require('./user'), - Groups = require('./groups'); + Groups = require('./groups'), + password; - winston.warn('No administrators have been detected, running initial user setup'); + winston.warn('No administrators have been detected, running initial user setup\n'); var questions = [{ name: 'username', @@ -323,7 +334,9 @@ function createAdmin(callback) { return callback(new Error('invalid-values')); } - Groups.join('administrators', uid, callback); + Groups.join('administrators', uid, function(err) { + callback(err, results); + }); }); }, retryPassword = function (originalResults) { @@ -348,11 +361,17 @@ function createAdmin(callback) { if (!install.values) { prompt.get(questions, success); } else { + // If automated setup did not provide a user password, generate one, it will be shown to the user upon setup completion + if (!install.values.hasOwnProperty('admin:password')) { + process.stdout.write('Password was not provided during automated setup, generating one...\n') + password = utils.generateUUID().slice(0, 8); + } + var results = { - username: install.values['admin:username'], - email: install.values['admin:email'], - password: install.values['admin:password'], - 'password:confirm': install.values['admin:password:confirm'] + username: install.values['admin:username'] || 'admin', + email: install.values['admin:email'] || '', + password: install.values['admin:password'] || password, + 'password:confirm': install.values['admin:password:confirm'] || password }; success(null, results); @@ -368,11 +387,11 @@ function createCategories(next) { } if (Array.isArray(categoryData) && categoryData.length) { - winston.info('Categories OK. Found ' + categoryData.length + ' categories.'); + process.stdout.write('Categories OK. Found ' + categoryData.length + ' categories.\n'); return next(); } - winston.warn('No categories found, populating instance with default categories'); + process.stdout.write('No categories found, populating instance with default categories\n'); fs.readFile(path.join(__dirname, '../', 'install/data/categories.json'), function (err, default_categories) { if (err) { @@ -423,7 +442,7 @@ function createWelcomePost(next) { function enableDefaultPlugins(next) { var Plugins = require('./plugins'); - winston.info('Enabling default plugins'); + process.stdout.write('Enabling default plugins\n'); var defaultEnabled = [ 'nodebb-plugin-markdown', @@ -462,6 +481,8 @@ function setCopyrightWidget(next) { } install.setup = function (callback) { + var upgrade = require('./upgrade'); + async.series([ checkSetupFlag, checkCIFlag, @@ -475,14 +496,23 @@ install.setup = function (callback) { enableDefaultPlugins, setCopyrightWidget, function (next) { - require('./upgrade').upgrade(next); + upgrade.check(function(uptodate) { + if (!uptodate) { upgrade.upgrade(next); } + else { next(); } + }); } - ], function (err) { + ], function (err, results) { if (err) { winston.warn('NodeBB Setup Aborted.\n ' + err.stack); process.exit(); } else { - callback(); + var data = {}; + if (results[6]) { + data.username = results[6].username + data.password = results[6].password; + } + + callback(null, data); } }); }; @@ -500,7 +530,7 @@ install.save = function (server_conf, callback) { return callback(err); } - winston.info('Configuration Saved OK'); + process.stdout.write('Configuration Saved OK\n'); nconf.file({ file: path.join(__dirname, '..', 'config.json') diff --git a/src/upgrade.js b/src/upgrade.js index 3a52020ca5..a11e890a52 100644 --- a/src/upgrade.js +++ b/src/upgrade.js @@ -971,23 +971,25 @@ Upgrade.upgrade = function(callback) { } else { winston.info('[upgrade] Schema already up to date!'); } - - process.exit(); } else { switch(err.message) { case 'upgrade-not-possible': winston.error('[upgrade] NodeBB upgrade could not complete, as your database schema is too far out of date.'); winston.error('[upgrade] Please ensure that you did not skip any minor version upgrades.'); winston.error('[upgrade] (e.g. v0.1.x directly to v0.3.x)'); - process.exit(); break; default: winston.error('[upgrade] Errors were encountered while updating the NodeBB schema: ' + err.message); - process.exit(); break; } } + + if (typeof callback === 'function') { + callback(err); + } else { + process.exit(); + } }); };