Skip to content

Commit 97626ee

Browse files
authored
Merge pull request #21 from AOSC-Dev/use-oma-to-update-os
feat: use oma to update-os
2 parents 0f5162f + 62fecdb commit 97626ee

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

src/actions/container.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ use std::{
1111
};
1212

1313
use crate::{
14-
actions::ensure_host_sanity,
14+
actions::{ensure_host_sanity, OMA_UPDATE_SCRIPT},
1515
common::*,
1616
config, error, info,
1717
machine::{self, get_container_ns_name, inspect_instance, spawn_container},
1818
network::download_file_progress,
1919
overlayfs, warn,
2020
};
2121

22-
use super::{for_each_instance, UPDATE_SCRIPT};
22+
use super::{for_each_instance, APT_UPDATE_SCRIPT};
2323

2424
/// Get the branch name of the workspace TREE repository
2525
#[inline]
@@ -380,9 +380,12 @@ pub fn update_os() -> Result<()> {
380380
info!("Updating base OS...");
381381
let instance = format!("update-{:x}", random::<u32>());
382382
add_instance(&instance)?;
383-
let status = run_in_container(&instance, &["/bin/bash", "-ec", UPDATE_SCRIPT])?;
383+
let mut status = run_in_container(&instance, &["/bin/bash", "-ec", OMA_UPDATE_SCRIPT])?;
384384
if status != 0 {
385-
return Err(anyhow!("Failed to update OS: {}", status));
385+
status = run_in_container(&instance, &["/bin/bash", "-ec", APT_UPDATE_SCRIPT])?;
386+
if status != 0 {
387+
return Err(anyhow!("Failed to update OS: {}", status));
388+
}
386389
}
387390
commit_container(&instance)?;
388391
remove_instance(&instance)?;

src/actions/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ const DEFAULT_MOUNTS: &[(&str, &str)] = &[
1818
("SRCS", "/var/cache/acbs/tarballs"),
1919
("CACHE", "/var/cache/apt/archives"),
2020
];
21-
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"#;
21+
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"#;
22+
const OMA_UPDATE_SCRIPT: &str = r#"oma upgrade -y --force-confnew --no-progress && oma autoremove --remove-config && oma clean"#;
2223

2324
type MountOptions = (Vec<String>, Vec<(String, &'static str)>);
2425
/// Ensure that the directories exist and mounted

src/actions/packaging.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ use std::{
1212
};
1313
use walkdir::WalkDir;
1414

15-
use crate::{common::create_spinner, config, error, info, repo, warn};
15+
use crate::{actions::OMA_UPDATE_SCRIPT, common::create_spinner, config, error, info, repo, warn};
1616

1717
use super::{
1818
container::{get_output_directory, mount_fs, rollback_container, run_in_container},
19-
UPDATE_SCRIPT,
19+
APT_UPDATE_SCRIPT,
2020
};
2121

2222
#[derive(Debug, Clone, Deserialize, Serialize)]
@@ -177,8 +177,13 @@ fn package_build_inner<P: AsRef<Path>>(
177177
info!("Refreshing local repository...");
178178
repo::init_repo(root.as_ref(), Path::new(instance))?;
179179
let mut status = -1;
180+
let mut oma = true;
180181
for i in 1..=5 {
181-
status = run_in_container(instance, &["/bin/bash", "-ec", UPDATE_SCRIPT]).unwrap_or(-1);
182+
status = if oma {
183+
run_in_container(instance, &["/bin/bash", "-ec", OMA_UPDATE_SCRIPT]).unwrap_or(-1)
184+
} else {
185+
run_in_container(instance, &["/bin/bash", "-ec", APT_UPDATE_SCRIPT]).unwrap_or(-1)
186+
};
182187
if status == 0 {
183188
break;
184189
} else {
@@ -187,6 +192,7 @@ fn package_build_inner<P: AsRef<Path>>(
187192
"Failed to update the OS, will retry in {} seconds ...",
188193
interval
189194
);
195+
oma = false;
190196
sleep(Duration::from_secs(interval));
191197
}
192198
}

0 commit comments

Comments
 (0)