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