2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2018-06-15 22:31:06 +02:00
|
|
|
const log = require("../log");
|
2017-11-12 19:28:13 +01:00
|
|
|
const fs = require("fs");
|
|
|
|
const path = require("path");
|
2017-07-18 11:36:24 +02:00
|
|
|
const program = require("commander");
|
|
|
|
const Helper = require("../helper");
|
2017-08-21 07:49:32 +02:00
|
|
|
const Utils = require("./utils");
|
2014-08-19 03:18:40 +02:00
|
|
|
|
2017-02-18 04:23:01 +01:00
|
|
|
program.version(Helper.getVersion(), "-v, --version")
|
2017-12-09 21:06:41 +01:00
|
|
|
.option(
|
|
|
|
"-c, --config <key=value>",
|
|
|
|
"override entries of the configuration file, must be specified for each entry that needs to be overriden",
|
|
|
|
Utils.parseConfigOptions
|
|
|
|
)
|
2017-12-10 22:57:26 +01:00
|
|
|
.on("--help", Utils.extraHelp);
|
|
|
|
|
|
|
|
// Parse options from `argv` returning `argv` void of these options.
|
|
|
|
const argvWithoutOptions = program.parseOptions(process.argv);
|
2016-05-09 18:19:16 +02:00
|
|
|
|
2017-11-22 22:51:22 +01:00
|
|
|
Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome());
|
2014-10-04 01:33:44 +02:00
|
|
|
|
2018-06-19 15:17:42 +02:00
|
|
|
// Check config file owner and warn if we're running under a different user
|
|
|
|
if (process.getuid) {
|
|
|
|
fs.stat(path.join(Helper.getHomePath(), "config.js"), (err, stat) => {
|
|
|
|
if (!err && stat.uid !== process.getuid()) {
|
|
|
|
log.warn("Config file owner does not match the user you are currently running The Lounge as.");
|
|
|
|
log.warn("To avoid issues, you should execute The Lounge commands under the same user.");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-03-02 17:59:37 +01:00
|
|
|
Utils.checkOldHome();
|
|
|
|
|
2017-12-09 21:06:41 +01:00
|
|
|
// Merge config key-values passed as CLI options into the main config
|
2019-03-04 19:35:21 +01:00
|
|
|
Helper.mergeConfig(Helper.config, program.config);
|
2017-12-09 21:06:41 +01:00
|
|
|
|
2016-04-19 22:58:49 +02:00
|
|
|
require("./start");
|
2018-02-20 08:28:04 +01:00
|
|
|
|
2017-12-07 03:28:21 +01:00
|
|
|
if (!Helper.config.public && !Helper.config.ldap.enable) {
|
|
|
|
require("./users");
|
|
|
|
}
|
2018-02-20 08:28:04 +01:00
|
|
|
|
2017-09-18 17:57:24 +02:00
|
|
|
require("./install");
|
2018-01-05 03:09:59 +01:00
|
|
|
require("./uninstall");
|
2018-04-29 09:47:39 +02:00
|
|
|
require("./upgrade");
|
2016-04-19 22:58:49 +02:00
|
|
|
|
2017-12-10 22:57:26 +01:00
|
|
|
// `parse` expects to be passed `process.argv`, but we need to remove to give it
|
|
|
|
// a version of `argv` that does not contain options already parsed by
|
|
|
|
// `parseOptions` above.
|
|
|
|
// This is done by giving it the updated `argv` that `parseOptions` returned,
|
|
|
|
// except it returns an object with `args`/`unknown`, so we need to concat them.
|
|
|
|
// See https://github.com/tj/commander.js/blob/fefda77f463292/index.js#L686-L763
|
|
|
|
program.parse(argvWithoutOptions.args.concat(argvWithoutOptions.unknown));
|
2014-10-14 22:53:26 +02:00
|
|
|
|
2014-08-19 03:18:40 +02:00
|
|
|
if (!program.args.length) {
|
2017-02-18 04:23:01 +01:00
|
|
|
program.help();
|
2014-08-19 03:18:40 +02:00
|
|
|
}
|