Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 20 additions & 14 deletions pkgm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -297,21 +297,27 @@ async function query_pkgx(
set("PKGX_DIST_URL");
set("XDG_DATA_HOME");

const needs_sudo_backwards = install_prefix().string == "/usr/local";
let cmd = needs_sudo_backwards ? "/usr/bin/sudo" : pkgx;
const isRoot = Deno.uid() == 0;
const sudoUser = Deno.env.get("SUDO_USER");
const prefix = install_prefix().string;

if (prefix == "/usr/local" && isRoot && !sudoUser) {
console.error(
"%cwarning",
"color:yellow",
"installing as root; installing via `sudo` is preferred",
);
}

const needs_sudo_backwards =
prefix == "/usr/local" && !isRoot && !sudoUser;

Comment thread
jhheider marked this conversation as resolved.
let cmd = pkgx;

if (needs_sudo_backwards) {
if (!Deno.env.get("SUDO_USER")) {
if (Deno.uid() == 0) {
console.error(
"%cwarning",
"color:yellow",
"installing as root; installing via `sudo` is preferred",
);
}
cmd = pkgx;
} else {
args.unshift("-u", Deno.env.get("SUDO_USER")!, pkgx);
}
cmd = "/usr/bin/sudo";
const user = Deno.env.get("USER")!;
Comment thread
jhheider marked this conversation as resolved.
args.unshift("-u", user, pkgx);
Comment on lines +319 to +320
Comment on lines +312 to +320
}
Comment on lines +318 to 321

const proc = new Deno.Command(cmd, {
Expand Down
Loading