deb: allow injecting .deb files packages
Some checks failed
CI / build (push) Failing after 1m19s
CI / snap (push) Has been skipped

This commit is contained in:
2026-04-04 12:35:14 +02:00
parent 2b27b7b06e
commit d83174c980

View File

@@ -178,17 +178,7 @@ pub async fn build(
// Install injected packages if specified // Install injected packages if specified
if let Some(packages) = inject_packages { if let Some(packages) = inject_packages {
log::info!("Installing injected packages: {:?}", packages); install_injected_packages(packages, &env, ctx.clone())?;
let mut cmd = ctx.command("apt-get");
cmd.envs(env.clone())
.arg("-y")
.arg("--allow-downgrades")
.arg("install")
.args(packages);
let status = cmd.status()?;
if !status.success() {
return Err(format!("Could not install injected packages: {:?}", packages).into());
}
} }
// Install arch-specific build dependencies // Install arch-specific build dependencies
@@ -256,6 +246,64 @@ pub async fn build(
Ok(()) Ok(())
} }
fn install_injected_packages(
packages: &[&str],
env: &HashMap<String, String>,
ctx: Arc<Context>,
) -> Result<(), Box<dyn Error>> {
log::info!("Installing injected packages: {:?}", packages);
// Separate .deb files from package names
let mut deb_files: Vec<String> = Vec::new();
let mut package_names: Vec<&str> = Vec::new();
for pkg in packages {
// Check if it's a .deb file path (ends with .deb and exists as a file)
let pkg_path = Path::new(pkg);
if pkg.ends_with(".deb") && pkg_path.exists() {
// Copy the .deb file into the build context
let dest_root = ctx.create_temp_dir()?;
let chroot_path = ctx.ensure_available(pkg_path, &dest_root)?;
log::debug!(
"Copied .deb file '{}' to chroot path '{}'",
pkg,
chroot_path.display()
);
deb_files.push(chroot_path.to_string_lossy().to_string());
} else {
package_names.push(pkg);
}
}
// Install .deb files using dpkg -i
if !deb_files.is_empty() {
log::info!("Installing .deb files: {:?}", deb_files);
let mut cmd = ctx.command("dpkg");
cmd.envs(env.clone()).arg("-i").args(&deb_files);
let status = cmd.status()?;
if !status.success() {
return Err(format!("Could not install .deb files: {:?}", deb_files).into());
}
}
// Install package names using apt-get
if !package_names.is_empty() {
log::info!("Installing packages from archive: {:?}", package_names);
let mut cmd = ctx.command("apt-get");
cmd.envs(env.clone())
.arg("-y")
.arg("--allow-downgrades")
.arg("install")
.args(&package_names);
let status = cmd.status()?;
if !status.success() {
return Err(format!("Could not install injected packages: {:?}", package_names).into());
}
}
Ok(())
}
fn dose3_explain_dependencies( fn dose3_explain_dependencies(
package: &str, package: &str,
version: &str, version: &str,