onepub-dev / dcli

An extensive library and tooling for building console/cli applications and scripts using the Dart programming language.
242 stars 28 forks source link

Don't use sudo unnecessarily #131

Closed Timmmm closed 3 years ago

Timmmm commented 3 years ago

When you do dcli install on Mac it randomly asks you for a password (there should at least be a prompt to tell you which password and why it needs it). If you cancel it then it turns out it is running a command as sudo that definitely doesn't need to be sudo:

The command [sudo] with args [ln, -sf, /Users/tim/.pub-cache/bin/dcli, /Users/tim/local/flutter/bin/dcli] failed with exitCode: 1

To Reproduce Follow the installation instructions on Mac.

Logs

 ~ dart pub global activate dcli
Resolving dependencies... (1.5s)
+ archive 3.1.2
+ args 2.0.0
+ async 2.5.0
+ basic_utils 3.0.2
+ charcode 1.2.0
+ collection 1.15.0
+ crypto 3.0.1
+ csv 5.0.0
+ dcli 1.0.2
+ equatable 2.0.0
+ ffi 1.0.0
+ file 6.1.0
+ glob 2.0.1
+ http 0.13.1
+ http_parser 4.0.0
+ ini 2.1.0
+ json_annotation 4.0.1
+ logging 1.0.1
+ matcher 0.12.10
+ meta 1.3.0
+ path 1.8.0
+ pedantic 1.11.0
+ pointycastle 3.0.1
+ posix 2.0.0
+ pub_semver 2.0.0
+ pubspec 2.0.1
+ quiver 3.0.1
+ random_string 2.2.0-nullsafety
+ source_span 1.8.1
+ stack_trace 1.10.0
+ string_scanner 1.1.0
+ term_glyph 1.2.0
+ typed_data 1.3.0
+ uri 1.0.0
+ uuid 3.0.4
+ validators2 3.0.0
+ vin_decoder 0.2.0-nullsafety
+ yaml 3.1.0
Downloading dcli 1.0.2...
Downloading validators2 3.0.0...
Downloading pub_semver 2.0.0...
Downloading posix 2.0.0...
Downloading ini 2.1.0...
Downloading equatable 2.0.0...
Downloading csv 5.0.0...
Downloading vin_decoder 0.2.0-nullsafety...
Downloading random_string 2.2.0-nullsafety...
Downloading yaml 3.1.0...
Downloading pubspec 2.0.1...
Downloading uri 1.0.0...
Downloading glob 2.0.1...
Downloading quiver 3.0.1...
Downloading archive 3.1.2...
Downloading crypto 3.0.1...
Downloading uuid 3.0.4...
Downloading basic_utils 3.0.2...
Downloading pointycastle 3.0.1...
Downloading json_annotation 4.0.1...
Precompiling executables... (7.9s)
Precompiled dcli:dcli_complete.
Precompiled dcli:dshell_upgrade.
Precompiled dcli:dcli_install.
Precompiled dcli:dcli.
Installed executables dcli, dcli_complete, dcli_install and dshell_upgrade.
Activated dcli 1.0.2.
 ~ dcli install
Hang on a tick whilst we install DCli 1.0.2

Package dcli is currently active at version 1.0.2.
Resolving dependencies... (1.3s)
The package dcli is already activated at newest available version.
To recompile executables, first run `global decativate dcli`.
Installed executables dcli, dcli_complete, dcli_install and dshell_upgrade.
Activated dcli 1.0.2.
Creating /Users/tim/.dcli

Creating Template directory in: /Users/tim/.dcli/templates.

Creating Cache directory in: /Users/tim/.dcli/cache.

Creating bin directory in: /Users/tim/.dcli/bin.
If you want to use dcli compile -i to install scripts, add /Users/tim/.dcli/bin to your PATH.

