|
|
@ -79,7 +79,7 @@ fn build_app(cwd: &Path, config: &Config, bundle_updater: bool, target: BundleTa
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone)]
|
|
|
|
#[derive(Copy, Clone, PartialEq)]
|
|
|
|
enum BundleTarget {
|
|
|
|
enum BundleTarget {
|
|
|
|
AppImage,
|
|
|
|
AppImage,
|
|
|
|
Deb,
|
|
|
|
Deb,
|
|
|
@ -106,12 +106,6 @@ impl Default for BundleTarget {
|
|
|
|
return Self::App;
|
|
|
|
return Self::App;
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Check if we're on a Debian-based system
|
|
|
|
|
|
|
|
if std::path::Path::new("/var/lib/dpkg").exists()
|
|
|
|
|
|
|
|
&& std::path::Path::new("/etc/apt").exists()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return Self::Deb;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return Self::AppImage;
|
|
|
|
return Self::AppImage;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#[cfg(windows)]
|
|
|
|
#[cfg(windows)]
|
|
|
@ -121,23 +115,21 @@ impl Default for BundleTarget {
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
fn bundle_paths(root_dir: &Path, version: &str) -> Vec<(BundleTarget, PathBuf)> {
|
|
|
|
fn bundle_paths(root_dir: &Path, version: &str) -> Vec<(BundleTarget, PathBuf)> {
|
|
|
|
// Check if we're on a Debian-based system
|
|
|
|
// Return both AppImage and Deb paths
|
|
|
|
if std::path::Path::new("/var/lib/dpkg").exists()
|
|
|
|
vec![
|
|
|
|
&& std::path::Path::new("/etc/apt").exists() {
|
|
|
|
(
|
|
|
|
vec![(
|
|
|
|
|
|
|
|
BundleTarget::Deb,
|
|
|
|
|
|
|
|
root_dir.join(format!(
|
|
|
|
|
|
|
|
"target/debug/bundle/deb/app-updater_{version}_amd64.deb"
|
|
|
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
)]
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
vec![(
|
|
|
|
|
|
|
|
BundleTarget::AppImage,
|
|
|
|
BundleTarget::AppImage,
|
|
|
|
root_dir.join(format!(
|
|
|
|
root_dir.join(format!(
|
|
|
|
"target/debug/bundle/appimage/app-updater_{version}_amd64.AppImage"
|
|
|
|
"target/debug/bundle/appimage/app-updater_{version}_amd64.AppImage"
|
|
|
|
)),
|
|
|
|
)),
|
|
|
|
)]
|
|
|
|
),
|
|
|
|
}
|
|
|
|
(
|
|
|
|
|
|
|
|
BundleTarget::Deb,
|
|
|
|
|
|
|
|
root_dir.join(format!(
|
|
|
|
|
|
|
|
"target/debug/bundle/deb/app-updater_{version}_amd64.deb"
|
|
|
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
),
|
|
|
|
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
#[cfg(target_os = "macos")]
|
|
|
@ -187,6 +179,19 @@ fn update_app() {
|
|
|
|
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
|
|
let manifest_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
|
|
|
|
let root_dir = manifest_dir.join("../../../..");
|
|
|
|
let root_dir = manifest_dir.join("../../../..");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set up cleanup on panic
|
|
|
|
|
|
|
|
let cleanup = std::panic::AssertUnwindSafe(|| {
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let _ = std::process::Command::new("sudo")
|
|
|
|
|
|
|
|
.arg("dpkg")
|
|
|
|
|
|
|
|
.arg("-r")
|
|
|
|
|
|
|
|
.arg("app-updater")
|
|
|
|
|
|
|
|
.status();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let test_result = std::panic::catch_unwind(|| {
|
|
|
|
for mut config in [
|
|
|
|
for mut config in [
|
|
|
|
Config {
|
|
|
|
Config {
|
|
|
|
version: "1.0.0",
|
|
|
|
version: "1.0.0",
|
|
|
@ -258,7 +263,8 @@ fn update_app() {
|
|
|
|
|
|
|
|
|
|
|
|
// start the updater server
|
|
|
|
// start the updater server
|
|
|
|
let server = Arc::new(
|
|
|
|
let server = Arc::new(
|
|
|
|
tiny_http::Server::http("localhost:3007").expect("failed to start updater server"),
|
|
|
|
tiny_http::Server::http("localhost:3007")
|
|
|
|
|
|
|
|
.expect("failed to start updater server"),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
let server_ = server.clone();
|
|
|
|
let server_ = server.clone();
|
|
|
@ -314,8 +320,35 @@ fn update_app() {
|
|
|
|
// bundle initial app version
|
|
|
|
// bundle initial app version
|
|
|
|
build_app(&manifest_dir, &config, false, bundle_target);
|
|
|
|
build_app(&manifest_dir, &config, false, bundle_target);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set appropriate permissions and install package if needed
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let paths = bundle_paths(&root_dir, "0.1.0");
|
|
|
|
|
|
|
|
let bundle_path = &paths.first().unwrap().1;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if bundle_target == BundleTarget::AppImage {
|
|
|
|
|
|
|
|
std::process::Command::new("sudo")
|
|
|
|
|
|
|
|
.arg("chmod")
|
|
|
|
|
|
|
|
.arg("+x")
|
|
|
|
|
|
|
|
.arg(bundle_path)
|
|
|
|
|
|
|
|
.status()
|
|
|
|
|
|
|
|
.expect("failed to change permissions");
|
|
|
|
|
|
|
|
} else if bundle_target == BundleTarget::Deb {
|
|
|
|
|
|
|
|
// Install the .deb package
|
|
|
|
|
|
|
|
let install_status = std::process::Command::new("sudo")
|
|
|
|
|
|
|
|
.arg("dpkg")
|
|
|
|
|
|
|
|
.arg("-i")
|
|
|
|
|
|
|
|
.arg(bundle_path)
|
|
|
|
|
|
|
|
.status()
|
|
|
|
|
|
|
|
.expect("failed to install .deb package");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if !install_status.success() {
|
|
|
|
|
|
|
|
panic!("Failed to install .deb package");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
let status_checks = if matches!(bundle_target, BundleTarget::Msi) {
|
|
|
|
let status_checks = if matches!(bundle_target, BundleTarget::Msi) {
|
|
|
|
// for msi we can't really check if the app was updated, because we can't change the install path
|
|
|
|
|
|
|
|
vec![UPDATED_EXIT_CODE]
|
|
|
|
vec![UPDATED_EXIT_CODE]
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
vec![UPDATED_EXIT_CODE, UP_TO_DATE_EXIT_CODE]
|
|
|
|
vec![UPDATED_EXIT_CODE, UP_TO_DATE_EXIT_CODE]
|
|
|
@ -334,11 +367,29 @@ fn update_app() {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
} else if std::env::var("CI").map(|v| v == "true").unwrap_or_default() {
|
|
|
|
} else if std::env::var("CI").map(|v| v == "true").unwrap_or_default() {
|
|
|
|
let mut c = Command::new("xvfb-run");
|
|
|
|
let mut c = Command::new("xvfb-run");
|
|
|
|
c.arg("--auto-servernum")
|
|
|
|
c.arg("--auto-servernum");
|
|
|
|
.arg(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1);
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
|
|
|
if bundle_target == BundleTarget::Deb {
|
|
|
|
|
|
|
|
c.arg("/usr/bin/app-updater");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
c.arg(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1);
|
|
|
|
|
|
|
|
}
|
|
|
|
c
|
|
|
|
c
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
let mut c = Command::new("sudo");
|
|
|
|
|
|
|
|
if bundle_target == BundleTarget::Deb {
|
|
|
|
|
|
|
|
c.arg("/usr/bin/app-updater");
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
c.arg(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
c
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(not(target_os = "linux"))]
|
|
|
|
|
|
|
|
{
|
|
|
|
Command::new(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1)
|
|
|
|
Command::new(&bundle_paths(&root_dir, "0.1.0").first().unwrap().1)
|
|
|
|
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
binary_cmd.env("TARGET", bundle_target.name());
|
|
|
|
binary_cmd.env("TARGET", bundle_target.name());
|
|
|
@ -362,4 +413,13 @@ fn update_app() {
|
|
|
|
server.unblock();
|
|
|
|
server.unblock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Always run cleanup
|
|
|
|
|
|
|
|
cleanup();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Re-panic if there was an error
|
|
|
|
|
|
|
|
if let Err(e) = test_result {
|
|
|
|
|
|
|
|
std::panic::resume_unwind(e);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|