Better handle spaces in paths

Replace eval with declare where possible
Handle new SD card locations and non-default names from SteamOS 3.5
This commit is contained in:
icenine451 2023-11-27 10:42:56 -05:00
parent aeed7d7917
commit d7ac1ad0f2
5 changed files with 27 additions and 23 deletions

View file

@ -113,7 +113,7 @@ configurator_move_folder_dialog() {
unlink "$dest_root/$rd_dir_path" # In case there is already a symlink at the picked destination unlink "$dest_root/$rd_dir_path" # In case there is already a symlink at the picked destination
move "$dir_to_move" "$dest_root/$rd_dir_path" move "$dir_to_move" "$dest_root/$rd_dir_path"
if [[ -d "$dest_root/$rd_dir_path" ]]; then # If the move succeeded if [[ -d "$dest_root/$rd_dir_path" ]]; then # If the move succeeded
eval "$rd_dir_name"="$dest_root/$rd_dir_path" # Set the new path for that folder variable in retrodeck.cfg declare -g "$rd_dir_name=$dest_root/$rd_dir_path" # Set the new path for that folder variable in retrodeck.cfg
if [[ "$rd_dir_name" == "rdhome" ]]; then # If the whole retrodeck folder was moved... if [[ "$rd_dir_name" == "rdhome" ]]; then # If the whole retrodeck folder was moved...
prepare_emulator "postmove" "retrodeck" prepare_emulator "postmove" "retrodeck"
fi fi
@ -146,7 +146,7 @@ configurator_move_folder_dialog() {
else # The folder to move was not found at the path pulled from retrodeck.cfg and it needs to be reconfigured manually. else # The folder to move was not found at the path pulled from retrodeck.cfg and it needs to be reconfigured manually.
configurator_generic_dialog "RetroDECK Configurator - Move Folder" "The $(basename $dir_to_move) folder was not found at the expected location.\n\nThis may have happened if the folder was moved manually.\n\nPlease select the current location of the folder." configurator_generic_dialog "RetroDECK Configurator - Move Folder" "The $(basename $dir_to_move) folder was not found at the expected location.\n\nThis may have happened if the folder was moved manually.\n\nPlease select the current location of the folder."
dir_to_move=$(directory_browse "RetroDECK $(basename $dir_to_move) directory location") dir_to_move=$(directory_browse "RetroDECK $(basename $dir_to_move) directory location")
eval "$rd_dir_name"="$dir_to_move" declare -g "$rd_dir_name=$dir_to_move"
prepare_emulator "postmove" "all" prepare_emulator "postmove" "all"
conf_write conf_write
configurator_generic_dialog "RetroDECK Configurator - Move Folder" "RetroDECK $(basename $dir_to_move) folder now configured at\n$dir_to_move." configurator_generic_dialog "RetroDECK Configurator - Move Folder" "RetroDECK $(basename $dir_to_move) folder now configured at\n$dir_to_move."

View file

@ -9,14 +9,14 @@ directory_browse() {
while [ $path_selected == false ] while [ $path_selected == false ]
do do
local target="$(zenity --file-selection --title="Choose $1" --directory)" local target="$(zenity --file-selection --title="Choose $1" --directory)"
if [ ! -z $target ] #yes if [ ! -z "$target" ] #yes
then then
zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" \ zenity --question --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" --cancel-label="No" --ok-label "Yes" \
--text="Directory $target chosen, is this correct?" --text="Directory $target chosen, is this correct?"
if [ $? == 0 ] if [ $? == 0 ]
then then
path_selected=true path_selected=true
echo $target echo "$target"
break break
fi fi
else else
@ -161,7 +161,7 @@ conf_read() {
if [[ "$current_section" == "" || "$current_section" == "paths" || "$current_section" == "options" ]]; then if [[ "$current_section" == "" || "$current_section" == "paths" || "$current_section" == "options" ]]; then
local current_setting_name=$(get_setting_name "$current_setting_line" "retrodeck") # Read the variable name from the current line local current_setting_name=$(get_setting_name "$current_setting_line" "retrodeck") # Read the variable name from the current line
local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "$current_section") # Read the variables value from retrodeck.cfg local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "$current_section") # Read the variables value from retrodeck.cfg
eval "$current_setting_name=$current_setting_value" # Write the current setting name and value to memory declare -g "$current_setting_name=$current_setting_value" # Write the current setting name and value to memory
fi fi
fi fi
fi fi
@ -341,7 +341,7 @@ finit() {
local finit_dest_choice=$(configurator_destination_choice_dialog "RetroDECK data" "Welcome to the first configuration of RetroDECK.\nThe setup will be quick but please READ CAREFULLY each message in order to avoid misconfigurations.\n\nWhere do you want your RetroDECK data folder to be located?\n\nThis folder will contain all ROMs, BIOSs and scraped data." ) local finit_dest_choice=$(configurator_destination_choice_dialog "RetroDECK data" "Welcome to the first configuration of RetroDECK.\nThe setup will be quick but please READ CAREFULLY each message in order to avoid misconfigurations.\n\nWhere do you want your RetroDECK data folder to be located?\n\nThis folder will contain all ROMs, BIOSs and scraped data." )
echo "Choice is $finit_dest_choice" echo "Choice is $finit_dest_choice"
case $finit_dest_choice in case "$finit_dest_choice" in
"Back" | "" ) # Back or X button quits "Back" | "" ) # Back or X button quits
rm -f "$rd_conf" # Cleanup unfinished retrodeck.cfg if first install is interrupted rm -f "$rd_conf" # Cleanup unfinished retrodeck.cfg if first install is interrupted
@ -352,8 +352,8 @@ finit() {
"Internal Storage" ) # Internal "Internal Storage" ) # Internal
echo "Internal selected" echo "Internal selected"
rdhome="$HOME/retrodeck" rdhome="$HOME/retrodeck"
if [[ -L $rdhome ]]; then #Remove old symlink from existing install, if it exists if [[ -L "$rdhome" ]]; then #Remove old symlink from existing install, if it exists
unlink $rdhome unlink "$rdhome"
fi fi
;; ;;
@ -366,9 +366,9 @@ finit() {
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \
--title "RetroDECK" \ --title "RetroDECK" \
--ok-label "Browse" \ --ok-label "Browse" \
--text="SD Card was not find in the default location.\nPlease choose the SD Card root.\nA retrodeck folder will be created starting from the directory that you selected." --text="SD Card was not found in the default location.\nPlease choose the SD Card root.\nA retrodeck folder will be created starting from the directory that you selected."
rdhome=$(finit_browse) # Calling the browse function rdhome="$(finit_browse)" # Calling the browse function
if [[ -z $rdhome ]]; then # If user hit the cancel button if [[ -z "$rdhome" ]]; then # If user hit the cancel button
rm -f "$rd_conf" # Cleanup unfinished retrodeck.cfg if first install is interrupted rm -f "$rd_conf" # Cleanup unfinished retrodeck.cfg if first install is interrupted
exit 2 exit 2
fi fi
@ -395,8 +395,8 @@ finit() {
--title "RetroDECK" \ --title "RetroDECK" \
--ok-label "Browse" \ --ok-label "Browse" \
--text="Please choose the root folder for the RetroDECK data.\nA retrodeck folder will be created starting from the directory that you selected." --text="Please choose the root folder for the RetroDECK data.\nA retrodeck folder will be created starting from the directory that you selected."
rdhome=$(finit_browse) # Calling the browse function rdhome="$(finit_browse)" # Calling the browse function
if [[ -z $rdhome ]]; then # If user hit the cancel button if [[ -z "$rdhome" ]]; then # If user hit the cancel button
rm -f "$rd_conf" # Cleanup unfinished retrodeck.cfg if first install is interrupted rm -f "$rd_conf" # Cleanup unfinished retrodeck.cfg if first install is interrupted
exit 2 exit 2
fi fi
@ -414,7 +414,7 @@ finit() {
if [[ "$finit_options_choices" =~ (rpcs3_firmware|Enable All) ]]; then # Additional information on the firmware install process, as the emulator needs to be manually closed if [[ "$finit_options_choices" =~ (rpcs3_firmware|Enable All) ]]; then # Additional information on the firmware install process, as the emulator needs to be manually closed
configurator_generic_dialog "RPCS3 Firmware Install" "You have chosen to install the RPCS3 firmware during the RetroDECK first setup.\n\nThis process will take several minutes and requires network access.\n\nRPCS3 will be launched automatically at the end of the RetroDECK setup process.\nOnce the firmware is installed, please close the emulator to finish the process." configurator_generic_dialog "RPCS3 Firmware Install" "You have chosen to install the RPCS3 firmware during the RetroDECK first setup.\n\nThis process will take several minutes and requires network access.\n\nRPCS3 will be launched automatically at the end of the RetroDECK setup process.\nOnce the firmware is installed, please close the emulator to finish the process."
fi fi
zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap \ zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap \
--window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --title "RetroDECK" \
--text="RetroDECK will now install the needed files, which can take up to one minute.\nRetroDECK will start once the process is completed.\n\nPress OK to continue." --text="RetroDECK will now install the needed files, which can take up to one minute.\nRetroDECK will start once the process is completed.\n\nPress OK to continue."
@ -423,7 +423,7 @@ finit() {
prepare_emulator "reset" "all" prepare_emulator "reset" "all"
build_retrodeck_current_presets build_retrodeck_current_presets
deploy_helper_files deploy_helper_files
# Optional actions based on user choices # Optional actions based on user choices
if [[ "$finit_options_choices" =~ (rpcs3_firmware|Enable All) ]]; then if [[ "$finit_options_choices" =~ (rpcs3_firmware|Enable All) ]]; then
if [[ $(check_network_connectivity) == "true" ]]; then if [[ $(check_network_connectivity) == "true" ]]; then
@ -433,7 +433,7 @@ finit() {
if [[ "$finit_options_choices" =~ (rd_controller_profile|Enable All) ]]; then if [[ "$finit_options_choices" =~ (rd_controller_profile|Enable All) ]]; then
install_retrodeck_controller_profile install_retrodeck_controller_profile
fi fi
if [[ "$finit_options_choices" =~ (rd_prepacks|Enable All) ]]; then if [[ "$finit_options_choices" =~ (rd_prepacks|Enable All) ]]; then
install_retrodeck_starterpack install_retrodeck_starterpack
fi fi
@ -449,7 +449,7 @@ finit() {
install_retrodeck_starterpack() { install_retrodeck_starterpack() {
# This function will install the roms, gamelists and metadata for the RetroDECK Starter Pack, a curated selection of games the creators of RetroDECK enjoy. # This function will install the roms, gamelists and metadata for the RetroDECK Starter Pack, a curated selection of games the creators of RetroDECK enjoy.
# USAGE: install_retrodeck_starterpack # USAGE: install_retrodeck_starterpack
## DOOM section ## ## DOOM section ##
cp /app/retrodeck/extras/doom1.wad "$roms_folder/doom/doom1.wad" # No -f in case the user already has it cp /app/retrodeck/extras/doom1.wad "$roms_folder/doom/doom1.wad" # No -f in case the user already has it
mkdir -p "/var/config/emulationstation/.emulationstation/gamelists/doom" mkdir -p "/var/config/emulationstation/.emulationstation/gamelists/doom"

View file

@ -126,9 +126,13 @@ if [[ ! -f "$rd_conf" ]]; then
fi fi
# Check if SD card path has changed from SteamOS update # Check if SD card path has changed from SteamOS update
if [[ ! -d $default_sd && "$(ls -A /run/media/deck/)" ]]; then if [[ ! -d "$default_sd" && "$(ls -A /run/media/deck/)" ]]; then
configurator_generic_dialog "RetroDECK Setup" "The SD card was not found in the expected location.\nThis may happen when SteamOS is updated.\n\nPlease browse to the current location of the SD card.\n\nIf you are not using an SD card, please click \"Cancel\"." if [[ $(find media/deck/* -maxdepth 0 -type d -print | wc -l) -eq 1 ]]; then # If there is only one SD card found in the new Steam OS 3.5 location, assign it as the default
default_sd=$(directory_browse "SD Card Location") default_sd="$(find media/deck/* -maxdepth 0 -type d -print)"
else # If the default legacy path cannot be found, and there are multiple entries in the new Steam OS 3.5 SD card path, let the user pick which one to use
configurator_generic_dialog "RetroDECK Setup" "The SD card was not found in the expected location.\nThis may happen when SteamOS is updated.\n\nPlease browse to the current location of the SD card.\n\nIf you are not using an SD card, please click \"Cancel\"."
default_sd="$(directory_browse "SD Card Location")"
fi
fi fi
cp $rd_defaults $rd_conf # Load default settings file cp $rd_defaults $rd_conf # Load default settings file

View file

@ -17,7 +17,7 @@ set_setting_value() {
sed -i '\^\['"$current_section_name"'\]^,\^\^'"$setting_name_to_change"'=^s^\^'"$setting_name_to_change"'=.*^'"$setting_name_to_change"'='"$setting_value_to_change"'^' "$1" sed -i '\^\['"$current_section_name"'\]^,\^\^'"$setting_name_to_change"'=^s^\^'"$setting_name_to_change"'=.*^'"$setting_name_to_change"'='"$setting_value_to_change"'^' "$1"
fi fi
if [[ "$4" == "retrodeck" && ("$current_section_name" == "" || "$current_section_name" == "paths" || "$current_section_name" == "options") ]]; then # If a RetroDECK setting is being changed, also write it to memory for immediate use if [[ "$4" == "retrodeck" && ("$current_section_name" == "" || "$current_section_name" == "paths" || "$current_section_name" == "options") ]]; then # If a RetroDECK setting is being changed, also write it to memory for immediate use
eval "$setting_name_to_change=$setting_value_to_change" declare -g "$setting_name_to_change=$setting_value_to_change"
fi fi
;; ;;

View file

@ -19,7 +19,7 @@ prepare_emulator() {
local current_setting_name=$(get_setting_name "$config_line" "retrodeck") local current_setting_name=$(get_setting_name "$config_line" "retrodeck")
if [[ ! $current_setting_name =~ (rdhome|sdcard) ]]; then # Ignore these locations if [[ ! $current_setting_name =~ (rdhome|sdcard) ]]; then # Ignore these locations
local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "paths") local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "paths")
eval "$current_setting_name=$rdhome/$(basename $current_setting_value)" declare -g "$current_setting_name=$rdhome/$(basename $current_setting_value)"
mkdir -p "$rdhome/$(basename $current_setting_value)" mkdir -p "$rdhome/$(basename $current_setting_value)"
fi fi
done < <(grep -v '^\s*$' $rd_conf | awk '/^\[paths\]/{f=1;next} /^\[/{f=0} f') done < <(grep -v '^\s*$' $rd_conf | awk '/^\[paths\]/{f=1;next} /^\[/{f=0} f')
@ -30,7 +30,7 @@ prepare_emulator() {
if [[ ! $current_setting_name =~ (rdhome|sdcard) ]]; then # Ignore these locations if [[ ! $current_setting_name =~ (rdhome|sdcard) ]]; then # Ignore these locations
local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "paths") local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "paths")
if [[ -d "$rdhome/$(basename $current_setting_value)" ]]; then # If the folder exists at the new ~/retrodeck location if [[ -d "$rdhome/$(basename $current_setting_value)" ]]; then # If the folder exists at the new ~/retrodeck location
eval "$current_setting_name=$rdhome/$(basename $current_setting_value)" declare -g "$current_setting_name=$rdhome/$(basename $current_setting_value)"
fi fi
fi fi
done < <(grep -v '^\s*$' $rd_conf | awk '/^\[paths\]/{f=1;next} /^\[/{f=0} f') done < <(grep -v '^\s*$' $rd_conf | awk '/^\[paths\]/{f=1;next} /^\[/{f=0} f')