summaryrefslogtreecommitdiff
path: root/src/packages
diff options
context:
space:
mode:
authorfxqnlr <[email protected]>2024-11-01 22:22:18 +0100
committerfxqnlr <[email protected]>2024-11-01 22:22:18 +0100
commit6b3cdf3e3d4417caa8f9d622561696a8d50c86aa (patch)
tree961f699e0b871d17460fbb1e6887c8b04ede9e32 /src/packages
parent7179fa0262c92b124e5d444754a572b2cecbf5cd (diff)
downloadarbs-6b3cdf3e3d4417caa8f9d622561696a8d50c86aa.tar
arbs-6b3cdf3e3d4417caa8f9d622561696a8d50c86aa.tar.gz
arbs-6b3cdf3e3d4417caa8f9d622561696a8d50c86aa.zip
add basic apt compatabilityapt
Diffstat (limited to 'src/packages')
-rw-r--r--src/packages/apt.rs58
1 files changed, 58 insertions, 0 deletions
diff --git a/src/packages/apt.rs b/src/packages/apt.rs
new file mode 100644
index 0000000..2036559
--- /dev/null
+++ b/src/packages/apt.rs
@@ -0,0 +1,58 @@
1use std::process::{Command, Stdio};
2
3use super::{Package, PackageList, PackageManager};
4
5use crate::error::{Error, Result};
6
7pub struct Apt;
8
9impl PackageManager for Apt {
10 fn get_installed(&self) -> Result<PackageList> {
11 let list = Command::new("apt").args(["list", "--installed"]).output().unwrap();
12
13 let mut pkgs: Vec<Package> = Vec::new();
14
15 let list_str = String::from_utf8(list.stdout).unwrap();
16 let list_lines: Vec<&str> = list_str.split('\n').collect();
17 // Pop first info line
18 let list_lines = &list_lines[1..list_lines.len()];
19 for pkg in list_lines {
20 if pkg.is_empty() {
21 continue;
22 };
23
24 let split: Vec<&str> = pkg.split_whitespace().collect();
25 if split.len() != 4 {
26 return Err(Error::UnknownOutput);
27 };
28
29 let Some(pkg_id) = split[0].split_once('/') else {
30 return Err(Error::UnknownOutput);
31 };
32
33 let explicit = split[3] == "[installed]";
34
35 pkgs.push(Package {
36 id: pkg_id.0.to_string(),
37 version: split[1].to_string(),
38 explicit
39 })
40 }
41
42 Ok(PackageList { packages: pkgs, manager: super::Manager::Apt })
43 }
44
45 fn install(&self, pkgs: Vec<super::Package>) -> Result<()> {
46 let mut args = vec!["apt".to_string(), "install".to_string(), "--yes".to_string()];
47
48 for pkg in pkgs {
49 args.push(pkg.id);
50 }
51 Command::new("sudo")
52 .stdout(Stdio::inherit())
53 .args(args)
54 .spawn()?
55 .wait_with_output()?;
56 Ok(())
57 }
58}