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

Automate downloading Linux binaries #3029

Open
wycats opened this issue Feb 8, 2021 · 9 comments
Open

Automate downloading Linux binaries #3029

wycats opened this issue Feb 8, 2021 · 9 comments

Comments

@wycats
Copy link
Collaborator

@wycats wycats commented Feb 8, 2021

Is your feature request related to a problem? Please describe.

Today, we make it very easy to get the binaries onto a Mac machine, but the same is not true about Linux. Instead, the Linux instructions ask the user to manually download the binaries from release and put them in an appropriate location. Speaking for myself, this is an annoying, somewhat error-prone process, and it tends to cause me to delay doing upgrades.

Describe the solution you'd like

Automate the process of downloading the binaries from the releases tab and copying them into ~/.local/bin.

The main wrinkle is that updating a binary that is currently used as the shell doesn't "just work", and we need to find a solution to make that possible.

One possibility is to copy the binaries into ~/.local/share/nu. The next time nushell boots, if any binaries are found in ~/.local/share/nu, exec a process that copies them into ~/.local/bin, and then exec the new nu binary. There may be other canonical solutions to this problem, and we should of course use a canonical solution if one exists.

Ideally, nushell would know how to update itself in the background, so that you wouldn't have to do anything other than use nu as usual to get the updates.

Describe alternatives you've considered

  1. Don't do anything and continue to give people the current instructions. Speaking for myself, this is not the best we can do.
  2. Integrate with Linux package managers. This might be a more optimal solution, but I'm thinking that the solution given in this issue would be easier to implement in the near term. Also, having nu auto-update itself is pretty nice.
@fdncred
Copy link
Collaborator

@fdncred fdncred commented Feb 8, 2021

I did a quick look around and found these.
Self_Update <-- been around a while, still receiving commits
updater-lp <-- archived

@wycats
Copy link
Collaborator Author

@wycats wycats commented Feb 8, 2021

@fdncred how would Self_Update handle the "updating the live shell in place" issue?

@fdncred
Copy link
Collaborator

@fdncred fdncred commented Feb 8, 2021

@wycats I haven't looked into it enough to know. These links are just starting points. More research is required. But I figure it would work like updating any other process that is in use.

On Linux/Mac one could probably use exec since it takes over a process somehow, although I don't know if self_update could do that. On Windows, it would have to be more radical like nu -c "ps | where name == 'nu.exe' | each { kill -f $it.pid }" but that could run into problems if user doesn't have permission.

@fdncred
Copy link
Collaborator

@fdncred fdncred commented Feb 8, 2021

very interesting. found here.

#[cfg(unix)]
fn restart_process(current_exe: PathBuf, logger: &Logger) {
    use std::os::unix::process::CommandExt as _;
    logger.headline(&format!("Waiting 5s before restarting {:?} ...", current_exe));
    thread::sleep(Duration::from_secs(5));
    let err = std::process::Command::new(current_exe)
        .args(std::env::args().into_iter().skip(1))
        .exec();
    panic!("Failed to restart: {}", err);
}
@wycats
Copy link
Collaborator Author

@wycats wycats commented Feb 9, 2021

@fdncred great job digging into this!

@wycats
Copy link
Collaborator Author

@wycats wycats commented Feb 16, 2021

While we're trying to figure out self-updating, could we create a curl | sh installer for the meantime?

@fdncred
Copy link
Collaborator

@fdncred fdncred commented Feb 16, 2021

Here's a start to a nushell script that could work. If fetch would follow redirects this would be easier.

def get-latest [] {
    let metadata = $(fetch https://api.github.com/repos/nushell/nushell/releases/latest)
    let release_name = $(echo $metadata | get name | split row ' ' | nth 0)
    let body = $(echo $metadata | get body)
    let asset_info = $(echo $metadata | get assets | where name =~ 'linux.tar.gz')
    let download_url = $(echo $asset_info | get browser_download_url)
    let file_name = $(echo $asset_info | get name)
    echo $(build-string "Release name is " $release_name $(char newline) $(char newline))
    echo $(build-string $body $(char newline) $(char newline) "Downloading...")
    let redirected_url = $(fetch $download_url --raw)
    let real_download_url = $(echo $redirected_url | xpath '//@href' | get '//@href')
    fetch $real_download_url | save $file_name
    # Remaining to do
    # tar xf $file_name
    # parse the $file_name to get the folder like going
    # from: nu_0_27_0_linux.tar.gz
    # to: nu_0_27_0_linux
    # cp nu_0_27_0_linux/nushell-0.27.0/* ~/.cargo/bin
    # exec ~/.cargo/bin/nu
}
@wycats
Copy link
Collaborator Author

@wycats wycats commented Feb 25, 2021

A different (but not competing) idea: how hard would it be to get nushell on Linux homebrew?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants