jaemk/self_update


Self updates for rust executables

License: MIT

Language: Rust

Keywords: rust, rust-executables, update, upgrade


self_update

Build status Build Status crates.io:clin docs

self_update provides updaters for updating rust executables in-place from various release distribution backends.

Usage

Update (replace) the current executable with the latest release downloaded from https://api.github.com/repos/jaemk/self_update/releases/latest. Note, the trust project provides a nice setup for producing release-builds via CI (travis/appveyor).

Features

The following cargo features are available (but disabled by default):

  • archive-tar: Support for tar archive format;
  • archive-zip: Support for zip archive format;
  • compression-flate2: Support for gzip compression;
  • compression-zip-deflate: Support for zip's deflate compression format;
  • compression-zip-bzip2: Support for zip's bzip2 compression format;
  • rustls: Use pure rust TLS implementation for network requests. This feature does not support 32bit macOS;
  • signatures: Use zipsign to verify .zip and .tar.gz artifacts. Artifacts are assumed to have been signed using zipsign.

Please activate the feature(s) needed by your release files.

Example

Run the following example to see self_update in action:

cargo run --example github --features "archive-tar archive-zip compression-flate2 compression-zip-deflate".

There's also an equivalent example for gitlab:

cargo run --example gitlab --features "archive-tar archive-zip compression-flate2 compression-zip-deflate".

which runs something roughly equivalent to:

use self_update::cargo_crate_version;

fn update() -> Result<(), Box<::std::error::Error>> {
    let status = self_update::backends::github::Update::configure()
        .repo_owner("jaemk")
        .repo_name("self_update")
        .bin_name("github")
        .show_download_progress(true)
        .current_version(cargo_crate_version!())
        .build()?
        .update()?;
    println!("Update status: `{}`!", status.version());
    Ok(())
}

Amazon S3, Google GCS, and DigitalOcean Spaces are also supported through the S3 backend to check for new releases. Provided a bucket_name and asset_prefix string, self_update will look up all matching files using the following format as a convention for the filenames: [directory/]<asset name>-<semver>-<platform/target>.<extension>. Leading directories will be stripped from the file name allowing the use of subdirectories in the S3 bucket, and any file not matching the format, or not matching the provided prefix string, will be ignored.

use self_update::cargo_crate_version;

fn update() -> Result<(), Box<::std::error::Error>> {
    let status = self_update::backends::s3::Update::configure()
        .bucket_name("self_update_releases")
        .asset_prefix("something/self_update")
        .region("eu-west-2")
        .bin_name("self_update_example")
        .show_download_progress(true)
        .current_version(cargo_crate_version!())
        .build()?
        .update()?;
    println!("S3 Update status: `{}`!", status.version());
    Ok(())
}

Separate utilities are also exposed (NOTE: the following example requires the archive-tar feature, see the features section above). The self_replace crate is re-exported for convenience:

fn update() -> Result<(), Box<::std::error::Error>> {
    let releases = self_update::backends::github::ReleaseList::configure()
        .repo_owner("jaemk")
        .repo_name("self_update")
        .build()?
        .fetch()?;
    println!("found releases:");
    println!("{:#?}\n", releases);

    // get the first available release
    let asset = releases[0]
        .asset_for(&self_update::get_target()).unwrap();

    let tmp_dir = tempfile::Builder::new()
            .prefix("self_update")
            .tempdir_in(::std::env::current_dir()?)?;
    let tmp_tarball_path = tmp_dir.path().join(&asset.name);
    let tmp_tarball = ::std::fs::File::open(&tmp_tarball_path)?;

    self_update::Download::from_url(&asset.download_url)
        .set_header(reqwest::header::ACCEPT, "application/octet-stream".parse()?)
        .download_to(&tmp_tarball)?;

    let bin_name = std::path::PathBuf::from("self_update_bin");
    self_update::Extract::from_source(&tmp_tarball_path)
        .archive(self_update::ArchiveKind::Tar(Some(self_update::Compression::Gz)))
        .extract_file(&tmp_dir.path(), &bin_name)?;

    let new_exe = tmp_dir.path().join(bin_name);
    self_replace::self_replace(new_exe)?;

    Ok(())
}

License: MIT

Project Statistics

Sourcerank 13
Repository Size 259 KB
Stars 755
Forks 67
Watchers 7
Open issues 39
Dependencies 16
Contributors 26
Tags 5
Created
Last updated
Last pushed

Top Contributors See all

James Kominick Roey Darwish Dror Nicolas Bigaouette Joel Natividad Tobias Mansfield-Williams René Kijewski bochaco Alexandre Rebert ryan Michael Yang Oliver Bøving Sven joshuef Johnathan Lee Niklas Fiekas Jacob Kiers Terakomari Frosti Grétarsson Elliott Indiran Dervex

Packages Referencing this Repo

self_update
Self updates for standalone executables
Latest release 0.41.0 - Updated - 755 stars

Recent Tags See all

v9.9.10 November 16, 2018
v9.9.9 July 26, 2017
v0.1.100 July 25, 2017
v0.1.1 July 25, 2017
v0.1.0 July 25, 2017

Something wrong with this page? Make a suggestion

Last synced: 2024-07-03 03:20:04 UTC

Login to resync this repository