dcli found in : /Users/tim/.pub-cache/bin/dcli.
Password:
Sorry, try again.
Password:
Sorry, try again.
Password:
sudo: 3 incorrect password attempts
RunException: sudo ln -sf /Users/tim/.pub-cache/bin/dcli /Users/tim/local/flutter/bin/dcli
exit: 1
reason: The command [sudo] with args [ln, -sf, /Users/tim/.pub-cache/bin/dcli, /Users/tim/local/flutter/bin/dcli] failed with exitCode: 1
Stacktrace: wait_for_ex.dart : waitForEx : 47
runnable_process.dart : RunnableProcess.processUntilExit : 408
runnable_process.dart : RunnableProcess.run : 161
run.dart : start : 227
string_as_process.dart : StringAsProcess.start : 182
install.dart : InstallCommand.symlinkDCli : 224
install.dart : InstallCommand.run : 178
command_line_runner.dart : CommandLineRunner.process : 87
entry_point.dart : EntryPoint._parseCmdLine : 36
entry_point.dart : EntryPoint.process : 31

Run dcli doctor: From the cli run dcli doctor

DCli version      1.0.2

OS                macos
OS Version        10.16
path separator    /

dart version      2.13.0

dcli path         /<HOME>/.pub-cache/bin/dcli
dart exe path     /<HOME>/local/flutter/bin/dart
dart path         /<HOME>/local/flutter/bin/dart                          which: /<HOME>/local/flutter/bin/dart
compiler          using 'dart compile exe'

pub               using 'dart pub'

package Config    not passed

PATH
                  /<HOME>/.pyenv/plugins/pyenv-virtualenv/shims
                  /<HOME>/.pyenv/shims
                  /<HOME>/.pyenv/bin
                  /<HOME>/.gem/ruby/2.6.0/bin
                  /<HOME>/.pub-cache/bin
                  /<HOME>/local/flutter/bin
                  /<HOME>/Qt/5.15.2/clang_64/bin
                  /<HOME>/Library/Python/3.8/bin
                  /usr/local/opt/node@10/bin
                  /<HOME>/go/bin
                  /<HOME>/local/arcanist/bin
                  /<HOME>/local/aarch64-linux-musl-cross/bin
                  /<HOME>/local/x86_64-linux-musl-cross/bin
                  /<HOME>/.cargo/bin
                  /usr/local/bin
                  /usr/bin
                  /bin
                  /usr/sbin
                  /sbin
                  /Library/TeX/texbin
                  /Library/Apple/usr/bin
                  /Library/Frameworks/Mono.framework/Versions/Current/Com

$SHELL            /bin/zsh
detected SHELL    zsh
Shell Start Scrip not found

dart location(s)
                  /Users/tim/local/flutter/bin/dart

permissions
HOME              rwxr-xr-x <user>: /<HOME>
.dcli             rwxr-xr-x <user>:tim /<HOME>/.dcli
cache             rwxr-xr-x <user>:tim /<HOME>/.dcli/cache
templates         rwxr-xr-x <user>:tim /<HOME>/.dcli/templates
bsutton commented 3 years ago

The sudo permission is required depending on where dart is installed. Under linux if you use the apt package installer then dart gets installed into /usr/bin which does require sudo.

I suspect on the mac there may be some install paths that do require sudo access as well.

So there are a couple of options. 1) do a better job in making the user aware that we are going to ask for the sudo password. 2) do better checks to see if sudo is required. 3) force the user to start the install with sudo so we remove the confusion.

Thoughts?

Timmmm commented 3 years ago

Yeah I would try and detect if the destination directory is writable but the current user, and if not then print a message Running: sudo ln ... \nPlease enter your password or something like that.

An alternative is just to run the command and grep for Permission denied or whatever it says in the output, but that seems more fragile and janky.

bsutton commented 3 years ago

These changes are in the latest release.

We now do additional checks on whether sudo is required. When we prompt for sudo we make it more obvious.

If you have further problems on this issue please feel free to re-open the issue.