|
|
@ -34,6 +34,31 @@ use crate::{
|
|
|
|
|
|
|
|
|
|
|
|
const UPDATER_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
|
|
|
|
const UPDATER_USER_AGENT: &str = concat!(env!("CARGO_PKG_NAME"), "/", env!("CARGO_PKG_VERSION"),);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Clone)]
|
|
|
|
|
|
|
|
pub enum Installer {
|
|
|
|
|
|
|
|
AppImage,
|
|
|
|
|
|
|
|
Deb,
|
|
|
|
|
|
|
|
Rpm,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
App,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Msi,
|
|
|
|
|
|
|
|
Nsis,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Installer{
|
|
|
|
|
|
|
|
fn suffix(self) -> &'static str {
|
|
|
|
|
|
|
|
match self {
|
|
|
|
|
|
|
|
Self::AppImage => "appimage",
|
|
|
|
|
|
|
|
Self::Deb => "deb",
|
|
|
|
|
|
|
|
Self::Rpm => "rpm",
|
|
|
|
|
|
|
|
Self::App => "app",
|
|
|
|
|
|
|
|
Self::Msi => "msi",
|
|
|
|
|
|
|
|
Self::Nsis => "nsis",
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
|
|
|
#[derive(Debug, Deserialize, Serialize, Clone)]
|
|
|
|
pub struct ReleaseManifestPlatform {
|
|
|
|
pub struct ReleaseManifestPlatform {
|
|
|
|
/// Download URL for the platform
|
|
|
|
/// Download URL for the platform
|
|
|
@ -68,28 +93,32 @@ pub struct RemoteRelease {
|
|
|
|
|
|
|
|
|
|
|
|
impl RemoteRelease {
|
|
|
|
impl RemoteRelease {
|
|
|
|
/// The release's download URL for the given target.
|
|
|
|
/// The release's download URL for the given target.
|
|
|
|
pub fn download_url(&self, target: &str, fallback_target: &Option<String>) -> Result<&Url> {
|
|
|
|
pub fn download_url(&self, target: &str, installer: Option<Installer>) -> Result<&Url> {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let fallback_target = installer.map(|installer| format!("{target}-{}", installer.suffix()));
|
|
|
|
match self.data {
|
|
|
|
match self.data {
|
|
|
|
RemoteReleaseInner::Dynamic(ref platform) => Ok(&platform.url),
|
|
|
|
RemoteReleaseInner::Dynamic(ref platform) => Ok(&platform.url),
|
|
|
|
RemoteReleaseInner::Static { ref platforms } => platforms
|
|
|
|
RemoteReleaseInner::Static { ref platforms } => platforms
|
|
|
|
.get(target)
|
|
|
|
.get(target)
|
|
|
|
.map_or_else(
|
|
|
|
.map_or_else(
|
|
|
|
|| match fallback_target {
|
|
|
|
|| match fallback_target {
|
|
|
|
Some(fallback) => platforms.get(fallback).map_or(Err(Error::TargetsNotFound(target.to_string(), fallback.to_string())), |p| Ok(&p.url)),
|
|
|
|
Some(fallback) => platforms.get(&fallback).map_or(Err(Error::TargetsNotFound(target.to_string(), fallback)), |p| Ok(&p.url)),
|
|
|
|
None => Err(Error::TargetNotFound(target.to_string()))
|
|
|
|
None => Err(Error::TargetNotFound(target.to_string()))
|
|
|
|
}, |p| { Ok(&p.url) })
|
|
|
|
}, |p| { Ok(&p.url) })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// The release's signature for the given target.
|
|
|
|
/// The release's signature for the given target.
|
|
|
|
pub fn signature(&self, target: &str, fallback_target: &Option<String>) -> Result<&String> {
|
|
|
|
pub fn signature(&self, target: &str, installer: Option<Installer>) -> Result<&String> {
|
|
|
|
|
|
|
|
let fallback_target = installer.map(|installer| format!("{target}-{}", installer.suffix()));
|
|
|
|
|
|
|
|
|
|
|
|
match self.data {
|
|
|
|
match self.data {
|
|
|
|
RemoteReleaseInner::Dynamic(ref platform) => Ok(&platform.signature),
|
|
|
|
RemoteReleaseInner::Dynamic(ref platform) => Ok(&platform.signature),
|
|
|
|
RemoteReleaseInner::Static { ref platforms } => platforms
|
|
|
|
RemoteReleaseInner::Static { ref platforms } => platforms
|
|
|
|
.get(target)
|
|
|
|
.get(target)
|
|
|
|
.map_or_else(
|
|
|
|
.map_or_else(
|
|
|
|
|| match fallback_target {
|
|
|
|
|| match fallback_target {
|
|
|
|
Some(fallback) => platforms.get(fallback).map_or(Err(Error::TargetsNotFound(target.to_string(), fallback.to_string())), |p| Ok(&p.signature)),
|
|
|
|
Some(fallback) => platforms.get(&fallback).map_or(Err(Error::TargetsNotFound(target.to_string(), fallback)), |p| Ok(&p.signature)),
|
|
|
|
None => Err(Error::TargetNotFound(target.to_string()))
|
|
|
|
None => Err(Error::TargetNotFound(target.to_string()))
|
|
|
|
}, |p| { Ok(&p.signature) })
|
|
|
|
}, |p| { Ok(&p.signature) })
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -246,16 +275,12 @@ impl UpdaterBuilder {
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let arch = get_updater_arch().ok_or(Error::UnsupportedArch)?;
|
|
|
|
let arch = get_updater_arch().ok_or(Error::UnsupportedArch)?;
|
|
|
|
let (target, json_target, fallback_target) = if let Some(target) = self.target {
|
|
|
|
let (target, json_target) = if let Some(target) = self.target {
|
|
|
|
(target.clone(), target, None)
|
|
|
|
(target.clone(), target )
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
let target = get_updater_target().ok_or(Error::UnsupportedOs)?;
|
|
|
|
let target = get_updater_target().ok_or(Error::UnsupportedOs)?;
|
|
|
|
let installer = get_updater_installer()?;
|
|
|
|
|
|
|
|
let json_target = format!("{target}-{arch}");
|
|
|
|
let json_target = format!("{target}-{arch}");
|
|
|
|
match installer {
|
|
|
|
(target.to_owned(), json_target)
|
|
|
|
Some(installer) => (target.to_owned(), format!("{json_target}-{installer}"), Some(json_target)),
|
|
|
|
|
|
|
|
None => (target.to_owned(), json_target, None)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
let executable_path = self.executable_path.clone().unwrap_or(current_exe()?);
|
|
|
|
let executable_path = self.executable_path.clone().unwrap_or(current_exe()?);
|
|
|
@ -280,7 +305,6 @@ impl UpdaterBuilder {
|
|
|
|
arch,
|
|
|
|
arch,
|
|
|
|
target,
|
|
|
|
target,
|
|
|
|
json_target,
|
|
|
|
json_target,
|
|
|
|
fallback_target,
|
|
|
|
|
|
|
|
headers: self.headers,
|
|
|
|
headers: self.headers,
|
|
|
|
extract_path,
|
|
|
|
extract_path,
|
|
|
|
on_before_exit: self.on_before_exit,
|
|
|
|
on_before_exit: self.on_before_exit,
|
|
|
@ -313,8 +337,6 @@ pub struct Updater {
|
|
|
|
target: String,
|
|
|
|
target: String,
|
|
|
|
// The value we search if the updater server returns a JSON with the `platforms` object
|
|
|
|
// The value we search if the updater server returns a JSON with the `platforms` object
|
|
|
|
json_target: String,
|
|
|
|
json_target: String,
|
|
|
|
// If target doesn't exist in the JSON check for this one
|
|
|
|
|
|
|
|
fallback_target: Option<String>,
|
|
|
|
|
|
|
|
headers: HeaderMap,
|
|
|
|
headers: HeaderMap,
|
|
|
|
extract_path: PathBuf,
|
|
|
|
extract_path: PathBuf,
|
|
|
|
on_before_exit: Option<OnBeforeExit>,
|
|
|
|
on_before_exit: Option<OnBeforeExit>,
|
|
|
@ -325,6 +347,7 @@ pub struct Updater {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl Updater {
|
|
|
|
impl Updater {
|
|
|
|
|
|
|
|
|
|
|
|
pub async fn check(&self) -> Result<Option<Update>> {
|
|
|
|
pub async fn check(&self) -> Result<Option<Update>> {
|
|
|
|
// we want JSON only
|
|
|
|
// we want JSON only
|
|
|
|
let mut headers = self.headers.clone();
|
|
|
|
let mut headers = self.headers.clone();
|
|
|
@ -421,6 +444,8 @@ impl Updater {
|
|
|
|
None => release.version > self.current_version,
|
|
|
|
None => release.version > self.current_version,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let installer = get_updater_installer(&self.extract_path)?;
|
|
|
|
|
|
|
|
|
|
|
|
let update = if should_update {
|
|
|
|
let update = if should_update {
|
|
|
|
Some(Update {
|
|
|
|
Some(Update {
|
|
|
|
config: self.config.clone(),
|
|
|
|
config: self.config.clone(),
|
|
|
@ -431,9 +456,10 @@ impl Updater {
|
|
|
|
extract_path: self.extract_path.clone(),
|
|
|
|
extract_path: self.extract_path.clone(),
|
|
|
|
version: release.version.to_string(),
|
|
|
|
version: release.version.to_string(),
|
|
|
|
date: release.pub_date,
|
|
|
|
date: release.pub_date,
|
|
|
|
download_url: release.download_url(&self.json_target, &self.fallback_target)?.to_owned(),
|
|
|
|
download_url: release.download_url(&self.json_target, installer.clone())?.to_owned(),
|
|
|
|
body: release.notes.clone(),
|
|
|
|
body: release.notes.clone(),
|
|
|
|
signature: release.signature(&self.json_target, &self.fallback_target)?.to_owned(),
|
|
|
|
signature: release.signature(&self.json_target, installer.clone())?.to_owned(),
|
|
|
|
|
|
|
|
installer,
|
|
|
|
raw_json: raw_json.unwrap(),
|
|
|
|
raw_json: raw_json.unwrap(),
|
|
|
|
timeout: self.timeout,
|
|
|
|
timeout: self.timeout,
|
|
|
|
proxy: self.proxy.clone(),
|
|
|
|
proxy: self.proxy.clone(),
|
|
|
@ -464,6 +490,8 @@ pub struct Update {
|
|
|
|
pub date: Option<OffsetDateTime>,
|
|
|
|
pub date: Option<OffsetDateTime>,
|
|
|
|
/// Target
|
|
|
|
/// Target
|
|
|
|
pub target: String,
|
|
|
|
pub target: String,
|
|
|
|
|
|
|
|
/// Current installer
|
|
|
|
|
|
|
|
pub installer: Option<Installer>,
|
|
|
|
/// Download URL announced
|
|
|
|
/// Download URL announced
|
|
|
|
pub download_url: Url,
|
|
|
|
pub download_url: Url,
|
|
|
|
/// Signature announced
|
|
|
|
/// Signature announced
|
|
|
@ -791,11 +819,9 @@ impl Update {
|
|
|
|
/// └── ...
|
|
|
|
/// └── ...
|
|
|
|
///
|
|
|
|
///
|
|
|
|
fn install_inner(&self, bytes: &[u8]) -> Result<()> {
|
|
|
|
fn install_inner(&self, bytes: &[u8]) -> Result<()> {
|
|
|
|
if self.is_deb_package() {
|
|
|
|
match self.installer {
|
|
|
|
self.install_deb(bytes)
|
|
|
|
Some(Installer::Deb) => self.install_deb(bytes),
|
|
|
|
} else {
|
|
|
|
_ =>self.install_appimage(bytes)
|
|
|
|
// Handle AppImage or other formats
|
|
|
|
|
|
|
|
self.install_appimage(bytes)
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -870,38 +896,6 @@ impl Update {
|
|
|
|
Err(Error::TempDirNotOnSameMountPoint)
|
|
|
|
Err(Error::TempDirNotOnSameMountPoint)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn is_deb_package(&self) -> bool {
|
|
|
|
|
|
|
|
// First check if we're in a typical Debian installation path
|
|
|
|
|
|
|
|
let in_system_path = self
|
|
|
|
|
|
|
|
.extract_path
|
|
|
|
|
|
|
|
.to_str()
|
|
|
|
|
|
|
|
.map(|p| p.starts_with("/usr"))
|
|
|
|
|
|
|
|
.unwrap_or(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !in_system_path {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Then verify it's actually a Debian-based system by checking for dpkg
|
|
|
|
|
|
|
|
let dpkg_exists = std::path::Path::new("/var/lib/dpkg").exists();
|
|
|
|
|
|
|
|
let apt_exists = std::path::Path::new("/etc/apt").exists();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Additional check for the package in dpkg database
|
|
|
|
|
|
|
|
let package_in_dpkg = if let Ok(output) = std::process::Command::new("dpkg")
|
|
|
|
|
|
|
|
.args(["-S", &self.extract_path.to_string_lossy()])
|
|
|
|
|
|
|
|
.output()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
output.status.success()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Consider it a deb package only if:
|
|
|
|
|
|
|
|
// 1. We're in a system path AND
|
|
|
|
|
|
|
|
// 2. We have Debian package management tools AND
|
|
|
|
|
|
|
|
// 3. The binary is tracked by dpkg
|
|
|
|
|
|
|
|
dpkg_exists && apt_exists && package_in_dpkg
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn install_deb(&self, bytes: &[u8]) -> Result<()> {
|
|
|
|
fn install_deb(&self, bytes: &[u8]) -> Result<()> {
|
|
|
|
// First verify the bytes are actually a .deb package
|
|
|
|
// First verify the bytes are actually a .deb package
|
|
|
@ -1125,11 +1119,49 @@ pub(crate) fn get_updater_arch() -> Option<&'static str> {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_updater_installer() -> Result<Option<&'static str>> {
|
|
|
|
fn is_deb_package(extract_path: &PathBuf) -> bool {
|
|
|
|
|
|
|
|
// First check if we're in a typical Debian installation path
|
|
|
|
|
|
|
|
let in_system_path = extract_path
|
|
|
|
|
|
|
|
.to_str()
|
|
|
|
|
|
|
|
.map(|p| p.starts_with("/usr"))
|
|
|
|
|
|
|
|
.unwrap_or(false);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !in_system_path {
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Then verify it's actually a Debian-based system by checking for dpkg
|
|
|
|
|
|
|
|
let dpkg_exists = std::path::Path::new("/var/lib/dpkg").exists();
|
|
|
|
|
|
|
|
let apt_exists = std::path::Path::new("/etc/apt").exists();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Additional check for the package in dpkg database
|
|
|
|
|
|
|
|
let package_in_dpkg = if let Ok(output) = std::process::Command::new("dpkg")
|
|
|
|
|
|
|
|
.args(["-S", &extract_path.to_string_lossy()])
|
|
|
|
|
|
|
|
.output()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
output.status.success()
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
false
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Consider it a deb package only if:
|
|
|
|
|
|
|
|
// 1. We're in a system path AND
|
|
|
|
|
|
|
|
// 2. We have Debian package management tools AND
|
|
|
|
|
|
|
|
// 3. The binary is tracked by dpkg
|
|
|
|
|
|
|
|
dpkg_exists && apt_exists && package_in_dpkg
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn get_updater_installer(extract_path: &PathBuf) -> Result<Option<Installer>> {
|
|
|
|
if cfg!(target_os = "linux") {
|
|
|
|
if cfg!(target_os = "linux") {
|
|
|
|
Ok(Some("deb"))
|
|
|
|
if std::env::var_os("APPIMAGE").is_some() {
|
|
|
|
|
|
|
|
Ok(Some(Installer::AppImage))
|
|
|
|
|
|
|
|
} else if is_deb_package(extract_path) {
|
|
|
|
|
|
|
|
Ok(Some(Installer::Deb))
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Err(Error::UnknownInstaller)
|
|
|
|
|
|
|
|
}
|
|
|
|
} else if cfg!(target_os = "windows") {
|
|
|
|
} else if cfg!(target_os = "windows") {
|
|
|
|
Ok(Some("wix"))
|
|
|
|
Ok(Some(Installer::Msi))
|
|
|
|
} else if cfg!(target_os = "macos") {
|
|
|
|
} else if cfg!(target_os = "macos") {
|
|
|
|
Ok(None)
|
|
|
|
Ok(None)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|