idt/installers/
marksman.rs1use std::path::Path;
2
3use ytil_sys::Arch;
4use ytil_sys::Os;
5use ytil_sys::SysInfo;
6
7use crate::downloaders::http::deflate::HttpDeflateOption;
8use crate::installers::Installer;
9use crate::installers::SystemDependent;
10
11pub struct Marksman<'a> {
12 pub bin_dir: &'a Path,
13 pub sys_info: &'a SysInfo,
14}
15
16impl SystemDependent for Marksman<'_> {
17 fn target_arch_and_os(&self) -> (&str, &str) {
18 let SysInfo { os, arch } = self.sys_info;
19 let arch_suffix = match (os, arch) {
20 (Os::MacOs, Arch::Arm | Arch::X86) => "",
21 (Os::Linux, Arch::Arm) => "-arm64",
22 (Os::Linux, Arch::X86) => "-x64",
23 };
24 let os = match os {
25 Os::MacOs => "macos",
26 Os::Linux => "linux",
27 };
28 (arch_suffix, os)
29 }
30}
31
32impl Installer for Marksman<'_> {
33 fn bin_name(&self) -> &'static str {
34 "marksman"
35 }
36
37 fn should_verify_checksum(&self) -> bool {
38 false
39 }
40
41 fn install(&self) -> rootcause::Result<()> {
42 let (arch, os) = self.target_arch_and_os();
43 let repo = format!("artempyanykh/{}", self.bin_name());
44 let latest_release = crate::downloaders::http::github::get_latest_release_tag(&repo)?;
45
46 let target = crate::downloaders::http::run(
47 &format!(
48 "https://github.com/{repo}/releases/download/{latest_release}/{0}-{os}{arch}",
49 self.bin_name()
50 ),
51 &HttpDeflateOption::WriteTo {
52 dest_path: &self.bin_dir.join(self.bin_name()),
53 },
54 None,
55 )?;
56
57 ytil_sys::file::chmod_x(&target)?;
58
59 Ok(())
60 }
61}