Update install hooks to respect XYZ_BINARY env vars

- All install hooks now respect their respective XYZ_BINARY env vars
  (e.g., WGET_BINARY, CHROME_BINARY, YTDLP_BINARY, etc.)
- Support both absolute paths (/usr/bin/wget2) and binary names (wget2)
- Dynamic bin_name used in Dependency JSONL output
- Updated 11 install hooks to follow the new pattern
- Mark checklist items as complete in TODO_hook_architecture.md
This commit is contained in:
Claude
2025-12-27 10:12:45 +00:00
parent 8c846b7d1c
commit e3ba599812
12 changed files with 339 additions and 85 deletions

View File

@@ -1,25 +1,43 @@
#!/usr/bin/env python3
"""
Validation hook for wget binary.
Install hook for wget binary.
Runs at crawl start to verify wget is available.
Outputs JSONL for InstalledBinary and Machine config updates.
Respects WGET_BINARY env var for custom binary paths.
"""
import os
import sys
import json
from pathlib import Path
def find_wget() -> dict | None:
"""Find wget binary using abx-pkg."""
"""Find wget binary using abx-pkg, respecting WGET_BINARY env var."""
try:
from abx_pkg import Binary, EnvProvider
binary = Binary(name='wget', binproviders=[EnvProvider()])
# Check if user has configured a custom binary
configured_binary = os.environ.get('WGET_BINARY', '').strip()
if configured_binary:
# User specified a custom binary path or name
if '/' in configured_binary:
# Absolute path - extract name from path
bin_name = Path(configured_binary).name
else:
# Just a binary name
bin_name = configured_binary
else:
# Default to 'wget'
bin_name = 'wget'
binary = Binary(name=bin_name, binproviders=[EnvProvider()])
loaded = binary.load()
if loaded and loaded.abspath:
return {
'name': 'wget',
'name': bin_name,
'abspath': str(loaded.abspath),
'version': str(loaded.version) if loaded.version else None,
'sha256': loaded.sha256 if hasattr(loaded, 'sha256') else None,
@@ -32,7 +50,15 @@ def find_wget() -> dict | None:
def main():
"""Validate wget binary and output JSONL."""
"""Find wget binary and output JSONL."""
# Determine binary name from config
configured_binary = os.environ.get('WGET_BINARY', '').strip()
if configured_binary and '/' in configured_binary:
bin_name = Path(configured_binary).name
elif configured_binary:
bin_name = configured_binary
else:
bin_name = 'wget'
result = find_wget()
@@ -65,15 +91,15 @@ def main():
sys.exit(0)
else:
# Output Dependency request
# Output Dependency request (uses configured bin_name)
print(json.dumps({
'type': 'Dependency',
'bin_name': 'wget',
'bin_name': bin_name,
'bin_providers': 'apt,brew,env',
}))
# Exit non-zero to indicate binary not found
print(f"wget binary not found", file=sys.stderr)
print(f"{bin_name} binary not found", file=sys.stderr)
sys.exit(1)