From cc80a23b0271eebd0c593431d7dc2caa3d2114c8 Mon Sep 17 00:00:00 2001 From: Max Howell Date: Wed, 26 Mar 2025 11:46:03 -0400 Subject: [PATCH] =?UTF-8?q?Don=E2=80=99t=20bail=20if=20no=20running=20as?= =?UTF-8?q?=20root=20in=20docker?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgm.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/pkgm.ts b/pkgm.ts index 154c268..b26e72b 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -257,13 +257,18 @@ async function query_pkgx( set("PKGX_DIST_URL"); const needs_sudo_backwards = install_prefix().string == "/usr/local"; - const cmd = needs_sudo_backwards ? "/usr/bin/sudo" : pkgx; + let cmd = needs_sudo_backwards ? "/usr/bin/sudo" : pkgx; if (needs_sudo_backwards) { if (!Deno.env.get("SUDO_USER")) { - //TODO if no SUDO_USER then probs we are a root shell, if so set PKGX_DIR and skip hard link step - throw new Error("SUDO_USER not set, cannot install as root"); + if (!Path.root.join(".dockerenv").isFile()) { // if we're running in Docker then screw it, it's fine + //TODO if no SUDO_USER then probs we are a root shell, if so set PKGX_DIR and skip hard link step + throw new Error("SUDO_USER not set, cannot install as root"); + } else { + cmd = pkgx; + } + } else { + args.unshift("-u", Deno.env.get("SUDO_USER")!, pkgx); } - args.unshift("-u", Deno.env.get("SUDO_USER")!, pkgx); } const proc = new Deno.Command(cmd, {