Merge pull request #3470 from thelounge/xpaw/first-run-crash
Do not crash on first run due to config.js not existing
This commit is contained in:
commit
5ba5505ba4
@ -29,31 +29,11 @@ const argvWithoutOptions = program.parseOptions(process.argv);
|
||||
Helper.setHome(process.env.THELOUNGE_HOME || Utils.defaultHome());
|
||||
|
||||
// Check config file owner and warn if we're running under a different user
|
||||
if (process.getuid) {
|
||||
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."
|
||||
);
|
||||
}
|
||||
try {
|
||||
verifyFileOwner();
|
||||
} catch (e) {
|
||||
// We do not care about failures of these checks
|
||||
// fs.statSync will throw if config.js does not exist (e.g. first run)
|
||||
}
|
||||
|
||||
Utils.checkOldHome();
|
||||
@ -83,3 +63,34 @@ program.parse(argvWithoutOptions.args.concat(argvWithoutOptions.unknown));
|
||||
if (!program.args.length) {
|
||||
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