Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for installing binaries #1413

Closed
wants to merge 4 commits into from

Conversation

crodjer
Copy link

@crodjer crodjer commented Nov 27, 2023

As noted in a existing TODO, this installs the atuin binary directly at /usr/local/bin for operating systems that don't have an official method. For example: Raspberry Pi / MacOS (without homebrew).

Steps:

  1. Get latest release info to find out the version.
  2. Get the release archive and extract it to a temporary directory.
  3. Move the atuin binary to PATH.

This is based on the installation script
for sysit - a small utility I made.

Also, add support for custom binary installation path. It can be an additional argument to the install command. For instance:

INSTALL_DIR=~/.local/bin bash <(curl https://raw.githubusercontent.com/ellie/atuin/main/install.sh)

to install the binary in ~/.local/bin

Copy link

vercel bot commented Nov 27, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
atuin-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Dec 24, 2023 7:29am

Copy link
Member

@ellie ellie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Just a couple of comments

install.sh Outdated
local arch=$(uname -sm)
local bin_dir=/usr/local/bin

# todo: Can make it an optional argument to install script as well,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could we do this now? would be really great to have!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, that's something I can add. I had it in the patch but wasn't sure if it is okay to change the interface for the script.

install.sh Outdated
local binary_url="https://github.com/atuinsh/atuin/releases/download/v17.0.1/$archive_name.tar.gz"
download_dir=$(mktemp -d)
curl -s -L $binary_url | tar -xz -C $download_dir -f -
sudo mkdir -p $bin_dir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be good to

  1. Let the user know what's going on (eg tell them we couldn't find anything + will install a binary from releases)
  2. Tell them where it's being installed, and ask for y/n to go ahead

I don't think we should go putting files in the users filesystem without getting their confirmation that is OK, especially when they'll be getting a sudo prompt without explanation

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

True. I think I can add logging here, with a prompt.

@crodjer
Copy link
Author

crodjer commented Nov 29, 2023

@ellie, made the suggested changes.

@crodjer
Copy link
Author

crodjer commented Dec 6, 2023

@ellie did you get a chance to look at it?

Copy link
Member

@ellie ellie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a couple more things

install.sh Outdated
@@ -34,6 +34,8 @@ LATEST_RELEASE=$(curl -L -s -H 'Accept: application/json' https://github.com/atu
# Allow sed; sometimes it's more readable than ${variable//search/replace}
# shellcheck disable=SC2001
LATEST_VERSION=$(echo "$LATEST_RELEASE" | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/')
# For binary install, use the first argument as the installation directory.
INSTALL_DIRECTORY=${1:-/usr/local/bin}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd really rather we just made this an env var input. That way we don't change the interface at all, but still allow customization.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense.

install.sh Outdated

local latest_version=$(curl -s https://api.github.com/repos/atuinsh/atuin/releases/latest | grep tag_name | grep -Eo "v[0-9]+\.[0-9]+\.[0-9]+")
local archive_name=atuin-$latest_version-$target
local binary_url="https://github.com/atuinsh/atuin/releases/download/v17.0.1/$archive_name.tar.gz"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hardcodes v17.0.1

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made a few updates for the review, shellcheck and a small fix for darwin's stat utility.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ellie , did you get a chance to see the changes?

As noted in a existing TODO, this installs the `atuin` binary directly
at `/usr/local/bin` for operating systems that don't have an official
method. For example: Raspberry Pi / MacOS (without homebrew).

Steps:
1. Get latest release info to find out the version.
2. Get the release archive and extract it to a temporary directory.
3. Move the `atuin` binary to PATH.

> This is based on the [installation script](https://github.com/crodjer/sysit/blob/main/scripts/install.sh)
> for `sysit` - a small utility I made.
The optional first argument to the installer can specify the install
directory other than `/usr/local/bin`.
- Don't change installation interface, use `INSTALL_DIR` instead.
- Fix all the shellcheck errors.
- Remove the hard coded 17.0.1
- Fix `stat` usage for `darwin`
@ellie
Copy link
Member

ellie commented Dec 23, 2023

@crodjer looks like the prompt I mentioned in a previous review isn't here?

I think it would be good to

Let the user know what's going on (eg tell them we couldn't find anything + will install a binary from releases)
Tell them where it's being installed, and ask for y/n to go ahead

I really don't want to go installing files on the users system without confirmation. It would be good to tell them what files are going to be downloaded where, and also explain how they can change that.

Also - the real fix for Ubuntu is to also build a deb for aarch64 and install with the proper tooling, not to install a binary manually. This should be a last resort.

For scripting usage (say ansible playbooks), setting ATUIN_NO_PROMPT
will ensure no prompt is shown.
@crodjer
Copy link
Author

crodjer commented Dec 24, 2023

looks like the prompt I mentioned in a previous review isn't here?

@ellie Yes, I figured we could rely on the sudo call. But you are right, users may miss out on seeing the prompt if sudo authorization is cached. So, added an explicit prompt as well. It'll behave like this:

Will copy atuin binary to /usr/local/bin...
Okay? [Y/n]: Y
Downloading atuin v17.1.0 from the latest github release...
Copying atuin binary to /usr/local/bin ...

I didn't want an explicit prompt because it'll then affect my scripts. For that, I have added another environment variable: ATUIN_NO_PROMPT. My goal toward having a binary install support was primarily to ensure my automation works on all my machines.

@ellie
Copy link
Member

ellie commented Feb 26, 2024

Longer term, I think the approach for installing binaries should be one of the following

  1. Use the users' package manager wherever possible
  2. Fallback to installing a binary to ~/.atuin or similar, request the user add to PATH
  3. Provide instructions for manual install to /usr/local/bin, ~/.local/bin, etc. These paths differ across distributions, platforms, and individual setups.

I am generally quite against automatically installing to known binary paths. This is the job of a package manager, and there are almost certainly many edge cases we have not considered. This can also conflict with existing package managers and other installs, which is not something we want.

Especially in the case of /usr/local/bin, I'd rather avoid calling sudo (unless it's needed to call a package manager).

My goal toward having a binary install support was primarily to ensure my automation works on all my machines.

For this specific case, you should be able to use ansible/saltstack/etc to automate a manual binary install.

@ellie ellie closed this Feb 26, 2024
@crodjer
Copy link
Author

crodjer commented Mar 1, 2024

I understand. Lately I haven't been using atuin, so I didn't ping further for review.

I discovered https://github.com/cargo-bins/cargo-binstall, so cargo binstall atuin should be able to serve a similar use-case.
You might consider adding that as an option to the doc.

@crodjer crodjer deleted the binary-installer branch March 1, 2024 18:15
@crodjer crodjer restored the binary-installer branch March 1, 2024 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants