Skip to content

Commit

Permalink
Merge pull request #21 from AOSC-Dev/use-oma-to-update-os
Browse files Browse the repository at this point in the history
feat: use oma to update-os
  • Loading branch information
eatradish authored Jul 18, 2024
2 parents 0f5162f + 62fecdb commit 97626ee
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
11 changes: 7 additions & 4 deletions src/actions/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ use std::{
};

use crate::{
actions::ensure_host_sanity,
actions::{ensure_host_sanity, OMA_UPDATE_SCRIPT},
common::*,
config, error, info,
machine::{self, get_container_ns_name, inspect_instance, spawn_container},
network::download_file_progress,
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]
Expand Down Expand Up @@ -380,9 +380,12 @@ pub fn update_os() -> Result<()> {
info!("Updating base OS...");
let instance = format!("update-{:x}", random::<u32>());
add_instance(&instance)?;
let status = run_in_container(&instance, &["/bin/bash", "-ec", UPDATE_SCRIPT])?;
let mut status = run_in_container(&instance, &["/bin/bash", "-ec", OMA_UPDATE_SCRIPT])?;
if status != 0 {
return Err(anyhow!("Failed to update OS: {}", status));
status = run_in_container(&instance, &["/bin/bash", "-ec", APT_UPDATE_SCRIPT])?;
if status != 0 {
return Err(anyhow!("Failed to update OS: {}", status));
}
}
commit_container(&instance)?;
remove_instance(&instance)?;
Expand Down
3 changes: 2 additions & 1 deletion src/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>, Vec<(String, &'static str)>);
/// Ensure that the directories exist and mounted
Expand Down
12 changes: 9 additions & 3 deletions src/actions/packaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -177,8 +177,13 @@ fn package_build_inner<P: AsRef<Path>>(
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 {
Expand All @@ -187,6 +192,7 @@ fn package_build_inner<P: AsRef<Path>>(
"Failed to update the OS, will retry in {} seconds ...",
interval
);
oma = false;
sleep(Duration::from_secs(interval));
}
}
Expand Down

0 comments on commit 97626ee

Please sign in to comment.