From 889f0e15694a4cb86860305ed309aed71b685764 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 21 Apr 2022 11:40:12 +0100 Subject: [PATCH 1/4] Don't start if user has no home directory If the user doesn't have a defined home dir (env var `HOME`, `USERPROFILE` or `HOMEPATH`) and the `userDir` is not passed on the command line then we shouldn't start as we don't know where to copy the default `settings.js` file to or where to store flows fixes #3539 --- packages/node_modules/node-red/red.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 2af02e2d5..421189118 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -112,6 +112,10 @@ if (parsedArgs.settings) { // Consider compatibility for older versions settingsFile = path.join(process.env.HOMEPATH,".node-red","settings.js"); } else { + if (!parsedArgs.userDir && !(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH)) { + console.log("User has no Home Directory and no userDir set") + process.exit() + } var userDir = parsedArgs.userDir || path.join(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH,".node-red"); var userSettingsFile = path.join(userDir,"settings.js"); if (fs.existsSync(userSettingsFile)) { From 812efde3424a012066d835ef6c28daa531c7a24c Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 21 Apr 2022 12:00:10 +0100 Subject: [PATCH 2/4] Also check if there is a useDir defined --- packages/node_modules/node-red/red.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 421189118..786f86a2b 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -114,7 +114,7 @@ if (parsedArgs.settings) { } else { if (!parsedArgs.userDir && !(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH)) { console.log("User has no Home Directory and no userDir set") - process.exit() + process.exit(1) } var userDir = parsedArgs.userDir || path.join(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH,".node-red"); var userSettingsFile = path.join(userDir,"settings.js"); @@ -321,6 +321,11 @@ httpsPromise.then(function(startupHttps) { settings.userDir = parsedArgs.userDir; } + if (!settings.userDir) { + console.log("No Node-RED userDir set, exiting") + process.exit(1) + } + try { RED.init(server,settings); } catch(err) { From 0014fec63f43842b47e61ac4d17ddce5f922ef3f Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 21 Apr 2022 13:52:38 +0100 Subject: [PATCH 3/4] Remove test that exits if no userDir defined With the storage plugins it is possible to not need a userDir, just a settings.js --- packages/node_modules/node-red/red.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index 786f86a2b..f6f019054 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -321,11 +321,6 @@ httpsPromise.then(function(startupHttps) { settings.userDir = parsedArgs.userDir; } - if (!settings.userDir) { - console.log("No Node-RED userDir set, exiting") - process.exit(1) - } - try { RED.init(server,settings); } catch(err) { From cdcc8cc59a295e7a36311bf14f6d277ebcb42411 Mon Sep 17 00:00:00 2001 From: Ben Hardill Date: Thu, 21 Apr 2022 15:47:40 +0100 Subject: [PATCH 4/4] Update packages/node_modules/node-red/red.js Co-authored-by: Nick O'Leary --- packages/node_modules/node-red/red.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node_modules/node-red/red.js b/packages/node_modules/node-red/red.js index f6f019054..38a51f434 100755 --- a/packages/node_modules/node-red/red.js +++ b/packages/node_modules/node-red/red.js @@ -113,7 +113,7 @@ if (parsedArgs.settings) { settingsFile = path.join(process.env.HOMEPATH,".node-red","settings.js"); } else { if (!parsedArgs.userDir && !(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH)) { - console.log("User has no Home Directory and no userDir set") + console.log("Could not find user directory. Ensure $HOME is set for the current user, or use --userDir option") process.exit(1) } var userDir = parsedArgs.userDir || path.join(process.env.HOME || process.env.USERPROFILE || process.env.HOMEPATH,".node-red");