From 42067ce53c4bc578b485c6f759622241d6465f7f Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Sat, 5 Oct 2013 13:48:23 -0400 Subject: [PATCH] closes #382 - install script can be run via command line --- src/install.js | 127 ++++++++++++++++++++++++++++++++----------------- 1 file changed, 84 insertions(+), 43 deletions(-) diff --git a/src/install.js b/src/install.js index eb292e319c..578cd551df 100644 --- a/src/install.js +++ b/src/install.js @@ -53,13 +53,30 @@ var async = require('async'), }], setup: function (callback) { async.series([ - function (next) { - // prompt prepends "prompt: " to questions, let's clear that. - prompt.start(); - prompt.message = ''; - prompt.delimiter = ''; + function(next) { + // Check if the `--setup` flag contained values we can work with + var setupVal; + try { + 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) { return next(new Error('aborted')); } @@ -94,7 +111,24 @@ var async = require('async'), server_conf.relative_path = relative_path; 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