idt/installers/
shellcheck.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 Shellcheck<'a> {
12 pub bin_dir: &'a Path,
13 pub sys_info: &'a SysInfo,
14}
15
16impl SystemDependent for Shellcheck<'_> {
17 fn target_arch_and_os(&self) -> (&str, &str) {
18 let SysInfo { os, arch } = self.sys_info;
19 let os = match os {
20 Os::MacOs => "darwin",
21 Os::Linux => "linux",
22 };
23 let arch = match arch {
24 Arch::Arm => "aarch64",
25 Arch::X86 => "x86_64",
26 };
27 (arch, os)
28 }
29}
30
31impl Installer for Shellcheck<'_> {
32 fn bin_name(&self) -> &'static str {
33 "shellcheck"
34 }
35
36 fn should_verify_checksum(&self) -> bool {
37 false
38 }
39
40 fn install(&self) -> rootcause::Result<()> {
41 let (arch, os) = self.target_arch_and_os();
42
43 let repo = format!("koalaman/{}", self.bin_name());
44 let latest_release = crate::downloaders::http::github::get_latest_release_tag(&repo)?;
45 let dest_dir = Path::new("/tmp");
46
47 crate::downloaders::http::run(
48 &format!(
49 "https://github.com/{repo}/releases/download/{latest_release}/{}-{latest_release}.{os}.{arch}.tar.xz",
50 self.bin_name()
51 ),
52 &HttpDeflateOption::ExtractTarXz {
53 dest_dir,
54 dest_name: None,
55 },
56 None,
57 )?;
58
59 let target = self.bin_dir.join(self.bin_name());
60 std::fs::rename(
61 dest_dir
62 .join(format!("{0}-{latest_release}", self.bin_name()))
63 .join(self.bin_name()),
64 &target,
65 )?;
66 ytil_sys::file::chmod_x(target)?;
67
68 Ok(())
69 }
70}