Skip to content

Commit

Permalink
New RA config scripts
Browse files Browse the repository at this point in the history
batocera-settings-set is finally not compatible for RA config (spaces are required before and after the "=")

We will use CrossMix own script finally : get_ra_cfg.sh and set_ra_cfg.sh
Usage:
set_ra_cfg.sh <config_file> <key1> <value1> [<key2> <value2> ...]
get_ra_cfg.sh <config_file> <key>
  • Loading branch information
cizia64 committed Jun 28, 2024
1 parent 3fc60f3 commit 70e1b2e
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Emus/MD/genplus_wide.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ source /mnt/SDCARD/System/usr/trimui/scripts/FolderOverrideFinder.sh
RA_DIR=/mnt/SDCARD/RetroArch
EMU_DIR=/mnt/SDCARD/Emus/MD

/mnt/SDCARD/System/bin/batocera-settings-set -f "/mnt/SDCARD/RetroArch/.retroarch/config/Genesis Plus GX Wide/MD.cfg" input_overlay_enable \""false\""
/mnt/SDCARD/System/usr/trimui/scripts/set_ra_cfg.sh "/mnt/SDCARD/RetroArch/.retroarch/config/Genesis Plus GX Wide/MD.cfg" "input_overlay_enable" "false"

cd $RA_DIR/

Expand Down
Binary file removed System/bin/batocera-settings-get
Binary file not shown.
Binary file removed System/bin/batocera-settings-set
Binary file not shown.
23 changes: 23 additions & 0 deletions System/usr/trimui/scripts/get_ra_cfg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/bash

config_file="$1"
key="$2"

if [ "$#" -ne 2 ]; then
echo "Usage: $0 <config_file> <key>"
exit 1
fi

if [ ! -f "$config_file" ]; then
echo "Config file $config_file does not exist."
exit 1
fi

# Extract the value of the key from the configuration file
value=$(grep "^[[:space:]]*$key[[:space:]]*=" "$config_file" | sed 's/^[[:space:]]*'"$key"'[[:space:]]*=[[:space:]]*"*\([^"]*\)"*/\1/')

if [ -z "$value" ]; then
echo "Key '$key' not found in $config_file"
else
echo "$key = \"$value\""
fi
36 changes: 36 additions & 0 deletions System/usr/trimui/scripts/set_ra_cfg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/bash

config_file="$1"
shift 1

if [ "$#" -lt 2 ] || [ $(($# % 2)) -ne 0 ]; then
echo "Usage: $0 <config_file> <key1> <value1> [<key2> <value2> ...]"
exit 1
fi

if [ ! -f "$config_file" ]; then
echo "Config file $config_file does not exist."
exit 1
fi

# Loop through pairs of key-value arguments
while [ "$#" -ge 2 ]; do
key="$1"
value="$2"

# Format the value with quotes if necessary
formatted_value=$(echo "$value" | sed 's/^"\(.*\)"$/\1/')

# Check if the key already exists in the file
if grep -q "^[[:space:]]*$key[[:space:]]*=" "$config_file"; then
# If the key exists, adjust the format with a space before the equals sign and quotes around the value
sed -i 's/^[[:space:]]*'"$key"'[[:space:]]*=[[:space:]]*".*"/'"$key"' = "'"$formatted_value"'"/' "$config_file"
else
# If the key does not exist, add a new line with the correct format (space before the equals sign and quotes)
echo "$key = \"$formatted_value\"" >> "$config_file"
fi

echo "Updated $config_file with $key = \"$formatted_value\""

shift 2
done

0 comments on commit 70e1b2e

Please sign in to comment.