feat: Dynamic package registry

This commit is contained in:
2026-06-20 19:05:20 +05:30
parent bad324a5cd
commit e658d6d375
20 changed files with 210 additions and 53 deletions

56
scripts/generate_registry.sh Executable file
View File

@@ -0,0 +1,56 @@
#!/usr/bin/env bash
# Automatically generate registry.sh from installer headers.
set -euo pipefail
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_DIR="$(dirname "$SCRIPT_DIR")"
INSTALLERS_DIR="$REPO_DIR/installers"
REGISTRY_FILE="$REPO_DIR/registry.sh"
echo "==> Generating registry.sh..."
# Temporary arrays
declare -A tools_desc
declare -A tools_disp
keys=()
for f in "$INSTALLERS_DIR"/install_*.sh; do
[ -f "$f" ] || continue
tool=$(grep -E "^# Tool:" "$f" | head -n1 | sed -E 's/^# Tool:\s*//I')
disp_name=$(grep -E "^# DisplayName:" "$f" | head -n1 | sed -E 's/^# DisplayName:\s*//I')
desc=$(grep -E "^# Description:" "$f" | head -n1 | sed -E 's/^# Description:\s*//I')
if [ -n "$tool" ]; then
tools_desc["$tool"]="$desc"
tools_disp["$tool"]="${disp_name:-$tool}"
keys+=("$tool")
fi
done
# Sort keys alphabetically
sorted_keys=($(printf '%s\n' "${keys[@]}" | sort))
{
echo "# This file is auto-generated by scripts/generate_registry.sh. Do not edit manually."
echo ""
echo "declare -A INSTALLERS=("
for k in "${sorted_keys[@]}"; do
# Escape any double quotes in description
escaped_desc=$(echo "${tools_desc[$k]}" | sed 's/"/\\"/g')
echo " [$k]=\"$escaped_desc\""
done
echo ")"
echo ""
echo "declare -A INSTALLER_DISPLAYS=("
for k in "${sorted_keys[@]}"; do
escaped_disp=$(echo "${tools_disp[$k]}" | sed 's/"/\\"/g')
echo " [$k]=\"$escaped_disp\""
done
echo ")"
echo ""
# Format keys output as space-separated list in array declaration format
echo "INSTALLER_KEYS=(${sorted_keys[*]})"
} > "$REGISTRY_FILE"
echo "==> registry.sh successfully generated with ${#sorted_keys[@]} tools."