# Script Reference This document provides a comprehensive reference for all scripts in the ROM Organizer project, organized by category and functionality. ## Core Scripts ### Configuration & Utilities - **`config.sh`** - Main configuration file with path definitions, directory settings, global variables, and DELETE flag initialization - **`utils.sh`** - Shared utility functions used across all scripts (enhanced with DELETE flag support and path validation) - **`logger.sh`** - Logging functions with color-coded output and different log levels - **`config-arrays.sh`** - Dynamic array definitions for platforms, regions, and ROM types - **`preflight-checks.sh`** - **NEW** Comprehensive pre-flight validation system for dependencies, directories, and configuration ### Main Organization Scripts - **`nointro-processor.sh`** - **ENHANCED** Core processor for No-Intro ROM sets with pre-flight checks and improved error handling - **`redump-processor.sh`** - Core processor for Redump ROM sets (disc-based systems) - **`organize-roms.sh`** - Core ROM organization script that sorts ROMs into subdirectories based on region, language, and type - **`delete-listfiles.sh`** - **ENHANCED** Delete ROM files listed in text files with improved validation and whitespace handling - **`link-listfiles.sh`** - Create symbolic links for ROM collections - **`romorganizer.sh`** - Legacy ROM organizer (older version) - **`rommover.sh`** - ROM file movement and management utilities - **`org.sh`** - Organization helper script ## Platform-Specific Build Scripts ### Nintendo Systems - **`build-nes-all-1g1r.sh`** - Nintendo Entertainment System (All regions) - **`build-nes-all.sh`** - Nintendo Entertainment System (All ROMs, no 1G1R filtering) - **`build-nes-usa-1g1r.sh`** - Nintendo Entertainment System (USA) - **`build-snes-all-1g1r.sh`** - Super Nintendo Entertainment System (All regions) - **`build-snes-eng-1g1r.sh`** - Super Nintendo Entertainment System (English) - **`build-snes-usa-1g1r.sh`** - Super Nintendo Entertainment System (USA) - **`build-n64-all-1g1r.sh`** - Nintendo 64 (All regions) - **`build-n64-eng-1g1r.sh`** - Nintendo 64 (English) - **`build-n64-usa-1g1r.sh`** - Nintendo 64 (USA) - **`build-gb-all-1g1r.sh`** - Game Boy (All regions) - **`build-gb-eng-1g1r.sh`** - Game Boy (English) - **`build-gb-usa-1g1r.sh`** - Game Boy (USA) - **`build-gbc-all-1g1r.sh`** - Game Boy Color (All regions) - **`build-gbc-eng-1g1r.sh`** - Game Boy Color (English) - **`build-gbc-usa-1g1r.sh`** - Game Boy Color (USA) - **`build-gba-all-1g1r.sh`** - Game Boy Advance (All regions) - **`build-gba-eng-1g1r.sh`** - Game Boy Advance (English) - **`build-gba-usa-1g1r.sh`** - Game Boy Advance (USA) - **`build-nds-all-1g1r.sh`** - Nintendo DS (All regions) - **`build-nds-eng-1g1r.sh`** - Nintendo DS (English) - **`build-nds-usa-1g1r.sh`** - Nintendo DS (USA) - **`build-3ds-usa-1g1r.sh`** - Nintendo 3DS (USA) ### Sega Systems - **`build-mastersystem-all.1g1r.sh`** - Sega Master System (All regions) - **`build-mastersystem-eng.1g1r.sh`** - Sega Master System (English) - **`build-mastersystem-usa.1g1r.sh`** - Sega Master System (USA) - **`build-megadrive-all.1g1r.sh`** - Sega Genesis/Mega Drive (All regions) - **`build-megadrive-eng.1g1r.sh`** - Sega Genesis/Mega Drive (English) - **`build-megadrive-usa.1g1r.sh`** - Sega Genesis/Mega Drive (USA) - **`build-sega32x-all-1g1r.sh`** - Sega 32X (All regions) - **`build-sega32x-eng-1g1r.sh`** - Sega 32X (English) - **`build-sega32x-usa-1g1r.sh`** - Sega 32X (USA) - **`build-segacd-usa-1g1r.sh`** - Sega CD (USA) - **`build-saturn-usa-1g1r.sh`** - Sega Saturn (USA) - **`build-dreamcast-usa-1g1r.sh`** - Sega Dreamcast (USA) - **`build-gamegear-all-1g1r.sh`** - Sega Game Gear (All regions) - **`build-gamegear-eng-1g1r.sh`** - Sega Game Gear (English) - **`build-gamegear-usa-1g1r.sh`** - Sega Game Gear (USA) - **`build-sg1000-all-1g1r.sh`** - Sega SG-1000 (All regions) - **`build-sg1000-eng-1g1r.sh`** - Sega SG-1000 (English) - **`build-sg1000-usa-1g1r-nosystem.sh`** - Sega SG-1000 (USA, no system folder) ### Atari Systems - **`build-atari2600-all-1g1r.sh`** - Atari 2600 (All regions) - **`build-atari2600-eng-1g1r.sh`** - Atari 2600 (English) - **`build-atari2600-usa-1g1r.sh`** - Atari 2600 (USA) - **`build-atari5200-all-1g1r.sh`** - Atari 5200 (All regions) - **`build-atari5200-eng-1g1r.sh`** - Atari 5200 (English) - **`build-atari5200-usa-1g1r.sh`** - Atari 5200 (USA) - **`build-atari7800-all-1g1r.sh`** - Atari 7800 (All regions) - **`build-atari7800-usa-1g1r.sh`** - Atari 7800 (USA) - **`build-jaguar-usa-1g1r.sh`** - Atari Jaguar (USA) - **`build-lynx-usa-1g1r.sh`** - Atari Lynx (USA) ### Sony Systems - **`build-psx-usa.1g1r.sh`** - Sony PlayStation (USA) - **`build-psp-usa.1g1r.sh`** - Sony PlayStation Portable (USA) - **`build-pspminis-usa.1g1r.sh`** - Sony PlayStation Portable Minis (USA) ### Other Systems - **`build-3do-usa-1g1r.sh`** - 3DO Interactive Multiplayer (USA) - **`build-colecovision-usa-1g1r.sh`** - ColecoVision (USA) - **`build-ngp-usa-1g1r.sh`** - Neo Geo Pocket (USA) - **`build-ngpc-usa-1g1r.sh`** - Neo Geo Pocket Color (USA) - **`build-pcengine-all-1g1r.sh`** - PC Engine/TurboGrafx-16 (All regions) - **`build-pcengine-eng-1g1r.sh`** - PC Engine/TurboGrafx-16 (English) - **`build-pcengine-usa-1g1r.sh`** - PC Engine/TurboGrafx-16 (USA) - **`build-pcenginecd-usa.1g1r.sh`** - PC Engine CD/TurboGrafx-CD (USA) - **`build-vectrex-usa.1g1r.sh`** - Vectrex (USA) - **`build-virtualboy-all-1g1r.sh`** - Nintendo Virtual Boy (All regions) - **`build-virtualboy-eng-1g1r.sh`** - Nintendo Virtual Boy (English) - **`build-virtualboy-usa-1g1r.sh`** - Nintendo Virtual Boy (USA) ## System-Agnostic Processing Scripts - **`nointro-processor.sh`** - **ENHANCED** Core processor for No-Intro ROM sets (cartridge-based systems) with comprehensive pre-flight checks - **`redump-processor.sh`** - Core processor for Redump ROM sets (disc-based systems) ## Format Conversion Scripts - **`convertFromZipCueToChd.sh`** - Convert ZIP+CUE files to CHD format for disc-based games - **`convertFromZipToPS3.sh`** - Convert ZIP files to PlayStation 3 format - **`convertFromZipToXboxIso.sh`** - Convert ZIP files to Xbox ISO format ## Validation & Cleanup Scripts - **`verify-and-clean-roms-zips.sh`** - **ROM-SPECIFIC** DAT-based ZIP validation tool: - Validates ROM ZIP files against DAT file specifications (No-Intro/Redump) - Performs MD5/SHA1 hash verification for ROM authenticity - Automatically deletes ZIPs that don't contain valid ROMs or have hash mismatches - Requires xmlstarlet for DAT file parsing - Usage: `./verify-and-clean-roms-zips.sh ` - **`delete-listfiles.sh`** - **ENHANCED** Delete ROM files listed in text files with improved validation, error handling, and whitespace trimming - **`link-listfiles.sh`** - Create symbolic links for ROM list files - **`remove-media.sh`** - **ENHANCED** Remove media files and cleanup directories for SD card optimization - Supports selective removal of boxart, screenshots, videos, manuals, and other media types - Includes dry-run functionality with detailed preview and size calculations - Automatically cleans XML entries from gamelist.xml with backup creation - Progress indicators and comprehensive logging with ROM Groomer integration - Designed for Batocera/Rocknix systems to reduce storage footprint - **`preflight-checks.sh`** - **NEW** Comprehensive system validation including dependencies, directory structure, and configuration verification ## Remote Source Management - **`rclone-myrient.sh`** - Download ROMs from Myrient archive using rclone - **`debug-copy-source.sh`** - Debug script for copying source files ## Utility & Helper Scripts - **`finalize-36S.sh`** - Finalization script for specific ROM collection (36S) - **`find-kinds.sh`** - Find and categorize ROM types and formats - **`sort2folders.sh`** - Sort ROMs into organized folder structures with smart alphabetical grouping - **`scan-archives.sh`** - **NEW** Comprehensive archive maintenance tool for corruption testing and filename collision detection ### Archive Maintenance Tools - **`sort2folders.sh`** - **ENHANCED** Smart alphabetical ROM organization utility: - Organizes large ROM collections into alphabetically grouped subdirectories - Intelligent sub-letter splitting for massive collections (tested with 5,803+ ROMs) - **FIXED**: Numbers/symbols now correctly grouped in `#` ranges instead of "Other" fallback - Handles special characters and non-alphabetic filenames properly - Configurable grouping sizes and dry-run preview mode - Comprehensive logging and progress tracking - **`scan-archives.sh`** - **NEW** **GENERAL-PURPOSE** Multi-format archive integrity and compatibility checker: - Tests archive corruption for ZIP, 7Z, RAR, TAR, and compressed formats - Detects case-insensitive filename collisions (Windows/FAT32 compatibility) - Parallel processing with 1-8 configurable jobs for faster scanning - Interactive deletion prompts with detailed file information - Support for compound extensions (.tar.gz, .tar.bz2, .tar.xz) - Comprehensive logging integration and dry-run capabilities - Dependency validation for all required archive tools - Use for general archive maintenance (corruption/duplicates) **NOTE:** `scan-archives.sh` and `verify-and-clean-roms-zips.sh` serve different purposes: - `scan-archives.sh`: General archive integrity and duplicate detection - `verify-and-clean-roms-zips.sh`: ROM-specific DAT validation and hash verification ## Test & Development Scripts - **`run-tests.sh`** - **NEW** Main test suite runner for comprehensive testing - **`test-framework.sh`** - **NEW** Testing framework with assertion functions and safe test environments - **`test-utils.sh`** - **NEW** Unit tests for utility functions (copy, move, URL encoding, validation) - **`test-delete-listfiles.sh`** - **NEW** Unit tests for delete functionality with security validation - **`test-organize-roms.sh`** - **NEW** Unit tests for ROM organization features - **`test-integration.sh`** - **NEW** Integration tests for end-to-end workflow validation - **`test-preflight-checks.sh`** - **NEW** Unit tests for pre-flight validation system - **`test.sh`** - General testing script - **`test2.sh`** - Secondary testing script - **`testfile.sh`** - File-specific testing utilities - **`x.sh`** - Experimental/development script ## Naming Conventions ### Build Script Naming Pattern ``` build-[system]-[region]-1g1r.sh ``` Where: - **system**: Platform name (nes, snes, genesis, psx, etc.) - **region**: Target region filter - `usa`: USA releases only - `eng`: English releases (USA + English releases from other regions) - `all`: All regions included - **1g1r**: Indicates "One Game One ROM" filtering is applied ### Region Priority Order 1. **USA** - Highest priority for USA region builds 2. **English** - English language releases from any region 3. **World/Europe** - PAL releases and worldwide releases 4. **Japan** - Japanese releases (when no English equivalent exists) 5. **Other** - All other regional releases ### File Organization - Scripts are organized by functionality and system type - Platform-specific scripts grouped by manufacturer - Utility scripts separated from build scripts - Configuration and core functionality in dedicated files ## Usage Guidelines ### Running Build Scripts All platform-specific build scripts follow the same general pattern: ```bash ./build-[system]-[region]-1g1r.sh ``` ### Configuration Edit `config.sh` to set: - Base directories for ROM organization - Source and destination paths - Platform-specific settings - User preferences ### Dependencies Most scripts require: - bash 4.0+ (for associative arrays) - Standard UNIX utilities (find, sort, uniq, etc.) - 7zip for archive handling - rclone for remote ROM sources (optional) ### Testing The project includes a comprehensive test suite: - **Unit tests**: Test individual functions and components - **Integration tests**: Test complete workflows - **Security tests**: Validate path security and prevent directory traversal - **Error handling tests**: Verify proper error handling and recovery - **Safe test environment**: All tests run in isolated temporary directories Run tests with: ```bash ./run-tests.sh # Complete test suite ./test-utils.sh # Utility function tests ./test-integration.sh # Workflow tests ``` ## Maintenance Notes - **Add new scripts**: Update this reference when creating new scripts - **Version tracking**: Document major changes to existing scripts - **Dependencies**: Note any new dependencies required by scripts - **Platform additions**: Update platform categories when adding new systems --- *Last updated: June 22, 2025* *Total scripts documented: 160 production scripts (97 build + 63 core/utility)* *All scripts including tests: 176* *Testing framework: 14 test files providing comprehensive coverage*