crosup_types/
git.rs

1use indexmap::IndexMap;
2use os_release::OsRelease;
3use serde::{Deserialize, Serialize};
4
5#[derive(Serialize, Deserialize, Debug, Clone, Default)]
6pub struct GitConfiguration {
7    #[serde(serialize_with = "hcl::ser::labeled_block")]
8    pub repo: IndexMap<String, Repository>,
9}
10
11#[derive(Serialize, Deserialize, Debug, Clone, Default)]
12pub struct Repository {
13    #[serde(skip_serializing, skip_deserializing)]
14    pub name: String,
15    pub url: String,
16    pub install: String,
17
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub preinstall: Option<String>,
20
21    #[serde(skip_serializing_if = "Option::is_none")]
22    pub postinstall: Option<String>,
23
24    #[serde(skip_serializing_if = "Option::is_none")]
25    pub install_check: Option<String>,
26
27    #[serde(skip_serializing_if = "Option::is_none")]
28    pub recursive: Option<bool>,
29
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub depth: Option<u32>,
32
33    #[serde(skip_serializing_if = "Option::is_none")]
34    pub shallow_submodules: Option<bool>,
35
36    #[serde(skip_serializing_if = "Option::is_none")]
37    pub depends_on: Option<Vec<String>>,
38}
39
40pub fn default_git_install() -> IndexMap<String, GitConfiguration> {
41    let mut repo = IndexMap::new();
42
43    let mut blesh = Repository {
44        name: "blesh".into(),
45        url: "https://github.com/akinomyoga/ble.sh.git".into(),
46        install: "make -C ble.sh install PREFIX=~/.local".into(),
47        preinstall: None,
48        postinstall: Some("echo 'source ~/.local/share/blesh/ble.sh' >> ~/.bashrc".into()),
49        install_check: Some("~/.local/share/blesh/ble.sh".into()),
50        recursive: Some(true),
51        depth: Some(1),
52        shallow_submodules: Some(true),
53        depends_on: None,
54    };
55
56    if cfg!(target_os = "linux") {
57        // determine linux distribution using os-release
58        if let Ok(os_release) = OsRelease::new() {
59            let os = os_release.id.to_lowercase();
60            let os = os.as_str();
61            match os {
62                "ubuntu" | "debian" | "linuxmint" | "pop" | "elementary" | "zorin" => {
63                    blesh.preinstall = Some("sudo apt-get install -y gawk build-essential".into());
64                }
65                _ => {}
66            }
67        }
68    }
69
70    if cfg!(target_os = "macos") {
71        blesh.preinstall = Some("brew install gawk bash".into());
72        blesh.depends_on = Some(vec!["homebrew".into()]);
73    }
74
75    repo.insert("blesh".into(), blesh);
76    let mut git = IndexMap::new();
77    git.insert("install".into(), GitConfiguration { repo });
78    git
79}