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);