feat: Dynamic package registry
This commit is contained in:
56
scripts/generate_registry.sh
Executable file
56
scripts/generate_registry.sh
Executable 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."
|
||||
@@ -4,6 +4,12 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# Generate the registry dynamically and stage it
|
||||
if [ -f "./scripts/generate_registry.sh" ]; then
|
||||
./scripts/generate_registry.sh
|
||||
git add registry.sh
|
||||
fi
|
||||
|
||||
VERSION_FILE="VERSION"
|
||||
|
||||
if [ ! -f "$VERSION_FILE" ]; then
|
||||
|
||||
Reference in New Issue
Block a user