devmatteini / dra

A command line tool to download release assets from GitHub
MIT License
185 stars 8 forks source link

Feature: Prevent downloading and installing already installed tools via `--version` #207

Open sandreas opened 4 months ago

sandreas commented 4 months ago

Hello,

sorry to bother you again, I really like this tool and had another idea of improving.

Since I'm using dra in a script to install all my tools, it would be really great, if I could make dra prevent downloading and installing a version lower or equal the already installed version.

Example:

# dra download -a --install --output /home/andreas/bin/ --version=0.16.5 restic/restic
dra download -a --install --output "$HOME/bin/" --version="$(restic version | cut -d ' ' -f 2)" restic/restic

This will skip any download or installation of version lower than equal 0.16.5 (the currently installed one).

Hope you like it.

devmatteini commented 1 month ago

Hi @sandreas! Sorry for the late answer but forgot about this issue 😅

I don't see this feature as needed. Are there scenarios where this feature would avoid you download an older version?

By default dra downloads the latest release which prevents this issue.

If you use the --tag option you are specifing which release you want.

The only improvement I see is that it would avoid downloading the same asset if the min version match the current one.

I'm open to discussion if you are still interested 🙂

sandreas commented 1 month ago

The only improvement I see is that it would avoid downloading the same asset if the min version match the current one.

Exactly this is the point. dra always starts a download, even if the tool is already installed in the same version. So if I write a shell script telling dra to download and install my tools, it is either slow (because of the additional downloads) or I have to workaround it with command -v $tool || dra download ....

Now the problem is, if I use command -v $tool || dra download ..., it does not check the installed version, but only if the tool is there - this means: no updates. Version compares in shell are possible, but adding a simple param to dra would make the script way cleaner.

devmatteini commented 1 month ago

I understand your point, but I'm not sure if this is something dra should handle.

I'll think about it.

sandreas commented 1 month ago

I understand your point, but I'm not sure if this is something dra should handle.

You may be correct. Here are my thoughts:

So the only thing I could come up with was providing the --installed-version manually, and if this is equal the remote version, just don't do anything, until --force--reinstall (or something like this) is provided.

devmatteini commented 1 month ago

These all make sense, but still not sure.

An alternative implementation could be using a new subcommand:

dra outdated --current-version 0.6.3 devmatteini/dra
# If current version is outdated, then exit code is 1
# If current version is NOT outdated, then exit code is 0

and you can combine it in your scripts like

dra outdated --current-version 0.6.3 devmatteini/dra || dra download -a -i devmatteini/dra

Of course, it would be much easier with only an option in dra download such as you suggested.

sandreas commented 1 month ago

Of course, it would be much easier with only an option in dra download such as you suggested.

I'm not willing to FORCE you to do anything, basically I think you did more than enough - thank you for that :-)

If you think, it's too much, just skip it. I'd also take the extra subcommand, whatever works.

My use case is pretty straight forward. I have a simple script paired with a text file to install all my tools (install-shell-tools.sh + install-shell-tools.txt) while the txt file looks like the example below. Now I basically have 2 problems: How I keep the tools up to date and how do I setup the tools without having to script every single one of them with wget / curl.

dra does an excellent job regarding the second use case (setup tools) - the update problem currently is a minor thing, where i provide a --force-reinstall to my script just reinstalling all of them. Now and then I just run it with --force-reinstall to update them all, but since a few tools are pretty big (> 50MB) this takes pretty long.

# bat - modern cat replacement
sharkdp/bat

# btop - process explorer
aristocratos/btop

# difftastic - better diff
difft;Wilfred/difftastic

# eza - modern ls replacement
eza-community/eza

# fd - find replacement
sharkdp/fd

# fzf - fuzzy finder
junegunn/fzf

# gdu - disk usage analyzer similar to ncdu but faster
dundee/gdu

# ...
devmatteini commented 1 month ago

I'm not willing to FORCE you to do anything, basically I think you did more than enough - thank you for that :-)

Sure, that's not what I meant, and I didn't feel any pressure from you, in fact it was an interesting discussion :smile:

It's always nice to see that a tool I created is helping other people solve similar problems!

My use case is pretty straight forward

Let me share how I use dra, since I have a different approach: Each tool I install is a single script (whether it uses dra or a package manager like apt). You can see it in my dotfiles here: https://github.com/devmatteini/dotfiles/tree/main/packages.

When I need to install or update a tool, I run its script, but I rarely perform a batch update of tools. In the past, I had a setup similar to yours, but it never fully convinced me.

If you think, it's too much, just skip it.

Avoiding downloading the version already installed would definitely be a great feature. I would say that it could even be the default behavior, with a --force flag to bypass it if needed.

I just need to see/think if it's possible to implement, otherwise the --min-version 1.1.3 option is a good solution with slightly worse UX.