use crate::define_tool;
#[cfg(all(
target_os = "linux",
any(target_arch = "x86_64", target_arch = "aarch64")
))]
use crate::tools::common::run;
use crate::tools::common::{InstallError, has};
#[cfg(all(
target_os = "linux",
any(target_arch = "x86_64", target_arch = "aarch64")
))]
use crate::tools::pinned_binary_installer::AppImagePin;
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
const HEADSCALE_LINUX_X64_URL: &str =
"https://github.com/juanfont/headscale/releases/download/v0.29.1/headscale_0.29.1_linux_amd64";
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
const HEADSCALE_LINUX_X64_SHA256: &str =
"5d24905749e68ee8ddbb3743f4903959878575aeab59c4a41b61d104853d1888";
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
const HEADSCALE_LINUX_ARM64_URL: &str =
"https://github.com/juanfont/headscale/releases/download/v0.29.1/headscale_0.29.1_linux_arm64";
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
const HEADSCALE_LINUX_ARM64_SHA256: &str =
"c1882d7f63e6a7780370bcc20458d9c6c14be72b1743f23f5f950088bd8e24af";
define_tool!(HEADSCALE, {
command: "headscale",
custom_install: install_headscale,
category: "networking",
});
fn install_headscale(_min_hint: &str) -> Result<(), InstallError> {
if has("headscale") {
return Ok(());
}
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
{
let installer = AppImagePin {
name: "headscale",
url: HEADSCALE_LINUX_X64_URL,
sha256: HEADSCALE_LINUX_X64_SHA256,
};
run("sh", &["-c", &installer.shell_command()])?;
return Ok(());
}
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
{
let installer = AppImagePin {
name: "headscale",
url: HEADSCALE_LINUX_ARM64_URL,
sha256: HEADSCALE_LINUX_ARM64_SHA256,
};
run("sh", &["-c", &installer.shell_command()])?;
return Ok(());
}
#[allow(unreachable_code)]
Err(InstallError::Unsupported)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn headscale_registration_shape() {
assert_eq!(HEADSCALE.command, "headscale");
assert!(HEADSCALE.custom_install.is_some());
assert!(HEADSCALE.macos.is_none());
assert!(HEADSCALE.linux.is_none());
assert!(HEADSCALE.windows.is_none());
}
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
#[test]
fn linux_x64_pin_is_well_formed() {
assert_eq!(HEADSCALE_LINUX_X64_SHA256.len(), 64);
assert!(
HEADSCALE_LINUX_X64_SHA256
.chars()
.all(|c| c.is_ascii_hexdigit() && !c.is_ascii_uppercase())
);
assert!(HEADSCALE_LINUX_X64_URL.starts_with("https://"));
assert!(!HEADSCALE_LINUX_X64_URL.contains("/latest/"));
}
#[cfg(all(target_os = "linux", target_arch = "aarch64"))]
#[test]
fn linux_arm64_pin_is_well_formed() {
assert_eq!(HEADSCALE_LINUX_ARM64_SHA256.len(), 64);
assert!(
HEADSCALE_LINUX_ARM64_SHA256
.chars()
.all(|c| c.is_ascii_hexdigit() && !c.is_ascii_uppercase())
);
assert!(HEADSCALE_LINUX_ARM64_URL.starts_with("https://"));
assert!(!HEADSCALE_LINUX_ARM64_URL.contains("/latest/"));
}
}