From 7e4534afa9c8ff5bf6c38c3bdbcb5dfe66ac369c Mon Sep 17 00:00:00 2001 From: Shell Turner Date: Wed, 1 Oct 2014 17:59:35 +0200 Subject: [PATCH 1/4] Always go through the Helper object to load config --- src/client.js | 3 ++- src/command-line/start.js | 3 ++- src/log.js | 2 +- src/server.js | 2 +- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/client.js b/src/client.js index 7cc339c6..077a8cc4 100644 --- a/src/client.js +++ b/src/client.js @@ -1,5 +1,4 @@ var _ = require("lodash"); -var config = require("../config"); var Chan = require("./models/chan"); var crypto = require("crypto"); var log = require("./log"); @@ -8,6 +7,8 @@ var Msg = require("./models/msg"); var Network = require("./models/network"); var slate = require("slate-irc"); var tls = require("tls"); +var Helper = require("./helper"); +var config = Helper.getConfig(); module.exports = Client; diff --git a/src/command-line/start.js b/src/command-line/start.js index 061dbbb9..f936a273 100644 --- a/src/command-line/start.js +++ b/src/command-line/start.js @@ -1,7 +1,8 @@ -var config = require("../../config"); var ClientManager = new require("../clientManager"); var program = require("commander"); var shout = require("../server"); +var Helper = require("../helper"); +var config = Helper.getConfig(); program .option("-H, --host ", "host") diff --git a/src/log.js b/src/log.js index 2224da6c..60af9623 100644 --- a/src/log.js +++ b/src/log.js @@ -1,8 +1,8 @@ -var config = require("../config"); var fs = require("fs"); var mkdirp = require("mkdirp"); var moment = require("moment"); var Helper = require("./helper"); +var config = Helper.getConfig(); module.exports = { write: function(user, network, chan, msg) { diff --git a/src/server.js b/src/server.js index e580a523..139f8cd3 100644 --- a/src/server.js +++ b/src/server.js @@ -2,11 +2,11 @@ var _ = require("lodash"); var bcrypt = require("bcrypt"); var Client = require("./client"); var ClientManager = require("./clientManager"); -var config = require("../config"); var express = require("express"); var fs = require("fs"); var io = require("socket.io"); var Helper = require("./helper"); +var config = Helper.getConfig(); var sockets = null; var manager = new ClientManager(); From 791a5914df2b4fdadbbe7e5b3bca5023ee2bf824 Mon Sep 17 00:00:00 2001 From: Shell Turner Date: Wed, 1 Oct 2014 18:13:37 +0200 Subject: [PATCH 2/4] Move config.js into the Shout home directory by default --- config.js | 4 ---- src/helper.js | 12 ++++++++++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/config.js b/config.js index 3d46aa71..21681a81 100644 --- a/config.js +++ b/config.js @@ -187,7 +187,3 @@ module.exports = { certificate: "" } }; - -if ("SHOUT_CONFIG" in process.env) { - module.exports = require(process.env.SHOUT_CONFIG); -} diff --git a/src/helper.js b/src/helper.js index d616592b..9c5b11a9 100644 --- a/src/helper.js +++ b/src/helper.js @@ -1,13 +1,21 @@ +var fs = require("fs"); var path = require("path"); var Helper = module.exports = { getConfig: function () { - return require(path.resolve(__dirname, "..", "config")); + var filename = process.env.SHOUT_CONFIG; + if(!filename || !fs.exists(filename)) { + filename = this.resolveHomePath("config.js"); + if(!fs.exists(filename)) { + filename = path.resolve(__dirname, "..", "config"); + } + } + return require(filename); }, getHomeDirectory: function () { return ( - this.getConfig().home + (process.env.SHOUT_CONFIG && fs.exists(process.env.SHOUT_CONFIG) && this.getConfig().home) || process.env.SHOUT_HOME || path.resolve(process.env.HOME, ".shout") ); From b7fd64c2d8588097e2b4bf488a59d93d6daed83b Mon Sep 17 00:00:00 2001 From: Shell Turner Date: Wed, 1 Oct 2014 18:43:46 +0200 Subject: [PATCH 3/4] Change config command to edit config.js in the Shout home directory Also, copy config.js to the Shout home directory if it's not already there. --- src/command-line/config.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/command-line/config.js b/src/command-line/config.js index 32e54426..e01a7157 100644 --- a/src/command-line/config.js +++ b/src/command-line/config.js @@ -1,7 +1,19 @@ +var fs = require("fs"); +var path = require("path"); var program = require("commander"); +var mkdirp = require("mkdirp"); var child = require("child_process"); +var Helper = require("../helper"); -var CONFIG_PATH = process.cwd() + "/config.js"; +var CONFIG_PATH = process.env.SHOUT_CONFIG; +if(!CONFIG_PATH) { + CONFIG_PATH = Helper.resolveHomePath("config.js"); +} +if(!fs.exists(CONFIG_PATH)) { + mkdirp.sync(Helper.getHomeDirectory()); + var configFile = fs.readFileSync(path.resolve(__dirname, "..", "..", "config.js")); + fs.writeFileSync(CONFIG_PATH, configFile); +} program .command("config") From cb588dc22fcd8925d1319e0f934c239fa49fd929 Mon Sep 17 00:00:00 2001 From: Shell Turner Date: Wed, 1 Oct 2014 18:45:34 +0200 Subject: [PATCH 4/4] Don't sudo when editing the config --- src/command-line/config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/command-line/config.js b/src/command-line/config.js index e01a7157..5c0991a8 100644 --- a/src/command-line/config.js +++ b/src/command-line/config.js @@ -20,8 +20,8 @@ program .description("Edit config: '" + CONFIG_PATH + "'") .action(function() { child.spawn( - "sudo", - ["vi", CONFIG_PATH], + "vi", + [CONFIG_PATH], {stdio: "inherit"} ); });