-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
5 changed files
with
60 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |