Do not crash on first run due to config.js not existing
This commit is contained in:
parent
5595b17060
commit
41e5090fb0
@ -29,31 +29,11 @@ const argvWithoutOptions = program.parseOptions(process.argv);
|
|||||||
Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome());
|
Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome());
|
||||||
|
|
||||||
// Check config file owner and warn if we're running under a different user
|
// Check config file owner and warn if we're running under a different user
|
||||||
if (process.getuid) {
|
try {
|
||||||
const uid = process.getuid();
|
verifyFileOwner();
|
||||||
|
} catch (e) {
|
||||||
if (uid === 0) {
|
// We do not care about failures of these checks
|
||||||
log.warn(
|
// fs.statSync will throw if config.js does not exist (e.g. first run)
|
||||||
`You are currently running The Lounge as root. ${colors.bold.red(
|
|
||||||
"We highly discourage running as root!"
|
|
||||||
)}`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
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."
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.checkOldHome();
|
Utils.checkOldHome();
|
||||||
@ -83,3 +63,34 @@ program.parse(argvWithoutOptions.args.concat(argvWithoutOptions.unknown));
|
|||||||
if (!program.args.length) {
|
if (!program.args.length) {
|
||||||
program.help();
|
program.help();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function verifyFileOwner() {
|
||||||
|
if (!process.getuid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const uid = process.getuid();
|
||||||
|
|
||||||
|
if (uid === 0) {
|
||||||
|
log.warn(
|
||||||
|
`You are currently running The Lounge as root. ${colors.bold.red(
|
||||||
|
"We highly discourage running as root!"
|
||||||
|
)}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
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."
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user