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.

shell self_update = "0.14"

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):

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

Example

```rust use selfupdate::cargocrate_version;

fn update() -> Result<(), Box<::std::error::Error>> { let status = selfupdate::backends::github::Update::configure() .repoowner("jaemk") .reponame("selfupdate") .binname("selfupdateexample") .showdownloadprogress(true) .currentversion(cargocrateversion!()) .build()? .update()?; println!("Update status: {}!", status.version()); Ok(()) } ```

Run the above example to see self_update in action: cargo run --example github --features "archive-tar compression-flate2"

Amazon S3 is also supported as the 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: <asset name>-<semver>-<platform/target>.<extension>. Any file not matching the format, or not matching the provided prefix string, will be ignored.

```rust use selfupdate::cargocrate_version;

fn update() -> Result<(), Box<::std::error::Error>> { let status = selfupdate::backends::s3::Update::configure() .bucketname("selfupdatereleases") .assetprefix("selfupdate") .region("eu-west-2") .binname("selfupdateexample") .showdownloadprogress(true) .currentversion(cargocrateversion!()) .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):

```rust fn update() -> Result<(), Box<::std::error::Error>> { let releases = selfupdate::backends::github::ReleaseList::configure() .repoowner("jaemk") .reponame("selfupdate") .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 = self_update::TempDir::new_in(::std::env::current_dir()?, "self_update")?;
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)
    .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 tmp_file = tmp_dir.path().join("replacement_tmp");
let bin_path = tmp_dir.path().join(bin_name);
self_update::Move::from_source(&bin_path)
    .replace_using_temp(&tmp_file)
    .to_dest(&::std::env::current_exe()?)?;

Ok(())

} ```

License: MIT