This commit is contained in:
MangoPig
2026-06-01 00:28:14 +01:00
parent 58531bf579
commit 52054493cc
8 changed files with 231 additions and 40 deletions

View File

@@ -22,6 +22,17 @@ ensure_deps() {
fi
}
detect_platform() {
case "$(uname -s)" in
Linux) printf 'linux\n' ;;
Darwin) printf 'macos\n' ;;
*)
printf 'Unsupported operating system: %s\n' "$(uname -s)" >&2
exit 1
;;
esac
}
detect_arch() {
case "$(uname -m)" in
x86_64) printf 'x86_64\n' ;;
@@ -35,8 +46,9 @@ detect_arch() {
install_tool() {
local tool="$1"
local arch version owner repo asset binary_rel url tmp_dir archive_path extracted_path target_path
local platform arch version owner repo asset binary_rel formula url tmp_dir archive_path extracted_path target_path installed_path
platform="$(detect_platform)"
arch="$(detect_arch)"
if ! jq -e --arg tool "$tool" '.[$tool]' "$MANIFEST" >/dev/null; then
@@ -47,11 +59,39 @@ install_tool() {
version="$(jq -r --arg tool "$tool" '.[$tool].version' "$MANIFEST")"
owner="$(jq -r --arg tool "$tool" '.[$tool].owner' "$MANIFEST")"
repo="$(jq -r --arg tool "$tool" '.[$tool].repo' "$MANIFEST")"
asset="$(jq -r --arg tool "$tool" --arg arch "$arch" '.[$tool].linux[$arch].asset' "$MANIFEST")"
binary_rel="$(jq -r --arg tool "$tool" --arg arch "$arch" '.[$tool].linux[$arch].binary' "$MANIFEST")"
formula="$(jq -r --arg tool "$tool" --arg platform "$platform" '.[$tool][$platform].formula // empty' "$MANIFEST")"
if [ -z "$asset" ] || [ "$asset" = "null" ] || [ -z "$binary_rel" ] || [ "$binary_rel" = "null" ]; then
printf 'No Linux asset mapping for %s on %s\n' "$tool" "$arch" >&2
if [ -n "$formula" ]; then
if ! command -v brew >/dev/null 2>&1; then
printf 'Homebrew is required to install %s on macOS\n' "$tool" >&2
exit 1
fi
if ! brew list --formula "$formula" >/dev/null 2>&1; then
printf 'Installing %s via Homebrew formula %s\n' "$tool" "$formula"
brew install "$formula"
else
printf '%s already installed via Homebrew\n' "$tool"
fi
installed_path="$(command -v "$tool" || true)"
if [ -z "$installed_path" ]; then
printf 'Installed formula %s but %s is not on PATH\n' "$formula" "$tool" >&2
exit 1
fi
mkdir -p "$TARGET_DIR"
target_path="$TARGET_DIR/$tool"
ln -sf "$installed_path" "$target_path"
printf 'Linked %s -> %s\n' "$target_path" "$installed_path"
return 0
fi
asset="$(jq -r --arg tool "$tool" --arg platform "$platform" --arg arch "$arch" '.[$tool][$platform][$arch].asset // empty' "$MANIFEST")"
binary_rel="$(jq -r --arg tool "$tool" --arg platform "$platform" --arg arch "$arch" '.[$tool][$platform][$arch].binary // empty' "$MANIFEST")"
if [ -z "$asset" ] || [ -z "$binary_rel" ]; then
printf 'No %s asset mapping for %s on %s\n' "$platform" "$tool" "$arch" >&2
exit 1
fi