marcosnils / bin

Effortless binary manager
MIT License
648 stars 45 forks source link

Fix init on failure to find PATH automatically #114

Closed darkowlzz closed 2 years ago

darkowlzz commented 2 years ago

Downloaded bin on a new machine and encountered the following behavior, with debug:

$ bin --debug
   • debug logs enabled
   • Config directory is: /home/ubuntu/.config/bin
   • User PATH is [/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin]
   • Checking path /usr/local/sbin
   • Error [permission denied] checking path
   • Checking path /usr/local/bin
   • Error [permission denied] checking path
   • Checking path /usr/sbin
   • Error [permission denied] checking path
   • Checking path /usr/bin
   • Error [permission denied] checking path
   • Checking path /sbin
   • Error [permission denied] checking path
   • Checking path /bin
   • Error [permission denied] checking path
   • Checking path /usr/games
   • Error [permission denied] checking path
   • Checking path /usr/local/games
   • Error [permission denied] checking path
   • Checking path /snap/bin
   • Error [permission denied] checking path
   • Could not find a PATH directory automatically, falling back to manual selection

Please specify a download directory: /home/ubuntu/.bin
   • Could not find a PATH directory automatically, falling back to manual selection

Please specify a download directory: /home/ubuntu/Downloads
   • Could not set download directory [/home/ubuntu/Downloads
]: [Error setting download path [stat /home/ubuntu/Downloads: no such file or directory]]
   • Could not find a PATH directory automatically, falling back to manual selection

Please specify a download directory: /home/ubuntu/go
   • Could not find a PATH directory automatically, falling back to manual selection

It enters a loop and never comes out of it. This change adds a break statement to help break out of the loop.

$ bin
Please specify a download directory: /home/ubuntu/.bin
   • Download path set to /home/ubuntu/.bin

 Path   Version         URL     Status

After fixing the above, encountered an issue when trying to install a binary:

$ bin install github.com/fluxcd/flux2
   • Getting latest release for fluxcd/flux2
   • Starting download of https://github.com/fluxcd/flux2/releases/download/v0.23.0/flux_0.23.0_linux_arm64.tar.gz
11.45 MiB / 11.45 MiB [---------------------------------------------------------------------------------------------------------------------------------------------------] 100.00% 3.86 MiB p/s 3s

   ⨯ command failed            error=Error installing binary: open /home/ubuntu/.bin
: file exists

Checked the bin config to find a white space in the default_path:

$ cat ~/.config/bin/config.json
{
    "default_path": "/home/ubuntu/.bin\n",
    "bins": {}
}

Removing the newline from default_path made the binary installation above to succeed and list the installed binary:

$ bin

 Path                           Version         URL                             Status
 /home/ubuntu/.bin/flux         v0.23.0         github.com/fluxcd/flux2         OK

Updated the loop that takes the input PATH to trim whitespace before using it and that fixed all the problems.

marcosnils commented 2 years ago

thanks for the contribution! crafting a release with the fix in a minute!

darkowlzz commented 2 years ago

thanks for the contribution! crafting a release with the fix in a minute!

Great! Thanks, will update and use the new version.

marcosnils commented 2 years ago

:ship: thx again!