diff options
author | fxqnlr <[email protected]> | 2024-09-14 14:20:52 +0200 |
---|---|---|
committer | fxqnlr <[email protected]> | 2024-09-14 14:20:52 +0200 |
commit | 1b99a4a1ed7772c9b68e59f46e493ea5b4715239 (patch) | |
tree | cd4e5b2dbac773ba1797cbe2c8bde62c7a94659f /src/packages | |
parent | 553bbac36bdc483135a7053ca64507e01397e5e1 (diff) | |
download | arbs-1b99a4a1ed7772c9b68e59f46e493ea5b4715239.tar arbs-1b99a4a1ed7772c9b68e59f46e493ea5b4715239.tar.gz arbs-1b99a4a1ed7772c9b68e59f46e493ea5b4715239.zip |
add portage package manager
Diffstat (limited to 'src/packages')
-rw-r--r-- | src/packages/portage.rs | 57 |
1 files changed, 52 insertions, 5 deletions
diff --git a/src/packages/portage.rs b/src/packages/portage.rs index 7fa09a8..dac0c2f 100644 --- a/src/packages/portage.rs +++ b/src/packages/portage.rs | |||
@@ -1,16 +1,63 @@ | |||
1 | use tracing::error; | 1 | use std::process::{Command, Stdio}; |
2 | 2 | ||
3 | use super::{PackageList, PackageManager}; | 3 | use crate::error::Error; |
4 | |||
5 | use super::{Package, PackageList, PackageManager}; | ||
4 | 6 | ||
5 | pub struct Portage; | 7 | pub struct Portage; |
6 | 8 | ||
7 | impl PackageManager for Portage { | 9 | impl PackageManager for Portage { |
8 | fn get_installed(&self) -> crate::error::Result<PackageList> { | 10 | fn get_installed(&self) -> crate::error::Result<PackageList> { |
9 | todo!() | 11 | let eix_pkgs = Command::new("eix") |
12 | .args(["--world", "-c*"]) | ||
13 | .output() | ||
14 | .unwrap(); | ||
15 | |||
16 | let eix_pkgs_out = String::from_utf8(eix_pkgs.stdout).unwrap(); | ||
17 | |||
18 | let mut pkgs: Vec<Package> = Vec::new(); | ||
19 | let portage_pkgs: Vec<&str> = eix_pkgs_out.split('\n').collect(); | ||
20 | for pkg in portage_pkgs { | ||
21 | if pkg.is_empty() { | ||
22 | continue; | ||
23 | }; | ||
24 | let split = pkg.split_once('@'); | ||
25 | let info = if let Some(sp) = split { | ||
26 | sp.0 | ||
27 | } else { | ||
28 | return Err(Error::UnknownOutput); | ||
29 | }; | ||
30 | |||
31 | let (id, version) = if let Some(res) = info.split_once('(') { | ||
32 | (res.0.split_at(4).1.trim().to_string(), res.1.to_string()) | ||
33 | } else { | ||
34 | return Err(Error::UnknownOutput); | ||
35 | }; | ||
36 | |||
37 | pkgs.push(Package { | ||
38 | id, | ||
39 | version, | ||
40 | explicit: true, | ||
41 | }); | ||
42 | } | ||
43 | |||
44 | Ok(PackageList { | ||
45 | packages: pkgs, | ||
46 | manager: super::Manager::Portage, | ||
47 | }) | ||
10 | } | 48 | } |
11 | 49 | ||
12 | fn install(&self, pkgs: Vec<super::Package>) -> crate::error::Result<()> { | 50 | fn install(&self, pkgs: Vec<super::Package>) -> crate::error::Result<()> { |
13 | error!("Install {pkgs:?}"); | 51 | let mut args = vec!["emerge".to_string()]; |
14 | todo!() | 52 | |
53 | for pkg in pkgs { | ||
54 | args.push(pkg.id); | ||
55 | } | ||
56 | Command::new("doas") | ||
57 | .stdout(Stdio::inherit()) | ||
58 | .args(args) | ||
59 | .spawn()? | ||
60 | .wait_with_output()?; | ||
61 | Ok(()) | ||
15 | } | 62 | } |
16 | } | 63 | } |