Expand description
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.zipand.tar.gzartifacts. 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_github_update_enhanced::cargo_crate_version;
*
* fn update() -> Result<(), Box<dyn ::std::error::Error>> {
* let status = self_github_update_enhanced::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(())
* }
* ```
Separate utilities are also exposed (**NOTE**: the following example _requires_ the `archive-tar` feature,
see the [features](#features) section above). The `self_replace` crate is re-exported for convenience:
```rust
fn update() -> Result<(), Box<::std::error::Error>> {
let releases = self_github_update_enhanced::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(())
}Re-exports§
pub use self_replace;
Modules§
- Collection of modules supporting various release distribution backends
- Error type, conversions, and macros
- Semver version checks
Macros§
- Allows you to pull the version from your Cargo.toml at compile time as
MAJOR.MINOR.PATCH_PKGVERSION_PRE
Structs§
- Download things into files
- Extract contents of an encoded archive (e.g. tar.gz) file to a specified directory
- Moves a file from the given path to the specified destination.
- A directory in the filesystem that is automatically deleted when it goes out of scope.
Enums§
- Supported archive formats
- Status returned after updating
Constants§
Functions§
- Get the current target triple.
- should_updateDeprecatedCheck if a version tag is greater than the current