Skip to content

Commit

Permalink
self-update: enable zipsign signature verification (#987)
Browse files Browse the repository at this point in the history
Fixes #980
  • Loading branch information
jdx authored Nov 9, 2023
1 parent 7c2e258 commit 9084a69
Showing 1 changed file with 40 additions and 24 deletions.
64 changes: 40 additions & 24 deletions src/cli/self_update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use color_eyre::Result;
use console::style;

use self_update::backends::github::{ReleaseList, Update};
use self_update::cargo_crate_version;
use self_update::update::Release;
use self_update::{cargo_crate_version, Status};

use crate::cli::command::Command;
use crate::cli::version::{ARCH, OS};
Expand All @@ -20,41 +21,56 @@ use crate::output::Output;
pub struct SelfUpdate {}

impl Command for SelfUpdate {
fn run(self, _config: Config, out: &mut Output) -> Result<()> {
let current_version =
env::var("RTX_SELF_UPDATE_VERSION").unwrap_or(cargo_crate_version!().to_string());
let target = format!("{}-{}", *OS, *ARCH);
fn run(self, config: Config, out: &mut Output) -> Result<()> {
let latest = &self.fetch_releases()?[0].version;
let status = self.do_update(&config, latest)?;

if status.updated() {
let version = style(status.version()).bright().yellow();
rtxprintln!(out, "Updated rtx to {version}");
} else {
rtxprintln!(out, "rtx is already up to date");
}

Ok(())
}
}

impl SelfUpdate {
fn fetch_releases(&self) -> Result<Vec<Release>> {
let mut releases = ReleaseList::configure();
releases.repo_owner("jdx").repo_name("rtx");
if let Some(token) = &*env::GITHUB_API_TOKEN {
releases.auth_token(token);
}
let releases = releases.build()?.fetch()?;
let latest = &releases[0].version;
let releases = releases
.repo_owner("jdx")
.repo_name("rtx")
.build()?
.fetch()?;
Ok(releases)
}

fn do_update(&self, config: &Config, latest: &str) -> Result<Status> {
let current_version =
env::var("RTX_SELF_UPDATE_VERSION").unwrap_or(cargo_crate_version!().to_string());
let target = format!("{}-{}", *OS, *ARCH);
let mut update = Update::configure();
update
if let Some(token) = &*env::GITHUB_API_TOKEN {
update.auth_token(token);
}
let status = update
.repo_owner("jdx")
.repo_name("rtx")
.bin_name("rtx")
// TODO: enable if working locally
//.verifying_keys([*include_bytes!("../../zipsign.pub")])
.verifying_keys([*include_bytes!("../../zipsign.pub")])
.show_download_progress(true)
.current_version(&current_version)
.target(&target)
.bin_path_in_archive("rtx/bin/rtx")
.identifier(&format!("rtx-v{latest}-{target}.tar.gz"));
if let Some(token) = &*env::GITHUB_API_TOKEN {
update.auth_token(token);
}
let status = update.build()?.update()?;
if status.updated() {
let version = style(status.version()).bright().yellow();
rtxprintln!(out, "Updated rtx to {version}");
} else {
rtxprintln!(out, "rtx is already up to date");
}

Ok(())
.identifier(&format!("rtx-v{latest}-{target}.tar.gz"))
.no_confirm(config.settings.yes)
.build()?
.update()?;
Ok(status)
}
}

0 comments on commit 9084a69

Please sign in to comment.