57 lines
1.7 KiB
Bash
Executable File
57 lines
1.7 KiB
Bash
Executable File
#!/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."
|