From 2953eb17d679e963b79913ecf89ca6e64114dd18 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 18 Jul 2022 19:57:08 +0200 Subject: [PATCH] Refuse installing Clusterio as root I have seen multiple people have installed Clusterio as the root account and then run it as root when tasked with setting up Clusterio on Linux. Make this mistake harder to do by refusing to install as root by default. --- README.md | 2 +- packages/create/create.js | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 2017c1be..38b00417 100644 --- a/README.md +++ b/README.md @@ -105,7 +105,7 @@ Otherwise see below for OS specific instructions. wget -qO - https://deb.nodesource.com/setup_14.x | sudo -E bash - sudo apt install nodejs -2. Create a new directory and run the Clusterio installer: +2. Log in as the user you wish to install Clusterio as (do not use root), and then create a new directory and run the Clusterio installer: mkdir clusterio cd clusterio diff --git a/packages/create/create.js b/packages/create/create.js index bc826314..446b435e 100755 --- a/packages/create/create.js +++ b/packages/create/create.js @@ -168,6 +168,19 @@ async function validateInstallDir() { } } +async function validateNotRoot(args) { + if (args.allowInstallAsRoot) { + return; + } + + if (os.userInfo().uid === 0) { + throw new InstallError( + "Refusing to install as root. Create a separate user account for clusterio " + + "and then use su/sudo to switch to it before invoking the installer." + ); + } +} + async function installClusterio(mode, plugins) { try { await safeOutputFile("package.json", JSON.stringify({ @@ -547,6 +560,9 @@ async function main() { if (process.platform === "linux") { args = args + .option("allow-install-as-root", { + nargs: 0, describe: "(Linux only) Allow installing as root (not recommended)", type: "boolean", + }) .option("download-headless", { nargs: 0, describe: "(Linux only) Automatically download and unpack the latest factorio release. " + @@ -563,6 +579,7 @@ async function main() { if (!dev) { await validateInstallDir(); + await validateNotRoot(args); } let answers = await inquirerMissingArgs(args);