Skip to content

Commit 5902dbe

Browse files
committed
If we’re root, then we don’t need sudo
1 parent 060cb45 commit 5902dbe

1 file changed

Lines changed: 11 additions & 10 deletions

File tree

pkgm.ts

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ async function install(args: string[]) {
107107

108108
const self = fromFileUrl(import.meta.url);
109109
const pkgx_dir = Deno.env.get("PKGX_DIR") || `${Deno.env.get("HOME")}/.pkgx`;
110+
const needs_sudo = Deno.uid() != 0;
110111

111-
status = await new Deno.Command("/usr/bin/sudo", {
112-
args: [
112+
if (needs_sudo) {
113+
args = [
113114
"pkgx",
114115
"deno^2.1",
115116
"run",
@@ -119,14 +120,14 @@ async function install(args: string[]) {
119120
self,
120121
"sudo-install",
121122
pkgx_dir,
122-
...to_install,
123-
],
124-
env,
125-
clearEnv: true,
126-
})
127-
.spawn().status;
128-
129-
Deno.exit(status.code);
123+
...to_install
124+
];
125+
const cmd = "/usr/bin/sudo";
126+
const status = await new Deno.Command(cmd, {args, env, clearEnv: true}).spawn().status;
127+
Deno.exit(status.code);
128+
} else {
129+
await sudo_install(pkgx_dir, to_install);
130+
}
130131
}
131132

132133
async function sudo_install(pkgx_dir: string, pkg_prefixes: string[]) {

0 commit comments

Comments
 (0)