topgrade-rs / topgrade

Upgrade all the things
GNU General Public License v3.0
1.9k stars 123 forks source link

Add bun sudo option? bun doesnt upgrade without it if installed on /usr/bin(from aur) #892

Open littleblack111 opened 2 weeks ago

littleblack111 commented 2 weeks ago

Erroneous Behavior

bun upgrade not working

Expected Behavior

bun upgraded

Steps to reproduce

install bun-bin from the aur then use topgrade 2 update

Possible Cause (Optional)

no sudo access

Problem persists without calling from topgrade

Did you run topgrade through Remote Execution

If yes, does the issue still occur when you run topgrade directlly in your remote host

Configuration file (Optional)

YES WE NEED 2 ADD A use_sudo like npm

Additional Details

littleblack111 commented 2 weeks ago

dude wat?! dont download it guys. kinda sketchy

SteveLauC commented 2 weeks ago

is that comment a spam comment🤔

SteveLauC commented 2 weeks ago

bun update is the official command to update it, will you get an error if you simply do it in the terminal:

$ bun upgrade
littleblack111 commented 2 weeks ago

ye and if its installed on /usr/bin then that would need SU to update

SteveLauC commented 2 weeks ago

I think Topgrade should only invoke the bun upgrade command if bun is installed through the official script, from the script (install.sh), on UNIX, bun will be installed under $BUN_INSTALL, which defaults to ~/.bun.

install_env=BUN_INSTALL
bin_env=\$$install_env/bin

install_dir=${!install_env:-$HOME/.bun}
bin_dir=$install_dir/bin
exe=$bin_dir/bun

And it looks the Windows script (install.ps1) also follows this convention:

  $BunRoot = if ($env:BUN_INSTALL) { $env:BUN_INSTALL } else { "${Home}\.bun" }
  $BunBin = mkdir -Force "${BunRoot}\bin"

Let me give this a fix.

littleblack111 commented 2 weeks ago

Pretty fair. But if it just add the use_sudo option. both will work. just user that got it installed on /usr/bin need to edit the configuration.

SteveLauC commented 2 weeks ago

But if it just add the use_sudo option.

We should avoid this if possible as unexpected conflicts may happen.

Screenshot 2024-08-26 at 11 07 48 PM

894 should fix this issue.

SteveLauC commented 2 weeks ago

Here is a build for Linux, welcome to give it a test.

https://github.com/SteveLauC/topgrade/releases/tag/pr894

SteveLauC commented 2 weeks ago

Here is a build for Linux, welcome to give it a test.

https://github.com/SteveLauC/topgrade/releases/tag/pr894

Gentle ping again.

dotfrag commented 2 weeks ago

Please do not do this, bun should only be upgraded from the method used to install, i.e. package manager if AUR.

Thanks for the PR, I'm not OP but I'll try to give this a go today.

dotfrag commented 2 weeks ago

Hi again, I'm currently on a machine with bun with official install script, and it's not working. I don't know rust but looking at the code it seems to check for ~/.bun? This might be tricky, as I've changed the install dir to ~/.local/share/bun.

SteveLauC commented 2 weeks ago

the code it seems to check for ~/.bun?

That is the default installation path, one can customize it via the environment variable BUN_INSTALL.

I've changed the install dir to ~/.local/share/bun.

Did you do it through that env var?

SteveLauC commented 2 weeks ago

BTW, mind giving me the output of:

$ topgrade --only bun --verbose
dotfrag commented 2 weeks ago

I did use the var, but only passed it to bash during installation. I've now exported the var in my shell profile and it's working!

I can only test the aur install when I'm on my arch machine later today, but judging from the behavior, it should work as expected, i.e. not try to upgrade.

Thanks Steve.

Update: for the output you asked, sorry no, because I'm on a business machine with restricted access. I'm typing from my phone.

I do however see:

Step bun Detected home.local.share.bun.bin.bun

Executing command ..bun upgrade

If I unset the var, it says Bun not installed through the official script, skipping..

Sorry for the formatting.

SteveLauC commented 2 weeks ago

but only passed it to bash during installation.

Wait, bun update can still work normally without that environment variable? Ah, this makes things hard, I have no idea how I can check if an installation is done through the official script in this case...

Update: for the output you asked, sorry no, because I'm on a business machine with restricted access. I'm typing from my phone.

Thanks for the manually typed output, it still helps a lot!

dotfrag commented 2 weeks ago

Yes it does, because, and this is only my assumption, it doesn't care about the env var, it knows where it's located from the binary itself. Even if you were to move it to /tmp and run it from there it would still work.

Maybe you could check install dir, i.e /usr/ vs ~/ but of course this is unreliable, as a user might have chosen to manually install to something like .usr.local.bin

SteveLauC commented 2 weeks ago

it doesn't care about the env var, it knows where it's located from the binary itself.

Yeah, that is also my guess.

Maybe you could check install dir, i.e /usr/ vs ~/ but of course this is unreliable, as a user might have chosen to manually install to something like .usr.local.bin

Perhaps I should file an issue in the Bun repo to seek some help.

SteveLauC commented 2 weeks ago

Perhaps I should file an issue in the Bun repo to seek some help.

filed: https://github.com/oven-sh/bun/discussions/13605

dotfrag commented 1 week ago

Thanks. FWIW, I tested it on my arch system and it's working.

bun: SKIPPED: Bun is not installed through the official script, skip the update
SteveLauC commented 1 week ago

I tested it on my arch system and it's working.

Thanks for testing it!