From c9619397b6abfd2902ca417e130cb44adda53989 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 18 Jul 2022 19:39:01 +0200 Subject: [PATCH 1/3] Use current user's group for systemd files Generate systemd files using the current user's main group name instead of nogroup as the latter is not present in all systems. --- packages/create/create.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/packages/create/create.js b/packages/create/create.js index 1d7972a2..bc826314 100755 --- a/packages/create/create.js +++ b/packages/create/create.js @@ -225,6 +225,17 @@ async function installClusterio(mode, plugins) { } } +async function groupIdToName(gid) { + try { + let exec = util.promisify(child_process.exec); + let { stdout } = await exec(`getent group ${gid}`); + return stdout.split(":")[0]; + } catch (err) { + logger.warn(`getent group ${gid} failed: ${err.message}`); + return gid; + } +} + async function writeScripts(mode) { if (["standalone", "master"].includes(mode)) { if (process.platform === "win32") { @@ -245,7 +256,7 @@ Description=Clusterio Master [Service] User=${os.userInfo().username} -Group=nogroup +Group=${await groupIdToName(os.userInfo().gid)} WorkingDirectory=${process.cwd()} KillMode=mixed KillSignal=SIGINT @@ -276,7 +287,7 @@ Description=Clusterio Slave [Service] User=${os.userInfo().username} -Group=nogroup +Group=${await groupIdToName(os.userInfo().gid)} WorkingDirectory=${process.cwd()} KillMode=mixed KillSignal=SIGINT From 2953eb17d679e963b79913ecf89ca6e64114dd18 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 18 Jul 2022 19:57:08 +0200 Subject: [PATCH 2/3] 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); From 2408dc8985d50fb63d19bdfb971ab904d447c8f6 Mon Sep 17 00:00:00 2001 From: Hornwitser Date: Mon, 18 Jul 2022 20:10:08 +0200 Subject: [PATCH 3/3] Remove obsolete Factorio download instructions On Linux the installer offers to correctly download and install the latest version of Factorio. Remove no longer needed instructions for how to do it incorrectly. --- README.md | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/README.md b/README.md index 38b00417..c326d14c 100644 --- a/README.md +++ b/README.md @@ -113,14 +113,7 @@ Otherwise see below for OS specific instructions. Make sure to note down the admin authentication token it provides at the end as you will need it later. -3. If you chose to use local factorio directory for the Factorio installation then download the headless build of Factorio and unpack it: - - wget -O factorio.tar.xz https://www.factorio.com/get-download/latest/headless/linux64 - tar -xf factorio.tar.xz - - To specify a version of Factorio to download replace "latest" in the URL with a version number like "1.0.0". - -4. Optionally copy the generated systemd service files in `systemd` folder to `/etc/systemd/system/`. +3. Optionally copy the generated systemd service files in `systemd` folder to `/etc/systemd/system/`. **Ubuntu with Docker**