Skip to content

Commit 2b64017

Browse files
authored
Merge pull request #53 from pkgxdev/docker-root-ok
Don’t bail if no running as root in docker
2 parents 3ccbcb4 + cc80a23 commit 2b64017

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

pkgm.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -257,13 +257,18 @@ async function query_pkgx(
257257
set("PKGX_DIST_URL");
258258

259259
const needs_sudo_backwards = install_prefix().string == "/usr/local";
260-
const cmd = needs_sudo_backwards ? "/usr/bin/sudo" : pkgx;
260+
let cmd = needs_sudo_backwards ? "/usr/bin/sudo" : pkgx;
261261
if (needs_sudo_backwards) {
262262
if (!Deno.env.get("SUDO_USER")) {
263-
//TODO if no SUDO_USER then probs we are a root shell, if so set PKGX_DIR and skip hard link step
264-
throw new Error("SUDO_USER not set, cannot install as root");
263+
if (!Path.root.join(".dockerenv").isFile()) { // if we're running in Docker then screw it, it's fine
264+
//TODO if no SUDO_USER then probs we are a root shell, if so set PKGX_DIR and skip hard link step
265+
throw new Error("SUDO_USER not set, cannot install as root");
266+
} else {
267+
cmd = pkgx;
268+
}
269+
} else {
270+
args.unshift("-u", Deno.env.get("SUDO_USER")!, pkgx);
265271
}
266-
args.unshift("-u", Deno.env.get("SUDO_USER")!, pkgx);
267272
}
268273

269274
const proc = new Deno.Command(cmd, {

0 commit comments

Comments
 (0)