Skip to content

Commit 07038e1

Browse files
authored
Merge pull request #1 from pkgxdev/no-need-sudo-if-root
If we’re root, then we don’t need sudo
2 parents 060cb45 + 7728860 commit 07038e1

1 file changed

Lines changed: 12 additions & 10 deletions

File tree

pkgm.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ async function install(args: string[]) {
8282
})
8383
.spawn();
8484

85-
let status = await proc.status;
85+
const status = await proc.status;
8686

8787
if (!status.success) {
8888
Deno.exit(status.code);
@@ -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",
@@ -120,13 +121,14 @@ async function install(args: string[]) {
120121
"sudo-install",
121122
pkgx_dir,
122123
...to_install,
123-
],
124-
env,
125-
clearEnv: true,
126-
})
127-
.spawn().status;
128-
129-
Deno.exit(status.code);
124+
];
125+
const cmd = "/usr/bin/sudo";
126+
const status = await new Deno.Command(cmd, { args, env, clearEnv: true })
127+
.spawn().status;
128+
Deno.exit(status.code);
129+
} else {
130+
await sudo_install(pkgx_dir, to_install);
131+
}
130132
}
131133

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

0 commit comments

Comments
 (0)