#!/bin/bash ################################################################################ # Script: fix-build-scripts.sh # Description: Fixes build scripts that have incorrect SYSTEM and SOURCESYSTEM # configurations due to copy-paste errors from master system template. # # Usage: ./fix-build-scripts.sh ################################################################################ # Determine the directory of the current script SCRIPT_DIR="$(dirname "$(realpath "$0")")" # Determine the project root directory PROJECT_ROOT="$(dirname "$SCRIPT_DIR")" # Load configuration and logger source "${PROJECT_ROOT}/core/config.sh" source "${PROJECT_ROOT}/core/logger.sh" log "INFO" "Starting build script fixes..." # Define correct configurations for each system declare -A SYSTEM_CONFIGS=( # Nintendo Systems ["snes"]="snes|Nintendo - Super Nintendo Entertainment System|Super Nintendo Entertainment System (SNES)" ["n64"]="n64|Nintendo - Nintendo 64 (BigEndian)|Nintendo 64" ["gb"]="gb|Nintendo - Game Boy|Game Boy" ["gbc"]="gbc|Nintendo - Game Boy Color|Game Boy Color" ["gba"]="gba|Nintendo - Game Boy Advance|Game Boy Advance" ["nds"]="nds|Nintendo - Nintendo DS (Decrypted)|Nintendo DS" ["3ds"]="3ds|Nintendo - Nintendo 3DS (Decrypted)|Nintendo 3DS" # Sega Systems ["megadrive"]="megadrive|Sega - Mega Drive - Genesis|Sega Mega Drive / Genesis" ["sega32x"]="sega32x|Sega - 32X|Sega 32X" ["gamegear"]="gamegear|Sega - Game Gear|Sega Game Gear" ["sg1000"]="sg1000|Sega - SG-1000|Sega SG-1000" ) # Function to fix a build script fix_build_script() { local script_file="$1" local system_key="$2" if [[ -n "${SYSTEM_CONFIGS[$system_key]}" ]]; then IFS='|' read -r correct_system correct_sourcesystem description <<< "${SYSTEM_CONFIGS[$system_key]}" log "INFO" "Fixing $script_file for system: $system_key" # Fix the description sed -i "s/Sega Master System/$description/g" "$script_file" # Fix the SYSTEM variable sed -i "s/SYSTEM=\"mastersystem\"/SYSTEM=\"$correct_system\"/g" "$script_file" # Fix the SOURCESYSTEM variable sed -i "s|SOURCESYSTEM=\"Sega - Master System - Mark III\"|SOURCESYSTEM=\"$correct_sourcesystem\"|g" "$script_file" log "INFO" "Fixed $script_file" else log "ERROR" "No configuration found for system: $system_key" fi } # Process each problematic build script for script_file in build-*.sh; do if [[ "$script_file" == *"mastersystem"* ]]; then continue # Skip actual master system scripts fi if grep -q "mastersystem" "$script_file"; then # Extract system name from filename if [[ "$script_file" =~ build-([^-]+)- ]]; then system_key="${BASH_REMATCH[1]}" fix_build_script "$script_file" "$system_key" else log "ERROR" "Could not extract system name from: $script_file" fi fi done log "INFO" "Build script fixes completed!"