From 3c6c4a50b654cabe7e88570c7e9ff583dac1f933 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 21:55:29 +0000 Subject: [PATCH 1/7] Initial plan From d76630c02a42350c112ea2ddaa8924411ade5918 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 21:57:26 +0000 Subject: [PATCH 2/7] Fix: Update both global.bootgame.path and global.bootgame.cmd Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com> --- random_game.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/random_game.sh b/random_game.sh index e4b9a1d..88d88d5 100644 --- a/random_game.sh +++ b/random_game.sh @@ -88,7 +88,10 @@ if [ -z "$old_game" ]; then fi # Replace the old game with the new game in batocera.conf -# Use a more precise pattern that matches the entire line +# Update global.bootgame.cmd - use a more precise pattern that matches the entire line sed -i "s|^\(global\.bootgame\.cmd.*\)${old_game}|\1${new_game}|g" /userdata/system/batocera.conf +# Update global.bootgame.path to point to the new game +sed -i "s|^global\.bootgame\.path=.*|global.bootgame.path=${new_game}|g" /userdata/system/batocera.conf + echo "Selected random game: $new_game" From 92bbc8d80c0897742ce7231115b1c02a13fe88c3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 21:58:01 +0000 Subject: [PATCH 3/7] Remove redundant global flag in sed command Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com> --- random_game.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/random_game.sh b/random_game.sh index 88d88d5..6f9cd51 100644 --- a/random_game.sh +++ b/random_game.sh @@ -92,6 +92,6 @@ fi sed -i "s|^\(global\.bootgame\.cmd.*\)${old_game}|\1${new_game}|g" /userdata/system/batocera.conf # Update global.bootgame.path to point to the new game -sed -i "s|^global\.bootgame\.path=.*|global.bootgame.path=${new_game}|g" /userdata/system/batocera.conf +sed -i "s|^global\.bootgame\.path=.*|global.bootgame.path=${new_game}|" /userdata/system/batocera.conf echo "Selected random game: $new_game" From 20f1f9d179fa0287046d628a105b33a7422d0f2c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 22:27:00 +0000 Subject: [PATCH 4/7] Fix: Update both -rom and -systemname parameters in global.bootgame.cmd Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com> --- random_game.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/random_game.sh b/random_game.sh index 6f9cd51..87831f7 100644 --- a/random_game.sh +++ b/random_game.sh @@ -77,19 +77,19 @@ fi # Randomly select a game new_game="${files[RANDOM % ${#files[@]}]}" -# Get the current boot game from batocera.conf -old_game=$(grep global.bootgame.cmd /userdata/system/batocera.conf | awk '{print $NF}') - -# Check if old_game was found -if [ -z "$old_game" ]; then +# Check if boot game is configured in batocera.conf +if ! grep -q "global.bootgame.cmd" /userdata/system/batocera.conf; then echo "Error: No boot game configured in batocera.conf" echo "Please configure a game to start on boot first, then run this script again." exit 1 fi # Replace the old game with the new game in batocera.conf -# Update global.bootgame.cmd - use a more precise pattern that matches the entire line -sed -i "s|^\(global\.bootgame\.cmd.*\)${old_game}|\1${new_game}|g" /userdata/system/batocera.conf +# Update the -rom parameter in global.bootgame.cmd +sed -i "s|\(-rom \)[^ ]*|\1${new_game}|" /userdata/system/batocera.conf + +# Update the -systemname parameter in global.bootgame.cmd +sed -i "s|\(-systemname \)[^ ]*|\1${new_game}|" /userdata/system/batocera.conf # Update global.bootgame.path to point to the new game sed -i "s|^global\.bootgame\.path=.*|global.bootgame.path=${new_game}|" /userdata/system/batocera.conf From 36f2337e183bde3b618719f317faf6e0fd1b0b24 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 22:29:02 +0000 Subject: [PATCH 5/7] Add proper escaping for special characters in game paths Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com> --- random_game.sh | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/random_game.sh b/random_game.sh index 87831f7..6432c9e 100644 --- a/random_game.sh +++ b/random_game.sh @@ -77,6 +77,10 @@ fi # Randomly select a game new_game="${files[RANDOM % ${#files[@]}]}" +# Escape special characters for sed replacement string +# This handles characters like &, \, and / that have special meaning in sed +escaped_game=$(echo "$new_game" | sed 's/[&/\]/\\&/g') + # Check if boot game is configured in batocera.conf if ! grep -q "global.bootgame.cmd" /userdata/system/batocera.conf; then echo "Error: No boot game configured in batocera.conf" @@ -86,12 +90,12 @@ fi # Replace the old game with the new game in batocera.conf # Update the -rom parameter in global.bootgame.cmd -sed -i "s|\(-rom \)[^ ]*|\1${new_game}|" /userdata/system/batocera.conf +sed -i "s|\(-rom \)[^ ]*|\1${escaped_game}|" /userdata/system/batocera.conf # Update the -systemname parameter in global.bootgame.cmd -sed -i "s|\(-systemname \)[^ ]*|\1${new_game}|" /userdata/system/batocera.conf +sed -i "s|\(-systemname \)[^ ]*|\1${escaped_game}|" /userdata/system/batocera.conf # Update global.bootgame.path to point to the new game -sed -i "s|^global\.bootgame\.path=.*|global.bootgame.path=${new_game}|" /userdata/system/batocera.conf +sed -i "s|^global\.bootgame\.path=.*|global.bootgame.path=${escaped_game}|" /userdata/system/batocera.conf echo "Selected random game: $new_game" From 06a1e9baa070c7832337a919c2f156f5b15b7a5c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 23:41:43 +0000 Subject: [PATCH 6/7] Fix: Update system-specific game settings in batocera.conf Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com> --- random_game.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/random_game.sh b/random_game.sh index 6432c9e..3f86214 100644 --- a/random_game.sh +++ b/random_game.sh @@ -81,6 +81,10 @@ new_game="${files[RANDOM % ${#files[@]}]}" # This handles characters like &, \, and / that have special meaning in sed escaped_game=$(echo "$new_game" | sed 's/[&/\]/\\&/g') +# Extract just the filename from the full path for game-specific settings +new_game_file=$(basename "$new_game") +escaped_filename=$(echo "$new_game_file" | sed 's/[&/\]/\\&/g') + # Check if boot game is configured in batocera.conf if ! grep -q "global.bootgame.cmd" /userdata/system/batocera.conf; then echo "Error: No boot game configured in batocera.conf" @@ -88,6 +92,9 @@ if ! grep -q "global.bootgame.cmd" /userdata/system/batocera.conf; then exit 1 fi +# Extract the system name from the boot command +system=$(grep "global.bootgame.cmd" /userdata/system/batocera.conf | grep -oP '\-system \K[^ ]+') + # Replace the old game with the new game in batocera.conf # Update the -rom parameter in global.bootgame.cmd sed -i "s|\(-rom \)[^ ]*|\1${escaped_game}|" /userdata/system/batocera.conf @@ -98,4 +105,7 @@ sed -i "s|\(-systemname \)[^ ]*|\1${escaped_game}|" /userdata/system/batocera.co # Update global.bootgame.path to point to the new game sed -i "s|^global\.bootgame\.path=.*|global.bootgame.path=${escaped_game}|" /userdata/system/batocera.conf +# Update any system-specific game settings (e.g., mame["game.zip"].setting=value) +sed -i "s|^${system}\[\"[^\"]*\"\]|${system}[\"${escaped_filename}\"]|g" /userdata/system/batocera.conf + echo "Selected random game: $new_game" From bf0b963bc5d42967397e11cfdb992a5e06a82019 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Tue, 17 Feb 2026 23:43:01 +0000 Subject: [PATCH 7/7] Add validation and escaping for system name extraction Co-authored-by: thehack904 <35552907+thehack904@users.noreply.github.com> --- random_game.sh | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/random_game.sh b/random_game.sh index 3f86214..b96ccf7 100644 --- a/random_game.sh +++ b/random_game.sh @@ -95,6 +95,17 @@ fi # Extract the system name from the boot command system=$(grep "global.bootgame.cmd" /userdata/system/batocera.conf | grep -oP '\-system \K[^ ]+') +# Validate that system was extracted successfully +if [ -z "$system" ]; then + echo "Warning: Could not extract system name from boot command" + echo "Skipping system-specific settings update" + system_update_needed=false +else + # Escape special regex characters in system name for safe sed usage + escaped_system=$(echo "$system" | sed 's/[.[\*^$]/\\&/g') + system_update_needed=true +fi + # Replace the old game with the new game in batocera.conf # Update the -rom parameter in global.bootgame.cmd sed -i "s|\(-rom \)[^ ]*|\1${escaped_game}|" /userdata/system/batocera.conf @@ -106,6 +117,8 @@ sed -i "s|\(-systemname \)[^ ]*|\1${escaped_game}|" /userdata/system/batocera.co sed -i "s|^global\.bootgame\.path=.*|global.bootgame.path=${escaped_game}|" /userdata/system/batocera.conf # Update any system-specific game settings (e.g., mame["game.zip"].setting=value) -sed -i "s|^${system}\[\"[^\"]*\"\]|${system}[\"${escaped_filename}\"]|g" /userdata/system/batocera.conf +if [ "$system_update_needed" = true ]; then + sed -i "s|^${escaped_system}\[\"[^\"]*\"\]|${escaped_system}[\"${escaped_filename}\"]|g" /userdata/system/batocera.conf +fi echo "Selected random game: $new_game"