File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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
132134async function sudo_install ( pkgx_dir : string , pkg_prefixes : string [ ] ) {
You can’t perform that action at this time.
0 commit comments