hardlounge/src/command-line/index.js

86 lines
2.5 KiB
JavaScript
Raw Normal View History

"use strict";
2018-06-15 16:31:06 -04:00
const log = require("../log");
2017-11-12 13:28:13 -05:00
const fs = require("fs");
const path = require("path");
2019-05-20 11:17:35 -04:00
const colors = require("chalk");
const program = require("commander");
const Helper = require("../helper");
const Utils = require("./utils");
2014-08-18 21:18:40 -04:00
2019-07-17 05:33:59 -04:00
program
.version(Helper.getVersion(), "-v, --version")
.option(
"-c, --config <key=value>",
"override entries of the configuration file, must be specified for each entry that needs to be overriden",
Utils.parseConfigOptions
)
2019-08-12 04:03:36 -04:00
.on("command:*", () => {
log.error(
`Unknown command. See ${colors.bold("--help")} for a list of available commands.`
);
process.exit(1);
})
.on("--help", Utils.extraHelp);
// Parse options from `argv` returning `argv` void of these options.
const argvWithoutOptions = program.parseOptions(process.argv);
2016-05-09 12:19:16 -04:00
Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome());
2014-10-03 19:33:44 -04:00
// Check config file owner and warn if we're running under a different user
if (process.getuid) {
2019-05-20 11:17:35 -04:00
const uid = process.getuid();
if (uid === 0) {
2019-07-17 05:33:59 -04:00
log.warn(
`You are currently running The Lounge as root. ${colors.bold.red(
"We highly discourage running as root!"
)}`
);
2019-05-20 11:17:35 -04:00
}
const configStat = fs.statSync(path.join(Helper.getHomePath(), "config.js"));
if (configStat && configStat.uid !== uid) {
log.warn(
"Config file owner does not match the user you are currently running The Lounge as."
);
log.warn(
"To prevent any issues, please run thelounge commands " +
"as the correct user that owns the config folder."
);
log.warn(
"See https://thelounge.chat/docs/usage#using-the-correct-system-user for more information."
);
}
}
2018-03-02 11:59:37 -05:00
Utils.checkOldHome();
// Merge config key-values passed as CLI options into the main config
Helper.mergeConfig(Helper.config, program.config);
require("./start");
if (!Helper.config.public && !Helper.config.ldap.enable) {
require("./users");
}
2017-09-18 11:57:24 -04:00
require("./install");
require("./uninstall");
require("./upgrade");
require("./outdated");
// `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 16:53:26 -04:00
2014-08-18 21:18:40 -04:00
if (!program.args.length) {
program.help();
2014-08-18 21:18:40 -04:00
}