From 5201da9afda7bf86c7a4f978c3dd5536e3a8dfa8 Mon Sep 17 00:00:00 2001 From: eatradish Date: Thu, 18 Jul 2024 15:33:21 +0800 Subject: [PATCH] feat: use oma to update-os ... if failed, fallback to apt --- src/actions/container.rs | 4 ++-- src/actions/mod.rs | 3 ++- src/actions/packaging.rs | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/actions/container.rs b/src/actions/container.rs index a35db0e..0c307e9 100644 --- a/src/actions/container.rs +++ b/src/actions/container.rs @@ -19,7 +19,7 @@ use crate::{ overlayfs, warn, }; -use super::{for_each_instance, UPDATE_SCRIPT}; +use super::{for_each_instance, APT_UPDATE_SCRIPT}; /// Get the branch name of the workspace TREE repository #[inline] @@ -380,7 +380,7 @@ pub fn update_os() -> Result<()> { info!("Updating base OS..."); let instance = format!("update-{:x}", random::()); add_instance(&instance)?; - let status = run_in_container(&instance, &["/bin/bash", "-ec", UPDATE_SCRIPT])?; + let status = run_in_container(&instance, &["/bin/bash", "-ec", APT_UPDATE_SCRIPT])?; if status != 0 { return Err(anyhow!("Failed to update OS: {}", status)); } diff --git a/src/actions/mod.rs b/src/actions/mod.rs index 032f6e5..d608b37 100644 --- a/src/actions/mod.rs +++ b/src/actions/mod.rs @@ -18,7 +18,8 @@ const DEFAULT_MOUNTS: &[(&str, &str)] = &[ ("SRCS", "/var/cache/acbs/tarballs"), ("CACHE", "/var/cache/apt/archives"), ]; -const UPDATE_SCRIPT: &str = r#"export DEBIAN_FRONTEND=noninteractive;apt-get update -y --allow-releaseinfo-change && apt-get -y -o Dpkg::Options::="--force-confnew" full-upgrade --autoremove --purge && apt autoclean"#; +const APT_UPDATE_SCRIPT: &str = r#"export DEBIAN_FRONTEND=noninteractive;apt-get update -y --allow-releaseinfo-change && apt-get -y -o Dpkg::Options::="--force-confnew" full-upgrade --autoremove --purge && apt autoclean"#; +const OMA_UPDATE_SCRIPT: &str = r#"oma upgrade -y --force-confnew --no-progress && oma autoremove --remove-config && oma clean"#; type MountOptions = (Vec, Vec<(String, &'static str)>); /// Ensure that the directories exist and mounted diff --git a/src/actions/packaging.rs b/src/actions/packaging.rs index f0c3956..a719e8d 100644 --- a/src/actions/packaging.rs +++ b/src/actions/packaging.rs @@ -12,11 +12,11 @@ use std::{ }; use walkdir::WalkDir; -use crate::{common::create_spinner, config, error, info, repo, warn}; +use crate::{actions::OMA_UPDATE_SCRIPT, common::create_spinner, config, error, info, repo, warn}; use super::{ container::{get_output_directory, mount_fs, rollback_container, run_in_container}, - UPDATE_SCRIPT, + APT_UPDATE_SCRIPT, }; #[derive(Debug, Clone, Deserialize, Serialize)] @@ -177,8 +177,13 @@ fn package_build_inner>( info!("Refreshing local repository..."); repo::init_repo(root.as_ref(), Path::new(instance))?; let mut status = -1; + let mut oma = true; for i in 1..=5 { - status = run_in_container(instance, &["/bin/bash", "-ec", UPDATE_SCRIPT]).unwrap_or(-1); + status = if oma { + run_in_container(instance, &["/bin/bash", "-ec", OMA_UPDATE_SCRIPT]).unwrap_or(-1) + } else { + run_in_container(instance, &["/bin/bash", "-ec", APT_UPDATE_SCRIPT]).unwrap_or(-1) + }; if status == 0 { break; } else { @@ -187,6 +192,7 @@ fn package_build_inner>( "Failed to update the OS, will retry in {} seconds ...", interval ); + oma = false; sleep(Duration::from_secs(interval)); } }