#!/bin/bash # Script: build-nointro-system.sh # CMD: ./build-nointro-system.sh -i -d -s nes -f usa.1g1r -ss myrient.erista.me/files/No-Intro -sy "Nintendo - Nintendo Entertainment System (Headered)" -l -r -k -u # Handle Extra Directories # Move translations into source/extra/translations/system # extras into source/extra/system # This is where non no-intro roms can hange out. If they are there they can be copied from during list copies. # Would allow pulling roms from more than just source or filtered areas such as Pier Solar.chd and Doom Resurection # Exit on any error set -e # Determine the directory of the current script SCRIPT_DIR="$(dirname "$(realpath "$0")")" # Load configuration from the script's directory source "${SCRIPT_DIR}/config.sh" # Set file permissions umask 000 # Function to copy files from source to destination copy_files() { local src=$1 local dest=$2 echo $1 - $2 # Check if the destination directory is within EMUBASEDIR if [[ "$dest" != "$EMUBASEDIR"* ]]; then echo "Error: Destination directory is not within EMUBASEDIR. Aborting." exit 1 fi if [ "$DELETE" = true ]; then rm -rf "$dest"/* # Delete contents of destination directory if DELETE flag is set fi mkdir -p "$dest" # Create destination directory if it doesn't exist cp -r "$src"/* "$dest/" # Copy files from source to destination recursively } # Function to run a script with given parameters run_script() { local script=$1 shift # Shift the arguments to remove the first one (script) #echo "Running script: $script with parameters: $@" "$script" "$@" } interactive_step() { local step=$1 local description=$2 shift 2 local command="$@" if [ "$INTERACTIVE" = true ]; then echo -e "\033[1;34m$step - $description\033[0m" # Display step description in blue read -p "Press [Enter] to continue, [S] to skip..." choice if [ "$choice" = "S" ] || [ "$choice" = "s" ]; then echo "Skipping $step" return fi else echo "$step - $description" fi # Debug statement to show the command before executing echo "Debug: About to execute command: $command" eval "$command" # Execute the command } # Check for interactive, delete, and other modes INTERACTIVE=false DELETE=false LANGUAGE=false REGION=false KIND=false USA=false while [[ "$#" -gt 0 ]]; do case $1 in -i|--interactive) INTERACTIVE=true ;; -d|--delete) DELETE=true ;; -s|--system) SYSTEM="$2"; shift ;; -f|--filter) FILTER="$2"; shift ;; -ss|--sourcesite) SOURCESITE="$2"; shift ;; -sy|--sourcesystem) SOURCESYSTEM="$2"; shift ;; -l|--language) LANGUAGE=true ;; -r|--region) REGION=true ;; -k|--kind) KIND=true ;; -u|--usa) USA=true ;; *) echo "Unknown parameter passed: $1"; exit 1 ;; esac shift done # Validate required parameters if [ -z "$SYSTEM" ] || [ -z "$FILTER" ] || [ -z "$SOURCESITE" ] || [ -z "$SOURCESYSTEM" ]; then echo "Missing required parameters." exit 1 fi # Define directories based on variables SOURCESYSTEMDIR="${SOURCEBASEDIR}/${SOURCESITE}/${SOURCESYSTEM}" FILTERSYSTEMDIR="${FILTERBASEDIR}/${SOURCESYSTEM}.${FILTER}" ORGSYSTEMDIR="${ORGBASEDIR}/${SYSTEM}.${FILTER}" STAGEFILTERDIR="${STAGEBASEDIR}/${FILTER}" STAGESYSTEMDIR="${STAGEFILTERDIR}/${SYSTEM}" SHAREFILTERDIR="${SHAREBASEDIR}/${FILTER}" SHARESYSTEMDIR="${SHAREFILTERDIR}/${SYSTEM}" # Step functions step1() { interactive_step "STEP 1" "Copy Source to Filter Directory" "copy_files \"$SOURCESYSTEMDIR\" \"$FILTERSYSTEMDIR\"" } step2() { interactive_step "STEP 2" "Filter ROMs to just the ones that we want" "echo 'Manual: Use Rom Manager to filter ROMs in $FILTERSYSTEMDIR based on dat for $FILTER'; read -p 'Press [Enter] key when done or [Ctrl+C] to exit...'" } step3() { interactive_step "STEP 3" "Copy Filtered ROMs to Organization Directory" "copy_files \"$FILTERSYSTEMDIR\" \"$ORGSYSTEMDIR\"" } step4() { interactive_step "STEP 4" "Delete Problematic ROMs - Second Filtering" run_script "${EMUBINDIR}/delete-listfiles.sh" "$ORGSYSTEMDIR" "${EMULISTSDIR}/${SYSTEM}.delete" } step5() { # Construct the parameters for organize-roms.sh local params=("$ORGSYSTEMDIR") if [ "$LANGUAGE" = true ]; then params+=("-l") fi if [ "$REGION" = true ]; then params+=("-r") fi if [ "$KIND" = true ]; then params+=("-k") fi if [ "$USA" = true ]; then params+=("-u") fi echo "params: ${params[@]}" interactive_step "STEP 5" "Organize ROMs into subdirectories" ${EMUBINDIR}/organize-roms.sh "${params[@]}" } step6() { # Find all relevant files excluding $SYSTEM.delete for file in "${EMULISTSDIR}/${SYSTEM}."*; do filename=$(basename "$file") # Skip $SYSTEM.delete files if [[ "$filename" == "${SYSTEM}.delete" ]]; then continue fi # Skip $SYSTEM.eng files if [[ "$filename" == "${SYSTEM}.eng" ]]; then continue fi # Extract the part after $SYSTEM. and replace '-' with ' ' dir_name="${filename#${SYSTEM}.}" dir_name="${dir_name//-/ }" # Create the directory and run the link-listfiles.sh script # get the roms from source instead of filter in order to have the best change of finding. #interactive_step "STEP 6 - Adding extra games" "Add extra games from $filename" run_script "${EMUBINDIR}/link-listfiles.sh" "$file" "\"$SOURCESYSTEMDIR\"" "\"${ORGSYSTEMDIR}/${dir_name}\"" interactive_step "STEP 6 - Adding extra games" "Add extra games from $filename" run_script "${EMUBINDIR}/link-listfiles.sh" "$file" "\"$FILTERSYSTEMDIR\"" "\"${ORGSYSTEMDIR}/${dir_name}\"" done # Handle english translations #Usage: /data/emu/bin/link-listfiles.sh #Script name: /data/emu/bin/link-listfiles.sh #Parameters: "/data/emu/lists/mastersystem.eng" "/data/emu/source/translations/mastersystem.eng" "/data/emu/org/mastersystem.usa.1g1r/English Translations" # ToDo: Convert to interactive_step format echo before english interactive_step "STEP 6a - Adding Translations" "Add extra games from $filename" run_script "${EMUBINDIR}/link-listfiles.sh" "${EMULISTSDIR}/${SYSTEM}.eng" "\"$SOURCEBASEDIR/translations/${SYSTEM}.eng\"" "\"${ORGSYSTEMDIR}/English Translations\"" #${EMUBINDIR}/link-listfiles.sh \"${EMULISTSDIR}/${SYSTEM}.eng\" \"${SOURCEBASEDIR}/translations/${SYSTEM}.eng\" \""${ORGSYSTEMDIR}/English-Translations\"" echo excellent! } step7() { interactive_step "STEP 7" "Copy Organized Games to Stage Directory" "copy_files \"$ORGSYSTEMDIR\" \"$STAGESYSTEMDIR\"" } step8() { echo "STEP 8 - Set ROM link" if [ "$INTERACTIVE" = true ]; then read -p "Press [Enter] to continue, [S] to skip..." choice if [ "$choice" = "S" ] || [ "$choice" = "s" ]; then echo "Skipping STEP 8" return fi fi if [ -L "$EMUROMSDIR" ]; then rm "$EMUROMSDIR" fi ln -s "$STAGEFILTERDIR" "$EMUROMSDIR" } step9() { interactive_step "STEP 9" "Run AARM on new data" "echo 'Manual: Use AARM to generate metadata for $EMUROMSDIR/$SYSTEM'; read -p 'Press [Enter] key when done or [Ctrl+C] to exit...'" } step10() { interactive_step "STEP 10" "Copy Staged Games to Share Directory" "copy_files \"$STAGESYSTEMDIR\" \"$SHARESYSTEMDIR\"" } # Execute steps step1 step2 step3 step4 step5 step6 step7 step8 step9 step10