From 4164898d85340bde8a7778d7ed5e63c8af16091a Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Thu, 17 Feb 2022 12:30:03 -0500 Subject: [PATCH] fix: regression caused by 94b79ce4024f72a3eee2cfa06b05d8f66898149f `./nodebb setup` was no longer able to be called without arguments or env vars --- src/install.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/install.js b/src/install.js index f9f7912d9f..9afa1b54f9 100644 --- a/src/install.js +++ b/src/install.js @@ -47,7 +47,7 @@ questions.optional = [ ]; function checkSetupFlagEnv() { - let setupVal = install.values || {}; + let setupVal = install.values; const envConfMap = { NODEBB_URL: 'url', @@ -65,17 +65,21 @@ function checkSetupFlagEnv() { }; // Set setup values from env vars (if set) - winston.info('[install/checkSetupFlagEnv] checking env vars for setup info...'); - - 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; - } - }); + 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']; + 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):