2022-06-09 08:25:20 +00:00
#!/bin/bash
# This file is containing some global function needed for the script such as the config file tools
2024-08-05 01:45:21 +00:00
# pathing the retrodeck components provided libraries
# now disabled as we are importing everything in /app/lib. In case we are breaking something we need to restore this approach
# export LD_LIBRARY_PATH="/app/retrodeck/lib:/app/retrodeck/lib/debug:/app/retrodeck/lib/pkgconfig:$LD_LIBRARY_PATH"
2024-11-30 13:39:30 +00:00
: " ${ logging_level : =info } " # Initializing the log level variable if not already valued, this will be actually red later from the config file
2025-03-27 16:52:04 +00:00
rd_logs_folder = " $XDG_CONFIG_HOME /retrodeck/logs " # Static location to write all RetroDECK-related logs
2025-03-09 19:31:40 +00:00
if [ -h " $rd_logs_folder " ] ; then # Check if internal logging folder is already a symlink
if [ ! -e " $rd_logs_folder " ] ; then # Check if internal logging folder symlink is broken
unlink " $rd_logs_folder " # Remove broken symlink so the folder is recreated when sourcing logger.sh
fi
fi
2024-11-30 13:39:30 +00:00
source /app/libexec/logger.sh
rotate_logs
2025-01-08 05:10:53 +00:00
2025-02-21 02:35:14 +00:00
# OS detection
2025-02-18 02:56:48 +00:00
width = $( grep -oP '\d+(?=x)' /sys/class/graphics/fb0/modes)
height = $( grep -oP '(?<=x)\d+' /sys/class/graphics/fb0/modes)
if [ [ $width -ne 1280 ] ] || [ [ $height -ne 800 ] ] ; then
native_resolution = false
else
native_resolution = true
fi
2025-02-21 02:35:14 +00:00
distro_name = $( flatpak-spawn --host grep '^ID=' /etc/os-release | cut -d'=' -f2)
distro_version = $( flatpak-spawn --host grep '^VERSION_ID=' /etc/os-release | cut -d'=' -f2)
gpu_info = $( flatpak-spawn --host lspci | grep -i 'vga\|3d\|2d' )
2025-02-18 02:56:48 +00:00
2025-02-05 04:30:35 +00:00
log d "Debug mode enabled"
2024-11-30 13:39:30 +00:00
log i "Initializing RetroDECK"
2025-02-21 02:35:14 +00:00
log i " Running on $XDG_SESSION_DESKTOP , $XDG_SESSION_TYPE , $distro_name $distro_version "
2025-01-08 05:10:53 +00:00
if [ [ -n $container ] ] ; then
2025-02-21 02:35:14 +00:00
log i " Running inside $container environment "
2025-01-08 05:10:53 +00:00
fi
2025-02-21 02:35:14 +00:00
log i " GPU: $gpu_info "
2025-02-18 02:56:48 +00:00
log i " Resolution: $width x $height "
if [ [ $native_resolution = = true ] ] ; then
log i "Steam Deck native resolution detected"
fi
2024-11-30 13:39:30 +00:00
2023-05-12 20:26:09 +00:00
source /app/libexec/050_save_migration.sh
source /app/libexec/checks.sh
source /app/libexec/compression.sh
source /app/libexec/dialogs.sh
2024-05-30 14:51:55 +00:00
source /app/libexec/other_functions.sh
2023-05-12 20:26:09 +00:00
source /app/libexec/multi_user.sh
2024-03-27 12:53:20 +00:00
source /app/libexec/framework.sh
2023-05-12 20:26:09 +00:00
source /app/libexec/post_update.sh
2024-01-16 08:14:27 +00:00
source /app/libexec/prepare_component.sh
2023-05-12 20:26:09 +00:00
source /app/libexec/presets.sh
2024-06-20 17:45:38 +00:00
source /app/libexec/configurator_functions.sh
2024-09-11 23:25:07 +00:00
source /app/libexec/run_game.sh
2025-03-25 12:54:14 +00:00
source /app/libexec/steam_sync.sh
2022-10-24 19:49:47 +00:00
2022-09-06 13:24:36 +00:00
# Static variables
2025-03-27 16:52:04 +00:00
rd_conf = " $XDG_CONFIG_HOME /retrodeck/retrodeck.cfg " # RetroDECK config file path
rd_conf_backup = " $XDG_CONFIG_HOME /retrodeck/retrodeck.bak " # Backup of RetroDECK config file from update
2024-09-11 23:25:07 +00:00
config = "/app/retrodeck/config" # folder with all the default emulator configs
2024-08-05 01:45:21 +00:00
rd_defaults = " $config /retrodeck/retrodeck.cfg " # A default RetroDECK config file
2025-03-27 16:52:04 +00:00
rd_update_patch = " $XDG_CONFIG_HOME /retrodeck/rd_update.patch " # A static location for the temporary patch file used during retrodeck.cfg updates
2025-01-10 06:53:46 +00:00
bios_checklist = " $config /retrodeck/reference_lists/bios.json " # A config file listing BIOS file information that can be verified
2024-08-05 01:45:21 +00:00
input_validation = " $config /retrodeck/reference_lists/input_validation.cfg " # A config file listing valid CLI inputs
finit_options_list = " $config /retrodeck/reference_lists/finit_options_list.cfg " # A config file listing available optional installs during finit
2025-03-27 16:52:04 +00:00
splashscreen_dir = " $XDG_CONFIG_HOME /ES-DE/resources/graphics/extra_splashes " # The default location of extra splash screens
current_splash_file = " $XDG_CONFIG_HOME /ES-DE/resources/graphics/splash.svg " # The active splash file that will be shown on boot
default_splash_file = " $XDG_CONFIG_HOME /ES-DE/resources/graphics/splash-orig.svg " # The default RetroDECK splash screen
2024-08-15 14:42:40 +00:00
# TODO: instead of this maybe we can iterate the features.json
2024-08-05 01:45:21 +00:00
multi_user_emulator_config_dirs = " $config /retrodeck/reference_lists/multi_user_emulator_config_dirs.cfg " # A list of emulator config folders that can be safely linked/unlinked entirely in multi-user mode
2024-09-11 23:25:07 +00:00
rd_es_themes = "/app/share/es-de/themes" # The directory where themes packaged with RetroDECK are stored
2025-03-27 16:52:04 +00:00
lockfile = " $XDG_CONFIG_HOME /retrodeck/.lock " # Where the lockfile is located
2024-09-11 23:25:07 +00:00
default_sd = "/run/media/mmcblk0p1" # Steam Deck SD default path
hard_version = " $( cat '/app/retrodeck/version' ) " # hardcoded version (in the readonly filesystem)
rd_repo = "https://github.com/RetroDECK/RetroDECK" # The URL of the main RetroDECK GitHub repo
es_themes_list = "https://gitlab.com/es-de/themes/themes-list/-/raw/master/themes.json" # The URL of the ES-DE 2.0 themes list
remote_network_target_1 = "https://flathub.org" # The URL of a common internet target for testing network access
remote_network_target_2 = " $rd_repo " # The URL of a common internet target for testing network access
remote_network_target_3 = "https://one.one.one.one" # The URL of a common internet target for testing network access
2024-08-05 01:45:21 +00:00
helper_files_folder = " $config /retrodeck/helper_files " # The parent folder of RetroDECK documentation files for deployment
2025-01-30 04:36:33 +00:00
rd_metainfo = "/app/share/metainfo/net.retrodeck.retrodeck.metainfo.xml" # The shipped metainfo XML file for this version
2024-09-11 23:25:07 +00:00
rpcs3_firmware = "http://dus01.ps3.update.playstation.net/update/ps3/image/us/2024_0227_3694eb3fb8d9915c112e6ab41a60c69f/PS3UPDAT.PUP" # RPCS3 Firmware download location
RA_API_URL = "https://retroachievements.org/dorequest.php" # API URL for RetroAchievements.org
2024-08-05 01:45:21 +00:00
presets_dir = " $config /retrodeck/presets " # Repository for all system preset config files
2024-09-11 23:25:07 +00:00
git_organization_name = "RetroDECK" # The name of the organization in our git repository such as GitHub
cooker_repository_name = "Cooker" # The name of the cooker repository under RetroDECK organization
main_repository_name = "RetroDECK" # The name of the main repository under RetroDECK organization
features = " $config /retrodeck/reference_lists/features.json " # A file where all the RetroDECK and component capabilities are kept for querying
es_systems = "/app/share/es-de/resources/systems/linux/es_systems.xml" # ES-DE supported system list
2024-11-28 06:01:21 +00:00
es_find_rules = "/app/share/es-de/resources/systems/linux/es_find_rules.xml" # ES-DE emulator find rules
2024-08-06 02:08:54 +00:00
2024-02-21 19:00:18 +00:00
# Godot data transfer temp files
2025-03-27 16:52:04 +00:00
godot_bios_files_checked = " $XDG_CONFIG_HOME /retrodeck/godot/godot_bios_files_checked.tmp "
godot_current_preset_settings = " $XDG_CONFIG_HOME /retrodeck/godot/godot_current_preset_settings.tmp "
godot_compression_compatible_games = " $XDG_CONFIG_HOME /retrodeck/godot/godot_compression_compatible_games.tmp "
godot_empty_roms_folders = " $XDG_CONFIG_HOME /retrodeck/godot/godot_empty_roms_folders.tmp "
2024-02-21 19:00:18 +00:00
2022-10-26 16:51:46 +00:00
# Config files for emulators with single config files
2025-03-27 16:52:04 +00:00
duckstationconf = " $XDG_CONFIG_HOME /duckstation/settings.ini "
melondsconf = " $XDG_CONFIG_HOME /melonDS/melonDS.ini "
ryujinxconf = " $XDG_CONFIG_HOME /Ryujinx/Config.json "
xemuconf = " $XDG_CONFIG_HOME /xemu/xemu.toml "
yuzuconf = " $XDG_CONFIG_HOME /yuzu/qt-config.ini "
citraconf = " $XDG_CONFIG_HOME /citra-emu/qt-config.ini "
2022-10-26 16:51:46 +00:00
# ES-DE config files
2025-03-27 16:52:04 +00:00
export ESDE_APPDATA_DIR = " $XDG_CONFIG_HOME /ES-DE "
es_settings = " $XDG_CONFIG_HOME /ES-DE/settings/es_settings.xml "
es_source_logs = " $XDG_CONFIG_HOME /ES-DE/logs "
2022-10-26 16:51:46 +00:00
# RetroArch config files
2025-03-27 16:52:04 +00:00
raconf = " $XDG_CONFIG_HOME /retroarch/retroarch.cfg "
ra_core_conf = " $XDG_CONFIG_HOME /retroarch/retroarch-core-options.cfg "
ra_scummvm_conf = " $XDG_CONFIG_HOME /retroarch/system/scummvm.ini "
ra_cores_path = " $XDG_CONFIG_HOME /retroarch/cores "
2022-10-26 16:51:46 +00:00
2023-05-16 16:29:36 +00:00
# CEMU config files
2025-03-27 16:52:04 +00:00
cemuconf = " $XDG_CONFIG_HOME /Cemu/settings.xml "
cemucontrollerconf = " $XDG_CONFIG_HOME /Cemu/controllerProfiles/controller0.xml "
2023-05-16 16:29:36 +00:00
2022-10-26 16:51:46 +00:00
# Dolphin config files
2025-03-27 16:52:04 +00:00
dolphinconf = " $XDG_CONFIG_HOME /dolphin-emu/Dolphin.ini "
dolphingcpadconf = " $XDG_CONFIG_HOME /dolphin-emu/GCPadNew.ini "
dolphingfxconf = " $XDG_CONFIG_HOME /dolphin-emu/GFX.ini "
dolphinhkconf = " $XDG_CONFIG_HOME /dolphin-emu/Hotkeys.ini "
dolphinqtconf = " $XDG_CONFIG_HOME /dolphin-emu/Qt.ini "
dolphinDynamicInputTexturesPath = " $XDG_DATA_HOME /dolphin-emu/Load/DynamicInputTextures "
dolphinCheevosConf = " $XDG_CONFIG_HOME /dolphin-emu/RetroAchievements.ini "
2022-10-26 16:51:46 +00:00
# PCSX2 config files
2025-03-27 16:52:04 +00:00
pcsx2conf = " $XDG_CONFIG_HOME /PCSX2/inis/PCSX2.ini "
pcsx2gsconf = " $XDG_CONFIG_HOME /PCSX2/inis/GS.ini " # This file should be deprecated since moving to PCSX2-QT
pcsx2uiconf = " $XDG_CONFIG_HOME /PCSX2/inis/PCSX2_ui.ini " # This file should be deprecated since moving to PCSX2-QT
pcsx2vmconf = " $XDG_CONFIG_HOME /PCSX2/inis/PCSX2_vm.ini " # This file should be deprecated since moving to PCSX2-QT
2022-11-18 20:10:17 +00:00
2025-02-14 00:32:14 +00:00
# PPSSPP-SDL config files
2023-05-18 15:38:20 +00:00
2025-03-27 16:52:04 +00:00
ppssppconf = " $XDG_CONFIG_HOME /ppsspp/PSP/SYSTEM/ppsspp.ini "
ppssppcontrolsconf = " $XDG_CONFIG_HOME /ppsspp/PSP/SYSTEM/controls.ini "
ppssppcheevosconf = " $XDG_CONFIG_HOME /ppsspp/PSP/SYSTEM/ppsspp_retroachievements.dat "
2023-05-18 15:38:20 +00:00
2023-03-11 16:15:16 +00:00
# Primehack config files
2025-03-27 16:52:04 +00:00
primehackconf = " $XDG_CONFIG_HOME /primehack/Dolphin.ini "
primehackgcpadconf = " $XDG_CONFIG_HOME /primehack/GCPadNew.ini "
primehackgfxconf = " $XDG_CONFIG_HOME /primehack/GFX.ini "
primehackhkconf = " $XDG_CONFIG_HOME /primehack/Hotkeys.ini "
primehackqtconf = " $XDG_CONFIG_HOME /primehack/Qt.ini "
primehackDynamicInputTexturesPath = " $XDG_DATA_HOME /primehack/Load/DynamicInputTextures "
2023-03-11 16:15:16 +00:00
2023-04-06 20:16:50 +00:00
# RPCS3 config files
2025-03-27 16:52:04 +00:00
rpcs3conf = " $XDG_CONFIG_HOME /rpcs3/config.yml "
rpcs3vfsconf = " $XDG_CONFIG_HOME /rpcs3/vfs.yml "
2023-04-06 20:16:50 +00:00
2023-12-11 15:30:35 +00:00
# Vita3k config files
2025-03-27 16:52:04 +00:00
vita3kconf = " $XDG_CONFIG_HOME /Vita3K/config.yml "
2023-12-11 15:30:35 +00:00
2024-02-27 15:44:52 +00:00
# MAME-SA config files
2025-03-27 16:52:04 +00:00
mameconf = " $XDG_CONFIG_HOME /mame/ini/mame.ini "
mameuiconf = " $XDG_CONFIG_HOME /mame/ini/ui.ini "
mamedefconf = " $XDG_CONFIG_HOME /mame/cfg/default.cfg "
2024-02-27 15:44:52 +00:00
2024-03-22 21:10:26 +00:00
# Initialize logging location if it doesn't exist, before anything else happens
if [ ! -d " $rd_logs_folder " ] ; then
create_dir " $rd_logs_folder "
fi
2024-05-30 14:58:11 +00:00
# Initialize location of Godot temp data files, if it doesn't exist
2025-03-27 16:52:04 +00:00
if [ [ ! -d " $XDG_CONFIG_HOME /retrodeck/godot " ] ] ; then
create_dir " $XDG_CONFIG_HOME /retrodeck/godot "
2024-05-30 14:58:11 +00:00
fi
2025-03-27 16:52:04 +00:00
# We moved the lockfile in $XDG_CONFIG_HOME/retrodeck in order to solve issue #53 - Remove in a few versions
2024-02-21 15:04:00 +00:00
if [ [ -f " $HOME /retrodeck/.lock " ] ] ; then
2025-03-27 16:52:04 +00:00
mv " $HOME /retrodeck/.lock " " $lockfile "
2022-11-18 20:10:17 +00:00
fi
2022-09-17 15:20:39 +00:00
# If there is no config file I initalize the file with the the default values
2023-04-26 21:02:44 +00:00
if [ [ ! -f " $rd_conf " ] ] ; then
2024-01-04 16:34:02 +00:00
log w " RetroDECK config file not found in $rd_conf "
log i "Initializing"
2022-10-24 19:49:47 +00:00
# if we are here means that the we are in a new installation, so the version is valorized with the hardcoded one
2022-09-19 07:25:49 +00:00
# Initializing the variables
2024-02-21 15:04:00 +00:00
if [ [ -z " $version " ] ] ; then
if [ [ -f " $lockfile " ] ] ; then
2025-03-27 16:52:04 +00:00
if [ [ $( cat " $lockfile " ) = = *"0.4." * ] ] || [ [ $( cat " $lockfile " ) = = *"0.3." * ] ] || [ [ $( cat " $lockfile " ) = = *"0.2." * ] ] || [ [ $( cat " $lockfile " ) = = *"0.1." * ] ] ; then # If the previous version is very out of date, pre-rd_conf
2024-02-28 14:24:39 +00:00
log d "Running version workaround"
2025-03-27 16:52:04 +00:00
version = $( cat " $lockfile " )
2024-02-21 15:04:00 +00:00
fi
2022-10-24 19:49:47 +00:00
else
version = " $hard_version "
fi
2022-10-06 21:47:09 +00:00
fi
2022-10-24 19:49:47 +00:00
2022-12-22 15:34:50 +00:00
# Check if SD card path has changed from SteamOS update
2025-03-27 16:52:04 +00:00
if [ [ ! -d " $default_sd " && " $( ls -A "/run/media/deck/" ) " ] ] ; then
if [ [ $( find "/run/media/deck/" * -maxdepth 0 -type d -print | wc -l) -eq 1 ] ] ; then # If there is only one SD card found in the new SteamOS 3.5 location, assign it as the default
default_sd = " $( find "/run/media/deck/" * -maxdepth 0 -type d -print) "
2023-11-27 15:42:56 +00:00
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
2024-02-21 15:04:00 +00:00
configurator_generic_dialog "RetroDECK Setup" "The SD card was not found in the default location, and multiple drives were detected.\nPlease browse to the location of the desired SD card.\n\nIf you are not using an SD card, please click \"Cancel\"."
2023-11-27 15:42:56 +00:00
default_sd = " $( directory_browse "SD Card Location" ) "
fi
2022-12-22 15:34:50 +00:00
fi
2023-03-11 16:15:16 +00:00
2025-03-27 16:52:04 +00:00
cp " $rd_defaults " " $rd_conf " # Load default settings file
set_setting_value " $rd_conf " "version" " $version " retrodeck # Set current version for new installs
set_setting_value " $rd_conf " "sdcard" " $default_sd " retrodeck "paths" # Set SD card location if default path has changed
2022-09-19 07:25:49 +00:00
2024-04-21 11:35:32 +00:00
if grep -qF "cooker" <<< " $hard_version " || grep -qF "PR-" <<< " $hard_version " ; then # If newly-installed version is a "cooker" or PR build
2025-03-27 16:52:04 +00:00
set_setting_value " $rd_conf " "update_repo" " $cooker_repository_name " retrodeck "options"
set_setting_value " $rd_conf " "update_check" "true" retrodeck "options"
set_setting_value " $rd_conf " "developer_options" "true" retrodeck "options"
2023-04-20 14:51:17 +00:00
fi
2024-01-04 16:34:02 +00:00
log i "Setting config file permissions"
2025-03-27 16:52:04 +00:00
chmod +rw " $rd_conf "
log i " RetroDECK config file initialized. Contents:\n\n $( cat " $rd_conf " ) \n "
2023-04-19 12:39:35 +00:00
conf_read # Load new variables into memory
2024-03-22 09:12:12 +00:00
#tmplog_merger # This function is tempry(?) removed
2022-09-24 18:28:49 +00:00
2023-04-19 12:39:35 +00:00
# If the config file is existing i just read the variables
2022-09-17 15:20:39 +00:00
else
2025-02-21 02:35:14 +00:00
log i " Loading RetroDECK config file in $rd_conf "
2023-04-20 14:51:17 +00:00
2025-03-27 16:52:04 +00:00
if grep -qF "cooker" <<< " $hard_version " ; then # If newly-installed version is a "cooker" build
set_setting_value " $rd_conf " "update_repo" " $cooker_repository_name " retrodeck "options"
set_setting_value " $rd_conf " "update_check" "true" retrodeck "options"
set_setting_value " $rd_conf " "developer_options" "true" retrodeck "options"
2023-04-20 14:51:17 +00:00
fi
2023-04-19 12:39:35 +00:00
conf_read
2022-12-22 15:34:50 +00:00
2023-01-05 14:50:07 +00:00
# Verify rdhome is where it is supposed to be.
2024-02-21 15:04:00 +00:00
if [ [ ! -d " $rdhome " ] ] ; then
2023-05-02 18:46:54 +00:00
configurator_generic_dialog "RetroDECK Setup" "The RetroDECK data folder was not found in the expected location.\nThis may happen when SteamOS is updated.\n\nPlease browse to the current location of the \"retrodeck\" folder."
2023-03-07 15:06:08 +00:00
new_home_path = $( directory_browse "RetroDECK folder location" )
2025-03-27 16:52:04 +00:00
set_setting_value " $rd_conf " "rdhome" " $new_home_path " retrodeck "paths"
2023-04-19 12:39:35 +00:00
conf_read
2024-03-22 09:12:12 +00:00
#tmplog_merger # This function is tempry(?) removed
2025-03-09 19:33:13 +00:00
prepare_component "postmove" "retrodeck"
prepare_component "postmove" "all"
2023-04-25 14:59:57 +00:00
conf_write
2022-12-22 15:34:50 +00:00
fi
2023-08-17 17:38:18 +00:00
# Static variables dependent on $rd_conf values, need to be set after reading $rd_conf
backups_folder = " $rdhome /backups " # A standard location for backup file storage
multi_user_data_folder = " $rdhome /multi-user-data " # The default location of multi-user environment profiles
2022-10-07 06:48:35 +00:00
fi
2024-02-16 16:20:23 +00:00
2025-03-25 13:44:51 +00:00
# Steam ROM Manager user files and paths
steamsync_folder = " $rdhome /.sync " # Folder containing favorites manifest for SRM
retrodeck_favorites_file = " $steamsync_folder /retrodeck_favorites.json " # The current SRM manifest of all games that have been favorited in ES-DE
2025-03-25 15:02:30 +00:00
srm_log = " $logs_folder /srm_log.log " # Log file for capturing the output of the most recent SRM run, for debugging purposes
2025-03-26 15:47:06 +00:00
retrodeck_added_favorites = " $steamsync_folder /retrodeck_added_favorites.json " # Temporary manifest of any games that were newly added to the ES-DE favorites and should be added to Steam
2025-03-25 20:19:59 +00:00
retrodeck_removed_favorites = " $steamsync_folder /retrodeck_removed_favorites.json " # Temporary manifest of any games that were unfavorited in ES-DE and should be removed from Steam
2025-01-23 02:23:22 +00:00
2025-03-05 16:12:26 +00:00
export GLOBAL_SOURCED = true