2022-03-27 13:30:22 +00:00
#!/bin/bash
2025-02-20 01:27:26 +00:00
# Function to display CLI help
2025-01-29 06:24:56 +00:00
show_cli_help( ) {
2025-02-20 01:27:26 +00:00
echo -e "
2025-02-07 00:55:13 +00:00
Usage:
2025-02-20 00:31:08 +00:00
flatpak run [ FLATPAK-RUN-OPTION] net.retrodeck.retrodeck [ ARGUMENTS]
2022-05-18 14:10:32 +00:00
Arguments:
2024-09-08 13:43:06 +00:00
-h, --help \t Print this help
-v, --version \t Print RetroDECK version
2025-02-20 01:27:26 +00:00
--show-config \t Print information about the RetroDECK configuration file and its contents
2025-02-07 00:55:13 +00:00
--debug \t Enable debug logging for this run of RetroDECK
2024-09-08 13:43:06 +00:00
--configurator \t Starts the RetroDECK Configurator
--compress-one <file> \t Compresses target file to a compatible format
2024-09-12 05:49:19 +00:00
--compress-all <format> \t Compresses all supported games into a compatible format.\n \t \t \t \t \t \t Available formats are \" chd\" , \" zip\" , \" rvz\" and \" all\"
2025-04-04 13:15:11 +00:00
--steam-sync [ purge] \t Run the Steam ROM Manager sync process to update all ES-DE favorites in Steam. Add the \" purge\" argument to remove all Steam ROM Manager information from Steam.
2025-03-26 15:12:36 +00:00
--repair-paths \t Reconfigure broken folder locations in RetroDECK without a full reset
2025-02-07 06:35:08 +00:00
--reset <component> \t Reset RetroDECK or one or more component/emulator configurations to default values. WARNING: no confirmation prompt
2025-02-10 07:34:49 +00:00
--factory-reset \t Factory Reset, triggers the initial setup WARNING: no confirmation prompt
2025-01-31 00:30:57 +00:00
--test-upgrade <version> \t Test upgrading RetroDECK to a specific version, developer use only
2025-04-01 21:29:24 +00:00
--get <preset> [ system/all] \t Show the current status of all systems in a given preset type. Use --get-help for more information.
--set <preset> <system/all> <value> \t Configure or toggle a preset. Examples: --set borders all true,\n \t \t \t \t \t \t --set borders gba false. Use --set-help for more information
2025-02-07 06:35:08 +00:00
--open <component/emulator> \t Open a specific component or emulator\n \t \t \t \t \t \t --open --list for a list of available components
2024-09-08 13:43:06 +00:00
2024-12-18 01:06:50 +00:00
Game Launch:
[ <options>] <game_path> \t Start a game using the default emulator or\n \t \t \t \t \t \t the one defined in ES-DE for game or system
\t Options:
2024-09-12 05:49:19 +00:00
\t \t -e ( emulator) \t Run the game with the defined emulator ( optional)
\t \t -s ( system) \t Force the game running with the defined system, for example running a gb game on gba ( optional)
2024-12-18 01:06:50 +00:00
\t \t -m ( manual) \t Manual mode: show the list of available emulator to choose from ( optional)
2022-05-18 14:10:32 +00:00
For flatpak run specific options please run: flatpak run -h
2025-02-07 00:55:13 +00:00
The RetroDECK Team
2022-05-18 14:10:32 +00:00
https://retrodeck.net
"
2025-01-29 06:24:56 +00:00
}
2025-02-20 01:27:26 +00:00
# Check if is an infromational message
# If so, set LOG_SILENT to true, source the global.sh script,
# show the needed information and quit
case " $1 " in
-h| --help)
LOG_SILENT = true
source /app/libexec/global.sh
if [ [ " $version " = ~ ^[ 0-9] ] ] ; then
2022-08-04 19:40:04 +00:00
echo " RetroDECK v $version "
2025-02-20 01:27:26 +00:00
else
echo " RetroDECK $version "
fi
show_cli_help
exit 0
; ;
-v| --version)
LOG_SILENT = true
source /app/libexec/global.sh
if [ [ " $version " = ~ ^[ 0-9] ] ] ; then
2022-08-04 19:40:04 +00:00
echo " RetroDECK v $version "
2025-02-20 01:27:26 +00:00
else
echo " RetroDECK $version "
fi
exit 0
2025-02-10 07:34:49 +00:00
; ;
2025-04-01 21:29:24 +00:00
--get-help)
LOG_SILENT = true
source /app/libexec/global.sh
echo -e "\nUsed to check the state of all systems for a given preset.\n\nAvailable presets are:"
fetch_all_presets | tr ' ' ',' | sed 's/,/, /g'
echo -e "\nUsage: --get <preset> [system/all]"
echo -e "\nExamples:"
echo -e " Get the list of all emulators that support the \"borders\" preset:"
echo -e " --get borders"
echo -e " Get the current state of the borders preset for the snes system:"
echo -e " --get borders snes"
echo -e " Get the current state of the borders preset for all the systems that support it:"
echo -e " --get borders all"
exit 0
; ;
2025-02-20 05:35:52 +00:00
--set-help)
LOG_SILENT = true
source /app/libexec/global.sh
echo -e "\nUsed to toggle or set a preset.\n\nAvailable presets are:"
fetch_all_presets | tr ' ' ',' | sed 's/,/, /g'
2025-04-01 21:29:24 +00:00
echo -e "\nUsage: --set <preset> <system/all> <value>"
2025-02-20 05:35:52 +00:00
echo -e "\nExamples:"
2025-04-01 21:29:24 +00:00
echo -e " Enable borders for GBA:"
echo -e " --set borders gba on"
echo -e " Disable borders for all supported systems:"
echo -e " --set borders all off"
echo -e "\nYou can also use 'true' or 'false' instead of 'on' and 'off'."
2025-02-20 05:35:52 +00:00
exit 0
; ;
2025-02-20 01:27:26 +00:00
esac
source /app/libexec/global.sh
# Process command-line arguments
while [ [ $# -gt 0 ] ] ; do
# If the first argument is -e, -s, -m, or a valid file, attempt to launch the game
if [ -f " $1 " ] || [ [ " $1 " = = "-e" || " $1 " = = "-s" || " $1 " = = "-m" ] ] ; then
echo " $LOG_BUFFER "
log i " Game start option detected: $1 "
2025-01-29 06:24:56 +00:00
run_game " $@ "
2025-02-20 01:27:26 +00:00
exit 0
fi
case " $1 " in
2025-02-21 02:35:14 +00:00
--show-config)
echo ""
cat " $rd_conf "
exit 0
; ;
2025-02-20 01:27:26 +00:00
--debug)
logging_level = "debug"
shift
; ;
--compress-one)
cli_compress_single_game " $2 "
exit 0
; ;
--compress-all)
cli_compress_all_games " $2 "
2025-04-03 16:51:42 +00:00
exit 0
2025-02-20 01:27:26 +00:00
; ;
2025-03-26 15:12:36 +00:00
--steam-sync)
2025-04-04 13:15:11 +00:00
if [ [ -n " $2 " ] ] ; then
if [ [ " $2 " = = "purge" ] ] ; then
steam-rom-manager nuke
else
echo " Unknown argument \" $2 \", please check the CLI help for more information. "
fi
else
steam_sync
fi
2025-03-26 15:12:36 +00:00
exit 0
; ;
2025-03-13 18:54:05 +00:00
--repair-paths)
repair_paths
exit 0
; ;
2025-02-20 01:27:26 +00:00
--configurator)
sh /app/tools/configurator.sh
exit 0
; ;
--reset)
component = " ${ @ : 2 } "
if [ -z " $component " ] ; then
echo "You are about to reset one or more RetroDECK components or emulators."
echo -e " Available options are:\nall, $( prepare_component --list | tr ' ' ',' | sed 's/,/, /g' ) "
2025-04-02 18:04:10 +00:00
read -r -p "Please enter the component you would like to reset: " component
2025-02-20 01:27:26 +00:00
component = $( echo " $component " | tr '[:upper:]' '[:lower:]' )
fi
log d " Resetting component: $component "
prepare_component "reset" " $component "
exit 0
; ;
--factory-reset)
prepare_component --factory-reset
exit 0
; ;
--test-upgrade)
if [ [ " $2 " = ~ ^.+ ] ] ; then
2025-04-08 04:36:36 +00:00
read -r -p " You are about to test upgrading RetroDECK from version $2 to $hard_version . Enter 'y' to continue ot 'n' to start RetroDECK normally: (y/N) " response
2025-02-20 01:27:26 +00:00
if [ [ $response = = [ yY] ] ] ; then
version = " $2 "
logging_level = "debug" # Temporarily enable debug logging
shift 2
else
shift
fi
else
echo "Error: Invalid format. Usage: --test-upgrade <version>"
exit 1
fi
; ;
2025-04-01 21:29:24 +00:00
--get)
preset = " $2 "
system = " $3 "
if [ [ -z " $preset " ] ] ; then
echo "Error: No preset specified. Usage: --get <preset> [system] (use --get-help for more information)"
exit 1
elif [ [ $( fetch_all_presets | tr ' ' ',' | sed 's/,/, /g' ) = ~ " $preset " ] ] ; then
preset_compatible_systems = $( sed -n '/\[' " $preset " '\]/, /\[/{ /\[' " $preset " '\]/! { /\[/! p } }' " $rd_conf " | sed '/^$/d' )
if [ [ -z " $system " ] ] ; then # User provided a preset but no system argument
preset_compatible_systems = $( echo " $preset_compatible_systems " | cut -d= -f1 | sed ':a;N;$!ba;s/\n/, /g' )
echo " The systems that support the preset $preset are $preset_compatible_systems "
elif [ [ " $system " = = "all" ] ] ; then
while IFS = read -r config_line; do
current_system_name = $( get_setting_name " $config_line " "retrodeck" )
current_system_value = $( get_setting_value " $rd_conf " " $current_system_name " "retrodeck" " $preset " )
if [ [ " $current_system_value " = = "true" ] ] ; then
current_system_value = "enabled"
else
current_system_value = "disabled"
fi
echo " The preset $preset for the system $current_system_name is $current_system_value "
done < <( printf '%s\n' " $preset_compatible_systems " )
elif [ [ " $preset_compatible_systems " = ~ " $system " ] ] ; then
preset_state = $( get_setting_value " $rd_conf " " $system " "retrodeck" " $preset " )
if [ [ " $preset_state " = = "true" ] ] ; then
preset_state = "enabled"
else
preset_state = "disabled"
fi
echo " The preset $preset for the system $system is $preset_state . "
else
echo " The system $system is not compatible with the preset $preset . (use --get-help for more information) "
exit 1
fi
else
echo " Preset $preset not recognized. Use --get-help for a list of valid options. "
exit 1
fi
exit 0
; ;
2025-02-20 01:27:26 +00:00
--set)
preset = " $2 "
2025-02-20 05:35:52 +00:00
system = " $3 "
value = " $4 "
2025-04-01 21:29:24 +00:00
if [ [ -z " $preset " ] ] ; then
echo "Error: No preset specified. Usage: --set <preset> <system/all> <value> (use --set-help for more information)"
2025-02-20 05:35:52 +00:00
exit 1
2025-04-01 21:29:24 +00:00
elif [ [ -z " $system " ] ] ; then
echo "Error: No system specified. Usage: --set <preset> <system/all> <value> (use --set-help for more information)"
exit 1
elif [ [ -z " $value " ] ] ; then
echo "Error: No value specified. Usage: --set <preset> <system/all> <value> (use --set-help for more information)"
exit 1
elif [ [ $( fetch_all_presets | tr ' ' ',' | sed 's/,/, /g' ) = ~ " $preset " ] ] ; then
if [ [ " $preset " = = "cheevos" && " $value " = ~ ( true| on) ] ] ; then # Get cheevos login information
2025-04-02 18:03:06 +00:00
current_system_value = $( get_setting_value " $rd_conf " " $system " "retrodeck" " $preset " )
if [ [ " $current_system_value " = = "false" || -z " $current_system_value " ] ] ; then
2025-04-02 18:04:10 +00:00
read -r -p "Please enter your RetroAchievements username: " cheevos_username
read -r -s -p "Please enter your RetroAchievements password: " cheevos_password
2025-04-02 18:03:06 +00:00
if cheevos_info = $( get_cheevos_token " $cheevos_username " " $cheevos_password " ) ; then
cheevos_token = $( echo " $cheevos_info " | jq -r '.Token' )
cheevos_login_timestamp = $( date +%s)
echo "RetroAchievements login succeeded, proceeding..."
else # login failed
echo "RetroAchievements login failed, please try again."
exit 1
fi
else
echo " RetroAchivements for $system are already enabled. "
2025-04-01 21:29:24 +00:00
exit 1
fi
fi
if [ [ ! " $system " = = "all" ] ] ; then # Check if emulator is already set as requested
current_system_value = $( get_setting_value " $rd_conf " " $system " "retrodeck" " $preset " )
if [ [ " $value " = ~ ( true| on) && " $current_system_value " = = "true" ] ] ; then
echo " The preset $preset is already enabled for the system $system "
elif [ [ " $value " = ~ ( false| off) && " $current_system_value " = = "false" ] ] ; then
echo " The preset $preset is already disabled for the system $system "
else # Otherwise needs to be changed
if change_presets_cli " $preset " " $system " " $value " ; then
echo " $preset preset changes for $system are complete "
else
echo "Something went wrong during the preset change, please check the logs for details."
exit 1
fi
fi
else
if change_presets_cli " $preset " " $system " " $value " ; then
echo " $preset preset changes for all compatible systems are complete "
else
echo "Something went wrong during the preset change, please check the logs for details."
exit 1
fi
fi
else
echo " Preset $preset not recognized. Use --set-help for a list of valid options. "
2025-02-20 05:35:52 +00:00
exit 1
2025-02-20 01:27:26 +00:00
fi
exit 0
; ;
--open)
open_component " ${ @ : 2 } "
exit 0
; ;
2025-04-04 16:08:35 +00:00
--api)
retrodeck_api start
wait
exit $?
; ;
2025-02-20 01:27:26 +00:00
-*)
# Catch-all for unrecognized options starting with a dash
log e " Error: Unknown option ' $1 ' "
echo " Error: Unrecognized option ' $1 '. Use -h or --help for usage information. "
exit 1
; ;
*)
# If it reaches here and is an unrecognized argument, report the error
log e " Error: Command or file ' $1 ' not recognized. "
echo " Error: Command or file ' $1 ' not recognized. Use -h or --help for usage information. "
exit 1
; ;
esac
2022-05-18 14:10:32 +00:00
done
2023-03-30 14:04:11 +00:00
if [ [ $multi_user_mode = = "true" ] ] ; then
multi_user_determine_current_user
fi
2023-05-08 20:54:35 +00:00
# Run optional startup checks
2024-03-12 14:13:41 +00:00
if [ [ $( check_is_steam_deck) = = "true" ] ] ; then # Only warn about Desktop Mode on Steam Deck, ignore for other platforms
desktop_mode_warning
fi
2023-05-08 20:54:35 +00:00
low_space_warning
2023-03-07 17:00:32 +00:00
2023-03-27 19:52:58 +00:00
# Check if there is a new version of RetroDECK available, if update_check=true in retrodeck.cfg and there is network connectivity available.
2024-03-04 09:17:25 +00:00
log i "Check if there is a new version of RetroDECK available"
2023-06-08 17:52:19 +00:00
if [ [ $update_check = = "true" ] ] ; then
if [ [ $( check_network_connectivity) = = "true" ] ] ; then
2024-03-04 09:17:25 +00:00
log d "Running function check_for_version_update"
2023-06-08 17:52:19 +00:00
check_for_version_update
fi
2024-03-04 09:17:25 +00:00
log i "You're running the latest version"
2023-03-27 19:52:58 +00:00
fi
2022-12-22 15:34:50 +00:00
# Normal Startup
2023-04-14 12:49:21 +00:00
start_retrodeck
2024-10-28 01:01:44 +00:00
# After everything is closed we run the quit function
2024-09-08 00:31:35 +00:00
quit_retrodeck