Skip to content

Commit

Permalink
synch remote main with local main
Browse files Browse the repository at this point in the history
  • Loading branch information
Eshar committed Feb 12, 2025
2 parents 47131ee + 66e5950 commit 4940245
Showing 1 changed file with 37 additions and 40 deletions.
77 changes: 37 additions & 40 deletions src/install.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,56 +69,52 @@ function checkSetupFlagEnv() {

// Set setup values from env vars (if set)
const envKeys = Object.keys(process.env);
if (Object.keys(envConfMap).some(key => envKeys.includes(key))) {
winston.info('[install/checkSetupFlagEnv] checking env vars for setup info...');
setupVal = setupVal || {};

Object.entries(process.env).forEach(([evName, evValue]) => { // get setup values from env
if (evName.startsWith('NODEBB_DB_')) {
setupVal[`${process.env.NODEBB_DB}:${envConfMap[evName]}`] = evValue;
} else if (evName.startsWith('NODEBB_')) {
setupVal[envConfMap[evName]] = evValue;
}
});

setupVal['admin:password:confirm'] = setupVal['admin:password'];
if (!Object.keys(envConfMap).some(key => envKeys.includes(key))) {
return;
}

winston.info('[install/checkSetupFlagEnv] checking env vars for setup info...');
setupVal = setupVal || {};

// Process relevant environment variables
const processEnvVariable = (evName, evValue) => {
if (evName.startsWith('NODEBB_DB_')) {
setupVal[`${process.env.NODEBB_DB}:${envConfMap[evName]}`] = evValue;
} else if (evName.startsWith('NODEBB_')) {
setupVal[envConfMap[evName]] = evValue;
}
};

Object.entries(process.env).forEach(([evName, evValue]) => {
processEnvVariable(evName, evValue);
});

// Confirm admin password setup
setupVal['admin:password:confirm'] = setupVal['admin:password'];

// try to get setup values from json, if successful this overwrites all values set by env
// TODO: better behaviour would be to support overrides per value, i.e. in order of priority (generic pattern):
// flag, env, config file, default
const setupData = nconf.get('setup');
if (!setupData) return;

try {
if (nconf.get('setup')) {
const setupJSON = JSON.parse(nconf.get('setup'));
setupVal = { ...setupVal, ...setupJSON };
}
const setupJSON = JSON.parse(setupData);
setupVal = { ...setupVal, ...setupJSON };
} catch (err) {
winston.error('[install/checkSetupFlagEnv] invalid json in nconf.get(\'setup\'), ignoring setup values from json');
winston.error('[install/checkSetupFlagEnv] invalid JSON in nconf.get(\'setup\'), ignoring setup values from JSON');
}

if (setupVal && typeof setupVal === 'object') {
if (setupVal['admin:username'] && setupVal['admin:password'] && setupVal['admin:password:confirm'] && setupVal['admin:email']) {
install.values = setupVal;
} else {
winston.error('[install/checkSetupFlagEnv] required values are missing for automated setup:');
if (!setupVal['admin:username']) {
winston.error(' admin:username');
}
if (!setupVal['admin:password']) {
winston.error(' admin:password');
}
if (!setupVal['admin:password:confirm']) {
winston.error(' admin:password:confirm');
}
if (!setupVal['admin:email']) {
winston.error(' admin:email');
}
if (!setupVal || typeof setupVal !== 'object') return;

process.exit();
}
} else if (nconf.get('database')) {
install.values = install.values || {};
install.values.database = nconf.get('database');
const requiredFields = ['admin:username', 'admin:password', 'admin:password:confirm', 'admin:email'];
const missingFields = requiredFields.filter(field => !setupVal[field]);

if (missingFields.length === 0) {
install.values = setupVal;
} else {
winston.error('[install/checkSetupFlagEnv] required values are missing for automated setup:');
missingFields.forEach(field => winston.error(` ${field}`));
}
}

Expand Down Expand Up @@ -261,6 +257,7 @@ async function enableDefaultTheme() {
});
}


async function createDefaultUserGroups() {
const groups = require('./groups');
async function createGroup(name) {
Expand Down

0 comments on commit 4940245

Please sign in to comment.