From 5902dbe540437b5061b83ca0739740b0bd1a8a7e Mon Sep 17 00:00:00 2001 From: Max Howell Date: Sun, 12 Jan 2025 14:57:38 -0500 Subject: [PATCH 1/2] =?UTF-8?q?If=20we=E2=80=99re=20root,=20then=20we=20do?= =?UTF-8?q?n=E2=80=99t=20need=20sudo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkgm.ts | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/pkgm.ts b/pkgm.ts index 9d795b6..9d66394 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -107,9 +107,10 @@ async function install(args: string[]) { const self = fromFileUrl(import.meta.url); const pkgx_dir = Deno.env.get("PKGX_DIR") || `${Deno.env.get("HOME")}/.pkgx`; + const needs_sudo = Deno.uid() != 0; - status = await new Deno.Command("/usr/bin/sudo", { - args: [ + if (needs_sudo) { + args = [ "pkgx", "deno^2.1", "run", @@ -119,14 +120,14 @@ async function install(args: string[]) { self, "sudo-install", pkgx_dir, - ...to_install, - ], - env, - clearEnv: true, - }) - .spawn().status; - - Deno.exit(status.code); + ...to_install + ]; + const cmd = "/usr/bin/sudo"; + const status = await new Deno.Command(cmd, {args, env, clearEnv: true}).spawn().status; + Deno.exit(status.code); + } else { + await sudo_install(pkgx_dir, to_install); + } } async function sudo_install(pkgx_dir: string, pkg_prefixes: string[]) { From 7728860f32c55c3dcf2a5afddf410c59c26a7be8 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Sun, 12 Jan 2025 15:09:20 -0500 Subject: [PATCH 2/2] fix lints --- pkgm.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkgm.ts b/pkgm.ts index 9d66394..3bc4f4c 100755 --- a/pkgm.ts +++ b/pkgm.ts @@ -82,7 +82,7 @@ async function install(args: string[]) { }) .spawn(); - let status = await proc.status; + const status = await proc.status; if (!status.success) { Deno.exit(status.code); @@ -120,10 +120,11 @@ async function install(args: string[]) { self, "sudo-install", pkgx_dir, - ...to_install + ...to_install, ]; const cmd = "/usr/bin/sudo"; - const status = await new Deno.Command(cmd, {args, env, clearEnv: true}).spawn().status; + const status = await new Deno.Command(cmd, { args, env, clearEnv: true }) + .spawn().status; Deno.exit(status.code); } else { await sudo_install(pkgx_dir, to_install);