diff --git a/functions/050_save_migration.sh b/functions/050_save_migration.sh index d569403b..f7a1f108 100644 --- a/functions/050_save_migration.sh +++ b/functions/050_save_migration.sh @@ -32,7 +32,7 @@ save_migration() { # Doing the dir prep as we don't know from which version we came dir_prep "$media_folder" "/var/config/ES-DE/downloaded_media" dir_prep "$themes_folder" "/var/config/ES-DE/themes" - mkdir -pv $rdhome/logs #this was added later, maybe safe to remove in a few versions + create_dir $rdhome/logs #this was added later, maybe safe to remove in a few versions # Resetting es_settings, now we need it but in the future I should think a better solution, maybe with sed cp -fv /app/retrodeck/es_settings.xml /var/config/ES-DE/settings/es_settings.xml diff --git a/functions/checks.sh b/functions/checks.sh index 9f01de7a..16414c57 100644 --- a/functions/checks.sh +++ b/functions/checks.sh @@ -84,7 +84,7 @@ check_for_version_update() { configurator_generic_dialog "RetroDECK Online Update" "The update process may take several minutes.\n\nAfter the update is complete, RetroDECK will close. When you run it again you will be using the latest version." ( local latest_cooker_download=$(curl --silent https://api.github.com/repos/XargonWan/$update_repo/releases/latest | grep '"browser_download_url":' | sed -E 's/.*"([^"]+)".*/\1/') - mkdir -p "$rdhome/RetroDECK_Updates" + create_dir "$rdhome/RetroDECK_Updates" wget -P "$rdhome/RetroDECK_Updates" $latest_cooker_download flatpak-spawn --host flatpak remove --noninteractive -y net.retrodeck.retrodeck # Remove current version before installing new one, to avoid duplicates flatpak-spawn --host flatpak install --user --bundle --noninteractive -y "$rdhome/RetroDECK_Updates/RetroDECK-cooker.flatpak" diff --git a/functions/functions.sh b/functions/functions.sh index b56cd19e..6b1f6fdb 100644 --- a/functions/functions.sh +++ b/functions/functions.sh @@ -73,9 +73,12 @@ verify_space() { source_size=$((source_size+(source_size/10))) # Add 10% to source size for safety dest_avail=$(df -k --output=avail "$2" | tail -1) + log i "Checking free disk space" if [[ $source_size -ge $dest_avail ]]; then + log e "Not enough disk space: $dest_avail" echo "false" else + log i "Disk space is enough: $dest_avail" echo "true" fi } @@ -87,6 +90,8 @@ move() { source_dir="$(echo $1 | sed 's![^/]$!&/!')" # Add trailing slash if it is missing dest_dir="$(echo $2 | sed 's![^/]$!&/!')" # Add trailing slash if it is missing + log d "Moving \"$source_dir\" to \"$dest_dir\"" + ( rsync -a --remove-source-files --ignore-existing --mkpath "$source_dir" "$dest_dir" # Copy files but don't overwrite conflicts find "$source_dir" -type d -empty -delete # Cleanup empty folders that were left behind @@ -104,6 +109,27 @@ move() { fi } +create_dir() { + # A simple function that creates a directory checking if is still there while logging the activity + # If -d it will delete it prior the creation + + if [[ "$1" == "-d" ]]; then + # If "force" flag is provided, delete the directory first + shift # Remove the first argument (-f) + if [[ -e "$1" ]]; then + rm -rf "$1" # Forcefully delete the directory + log d "Found \"$1\", deleting it." + fi + fi + + if [[ ! -d "$1" ]]; then + mkdir -p "$1" # Create directory if it doesn't exist + log d "Created directory: $1" + else + log d "Directory \"$1\" already exists, skipping." + fi +} + download_file() { # Function to download file from the Internet, with Zenity progress bar # USAGE: download_file $source_url $file_dest $file_name @@ -247,12 +273,12 @@ dir_prep() { if [ ! -d "$real" ]; then log d "$real not found, creating it" #DEBUG - mkdir -pv "$real" + create_dir "$real" fi # creating the symlink log d "linking $real in $symlink" #DEBUG - mkdir -pv "$(dirname "$symlink")" # creating the full path except the last folder + create_dir "$(dirname "$symlink")" # creating the full path except the last folder ln -svf "$real" "$symlink" # moving everything from the old folder to the new one, delete the old one @@ -298,7 +324,7 @@ check_bios_files() { } update_rpcs3_firmware() { - mkdir -p "$roms_folder/ps3/tmp" + create_dir "$roms_folder/ps3/tmp" chmod 777 "$roms_folder/ps3/tmp" download_file "$rpcs3_firmware" "$roms_folder/ps3/tmp/PS3UPDAT.PUP" "RPCS3 Firmware" rpcs3 --installfw "$roms_folder/ps3/tmp/PS3UPDAT.PUP" @@ -313,7 +339,7 @@ update_vita3k_firmware() { } backup_retrodeck_userdata() { - mkdir -p "$backups_folder" + create_dir "$backups_folder" zip -rq9 "$backups_folder/$(date +"%0m%0d")_retrodeck_userdata.zip" "$saves_folder" "$states_folder" "$bios_folder" "$media_folder" "$themes_folder" "$logs_folder" "$screenshots_folder" "$mods_folder" "$texture_packs_folder" "$borders_folder" > $logs_folder/$(date +"%0m%0d")_backup_log.log } @@ -519,11 +545,11 @@ install_retrodeck_starterpack() { ## DOOM section ## cp /app/retrodeck/extras/doom1.wad "$roms_folder/doom/doom1.wad" # No -f in case the user already has it - mkdir -p "/var/config/ES-DE/gamelists/doom" + create_dir "/var/config/ES-DE/gamelists/doom" if [[ ! -f "/var/config/ES-DE/gamelists/doom/gamelist.xml" ]]; then # Don't overwrite an existing gamelist cp "/app/retrodeck/rd_prepacks/doom/gamelist.xml" "/var/config/ES-DE/gamelists/doom/gamelist.xml" fi - mkdir -p "$media_folder/doom" + create_dir "$media_folder/doom" unzip -oq "/app/retrodeck/rd_prepacks/doom/doom.zip" -d "$media_folder/doom/" } @@ -679,7 +705,7 @@ branch_selector() { configurator_generic_dialog "RetroDECK Online Update" "The update process may take several minutes.\n\nAfter the update is complete, RetroDECK will close. When you run it again you will be using the latest version." ( local desired_flatpak_file=$(curl --silent $flatpak_file_url | grep '"browser_download_url":' | sed -E 's/.*"([^"]+)".*/\1/') - mkdir -p "$rdhome/RetroDECK_Updates" + create_dir "$rdhome/RetroDECK_Updates" wget -P "$rdhome/RetroDECK_Updates" $desired_flatpak_file flatpak-spawn --host flatpak remove --noninteractive -y net.retrodeck.retrodeck # Remove current version before installing new one, to avoid duplicates flatpak-spawn --host flatpak install --user --bundle --noninteractive -y "$rdhome/RetroDECK_Updates/RetroDECK-cooker.flatpak" diff --git a/functions/global.sh b/functions/global.sh index 3ed2218f..a6290f65 100644 --- a/functions/global.sh +++ b/functions/global.sh @@ -126,7 +126,7 @@ fi # If there is no config file I initalize the file with the the default values if [[ ! -f "$rd_conf" ]]; then - mkdir -p /var/config/retrodeck + create_dir /var/config/retrodeck log w "RetroDECK config file not found in $rd_conf" log i "Initializing" # if we are here means that the we are in a new installation, so the version is valorized with the hardcoded one diff --git a/functions/multi_user.sh b/functions/multi_user.sh index 7895c03b..05231bc0 100644 --- a/functions/multi_user.sh +++ b/functions/multi_user.sh @@ -45,7 +45,7 @@ multi_user_enable_multi_user_mode() { if [[ -d "$multi_user_data_folder" && $(ls -1 "$multi_user_data_folder" | wc -l) -gt 0 ]]; then # If multi-user data folder exists from prior use and is not empty if [[ -d "$multi_user_data_folder/$SteamAppUser" ]]; then # Current user has an existing save folder configurator_generic_dialog "RetroDECK Multi-User Mode" "The current user $SteamAppUser has an existing folder in the multi-user data folder.\n\nThe saves here are likely older than the ones currently used by RetroDECK.\n\nThe old saves will be backed up to $backups_folder and the current saves will be loaded into the multi-user data folder." - mkdir -p "$backups_folder" + create_dir "$backups_folder" tar -C "$multi_user_data_folder" -cahf "$backups_folder/multi-user-backup_$SteamAppUser_$(date +"%Y_%m_%d").zip" "$SteamAppUser" rm -rf "$multi_user_data_folder/$SteamAppUser" # Remove stale data after backup fi @@ -164,18 +164,18 @@ multi_user_return_to_single_user() { # XEMU one-offs, because it stores its config in /var/data, not /var/config like everything else unlink "/var/config/xemu" unlink "/var/data/xemu/xemu" - mkdir -p "/var/config/xemu" + create_dir "/var/config/xemu" mv -f "$multi_user_data_folder/$single_user/config/xemu"/{.[!.],}* "/var/config/xemu" dir_prep "/var/config/xemu" "/var/data/xemu/xemu" - mkdir -p "$saves_folder" - mkdir -p "$states_folder" + create_dir "$saves_folder" + create_dir "$states_folder" mv -f "$multi_user_data_folder/$single_user/saves"/{.[!.],}* "$saves_folder" mv -f "$multi_user_data_folder/$single_user/states"/{.[!.],}* "$states_folder" for emu_conf in $(find "$multi_user_data_folder/$single_user/config" -mindepth 1 -maxdepth 1 -type d -printf '%f\n') do if [[ ! -z $(grep "^$emu_conf$" "$multi_user_emulator_config_dirs") ]]; then unlink "/var/config/$emu_conf" - mkdir -p "/var/config/$emu_conf" + create_dir "/var/config/$emu_conf" mv -f "$multi_user_data_folder/$single_user/config/$emu_conf"/{.[!.],}* "/var/config/$emu_conf" fi done @@ -189,11 +189,11 @@ multi_user_setup_new_user() { unlink "$states_folder" dir_prep "$multi_user_data_folder/$SteamAppUser/saves" "$saves_folder" dir_prep "$multi_user_data_folder/$SteamAppUser/states" "$states_folder" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/retrodeck" + create_dir "$multi_user_data_folder/$SteamAppUser/config/retrodeck" cp -L "$rd_conf" "$multi_user_data_folder/$SteamAppUser/config/retrodeck/retrodeck.cfg" # Copy existing rd_conf file for new user. rm -f "$rd_conf" ln -sfT "$multi_user_data_folder/$SteamAppUser/config/retrodeck/retrodeck.cfg" "$rd_conf" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/retroarch" + create_dir "$multi_user_data_folder/$SteamAppUser/config/retroarch" if [[ ! -L "/var/config/retroarch/retroarch.cfg" ]]; then mv "/var/config/retroarch/retroarch.cfg" "$multi_user_data_folder/$SteamAppUser/config/retroarch/retroarch.cfg" mv "/var/config/retroarch/retroarch-core-options.cfg" "$multi_user_data_folder/$SteamAppUser/config/retroarch/retroarch-core-options.cfg" diff --git a/functions/post_update.sh b/functions/post_update.sh index 26561059..9449a3d5 100644 --- a/functions/post_update.sh +++ b/functions/post_update.sh @@ -106,9 +106,9 @@ post_update() { deploy_single_patch "$emuconfigs/duckstation/settings.ini" "/var/config/duckstation/duckstation-cheevos-upgrade.patch" "$duckstationconf" rm -f "/var/config/duckstation/duckstation-cheevos-upgrade.patch" - mkdir -p "$mods_folder" - mkdir -p "$texture_packs_folder" - mkdir -p "$borders_folder" + create_dir "$mods_folder" + create_dir "$texture_packs_folder" + create_dir "$borders_folder" dir_prep "$mods_folder/Primehack" "/var/data/primehack/Load/GraphicMods" dir_prep "$texture_packs_folder/Primehack" "/var/data/primehack/Load/Textures" @@ -144,13 +144,13 @@ post_update() { rm "$roms_folder/ps3/emudir" configurator_generic_dialog "RetroDECK 0.7.0b Upgrade" "As part of this update and due to a RPCS3 config upgrade, the files that used to exist at\n\n~/retrodeck/roms/ps3/emudir\n\nare now located at\n\n~/retrodeck/bios/rpcs3.\nYour existing files have been moved automatically." fi - mkdir -p "$bios_folder/rpcs3/dev_hdd0" - mkdir -p "$bios_folder/rpcs3/dev_hdd1" - mkdir -p "$bios_folder/rpcs3/dev_flash" - mkdir -p "$bios_folder/rpcs3/dev_flash2" - mkdir -p "$bios_folder/rpcs3/dev_flash3" - mkdir -p "$bios_folder/rpcs3/dev_bdvd" - mkdir -p "$bios_folder/rpcs3/dev_usb000" + create_dir "$bios_folder/rpcs3/dev_hdd0" + create_dir "$bios_folder/rpcs3/dev_hdd1" + create_dir "$bios_folder/rpcs3/dev_flash" + create_dir "$bios_folder/rpcs3/dev_flash2" + create_dir "$bios_folder/rpcs3/dev_flash3" + create_dir "$bios_folder/rpcs3/dev_bdvd" + create_dir "$bios_folder/rpcs3/dev_usb000" dir_prep "$bios_folder/rpcs3/dev_hdd0/home/00000001/savedata" "$saves_folder/ps3/rpcs3" set_setting_value $es_settings "ApplicationUpdaterFrequency" "never" "es_settings" @@ -158,7 +158,7 @@ post_update() { if [[ -f "$saves_folder/duckstation/shared_card_1.mcd" || -f "$saves_folder/duckstation/shared_card_2.mcd" ]]; then configurator_generic_dialog "RetroDECK 0.7.0b Upgrade" "As part of this update, the location of saves and states for Duckstation has been changed.\n\nYour files will be moved automatically, and can now be found at\n\n~.../saves/psx/duckstation/memcards/\nand\n~.../states/psx/duckstation/" fi - mkdir -p "$saves_folder/psx/duckstation/memcards" + create_dir "$saves_folder/psx/duckstation/memcards" mv "$saves_folder/duckstation/"* "$saves_folder/psx/duckstation/memcards/" rmdir "$saves_folder/duckstation" # File-safe folder cleanup unlink "/var/config/duckstation/memcards" @@ -166,7 +166,7 @@ post_update() { set_setting_value "$duckstationconf" "Card2Path" "$saves_folder/psx/duckstation/memcards/shared_card_2.mcd" "duckstation" "MemoryCards" set_setting_value "$duckstationconf" "Directory" "$saves_folder/psx/duckstation/memcards" "duckstation" "MemoryCards" set_setting_value "$duckstationconf" "RecursivePaths" "$roms_folder/psx" "duckstation" "GameList" - mkdir -p "$states_folder/psx" + create_dir "$states_folder/psx" mv -t "$states_folder/psx/" "$states_folder/duckstation" unlink "/var/config/duckstation/savestates" dir_prep "$states_folder/psx/duckstation" "/var/config/duckstation/savestates" @@ -308,7 +308,7 @@ post_update() { # The save folder of rpcs3 was inverted so we're moving the saves into the real one log w "RPCS3 saves needs to be migrated, executing." mv "$saves_folder/ps3/rpcs3" "$saves_folder/ps3/rpcs3.bak" - mkdir -p "$saves_folder/ps3/rpcs3" + create_dir "$saves_folder/ps3/rpcs3" mv -v "$saves_folder/ps3/rpcs3.bak"/* "$saves_folder/ps3/rpcs3" mv -v "$bios_folder/rpcs3/dev_hdd0/home/00000001/savedata"/* "$saves_folder/ps3/rpcs3" mv -v "$saves_folder/ps3/rpcs3.bak" "$rdhome/backups/saves/ps3/rpcs3" diff --git a/functions/prepare_component.sh b/functions/prepare_component.sh index 7ccc6c16..2df58ae7 100644 --- a/functions/prepare_component.sh +++ b/functions/prepare_component.sh @@ -20,10 +20,10 @@ prepare_component() { if [[ ! $current_setting_name =~ (rdhome|sdcard) ]]; then # Ignore these locations local current_setting_value=$(get_setting_value "$rd_conf" "$current_setting_name" "retrodeck" "paths") declare -g "$current_setting_name=$rdhome/$(basename $current_setting_value)" - mkdir -p "$rdhome/$(basename $current_setting_value)" + create_dir "$rdhome/$(basename $current_setting_value)" fi done < <(grep -v '^\s*$' $rd_conf | awk '/^\[paths\]/{f=1;next} /^\[/{f=0} f') - mkdir -p "/var/config/retrodeck/godot" + create_dir "/var/config/retrodeck/godot" fi if [[ "$action" == "postmove" ]]; then # Update the paths of any folders that came with the retrodeck folder during a move while read -r config_line; do @@ -41,7 +41,7 @@ prepare_component() { if [[ "$component" =~ ^(es-de|ES-DE|all)$ ]]; then # For use after ESDE-related folders are moved or a reset if [[ "$action" == "reset" ]]; then rm -rf /var/config/ES-DE - mkdir -p /var/config/ES-DE/settings + create_dir /var/config/ES-DE/settings cp -f /app/retrodeck/es_settings.xml /var/config/ES-DE/settings/es_settings.xml set_setting_value "$es_settings" "ROMDirectory" "$roms_folder" "es_settings" set_setting_value "$es_settings" "MediaDirectory" "$media_folder" "es_settings" @@ -61,16 +61,14 @@ prepare_component() { if [[ "$component" =~ ^(retroarch|RetroArch|all)$ ]]; then if [[ "$action" == "reset" ]]; then # Run reset-only commands if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/retroarch" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/retroarch" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/retroarch" cp -fv $emuconfigs/retroarch/retroarch.cfg "$multi_user_data_folder/$SteamAppUser/config/retroarch/" cp -fv $emuconfigs/retroarch/retroarch-core-options.cfg "$multi_user_data_folder/$SteamAppUser/config/retroarch/" else # Single-user actions - rm -rf /var/config/retroarch - mkdir -p /var/config/retroarch + create_dir -d /var/config/retroarch dir_prep "$bios_folder" "/var/config/retroarch/system" dir_prep "$logs_folder/retroarch" "/var/config/retroarch/logs" - mkdir -pv /var/config/retroarch/shaders/ + create_dir /var/config/retroarch/shaders/ cp -rf /app/share/libretro/shaders /var/config/retroarch/ dir_prep "$rdhome/shaders/retroarch" "/var/config/retroarch/shaders" rsync -rlD --mkpath "/app/share/libretro/cores/" "/var/config/retroarch/cores/" @@ -161,15 +159,13 @@ prepare_component() { log i "Initializing CEMU" log i "----------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/Cemu" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/Cemu" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/Cemu" cp -fr "$emuconfigs/cemu/"* "$multi_user_data_folder/$SteamAppUser/config/Cemu/" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/Cemu/settings.ini" "mlc_path" "$bios_folder/cemu" "cemu" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/Cemu/settings.ini" "Entry" "$roms_folder/wiiu" "cemu" "GamePaths" dir_prep "$multi_user_data_folder/$SteamAppUser/config/Cemu" "/var/config/Cemu" else - rm -rf /var/config/Cemu - mkdir -pv /var/config/Cemu/ + create_dir -d /var/config/Cemu/ cp -fr "$emuconfigs/cemu/"* /var/config/Cemu/ set_setting_value "$cemuconf" "mlc_path" "$bios_folder/cemu" "cemu" set_setting_value "$cemuconf" "Entry" "$roms_folder/wiiu" "cemu" "GamePaths" @@ -190,8 +186,7 @@ prepare_component() { log i "Initializing CITRA" log i "------------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/citra-emu" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/citra-emu" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/citra-emu" cp -fv $emuconfigs/citra/qt-config.ini "$multi_user_data_folder/$SteamAppUser/config/citra-emu/qt-config.ini" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/citra-emu/qt-config.ini" "nand_directory" "$saves_folder/n3ds/citra/nand/" "citra" "Data%20Storage" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/citra-emu/qt-config.ini" "sdmc_directory" "$saves_folder/n3ds/citra/sdmc/" "citra" "Data%20Storage" @@ -199,8 +194,7 @@ prepare_component() { set_setting_value "$multi_user_data_folder/$SteamAppUser/config/citra-emu/qt-config.ini" "Paths\screenshotPath" "$screenshots_folder" "citra" "UI" dir_prep "$multi_user_data_folder/$SteamAppUser/config/citra-emu" "/var/config/citra-emu" else # Single-user actions - rm -rf /var/config/citra-emu - mkdir -pv /var/config/citra-emu/ + create_dir -d /var/config/citra-emu/ cp -f $emuconfigs/citra/qt-config.ini /var/config/citra-emu/qt-config.ini set_setting_value "$citraconf" "nand_directory" "$saves_folder/n3ds/citra/nand/" "citra" "Data%20Storage" set_setting_value "$citraconf" "sdmc_directory" "$saves_folder/n3ds/citra/sdmc/" "citra" "Data%20Storage" @@ -208,8 +202,8 @@ prepare_component() { set_setting_value "$citraconf" "Paths\screenshotPath" "$screenshots_folder" "citra" "UI" fi # Shared actions - mkdir -pv "$saves_folder/n3ds/citra/nand/" - mkdir -pv "$saves_folder/n3ds/citra/sdmc/" + create_dir "$saves_folder/n3ds/citra/nand/" + create_dir "$saves_folder/n3ds/citra/sdmc/" dir_prep "$bios_folder/citra/sysdata" "/var/data/citra-emu/sysdata" dir_prep "$logs_folder/citra" "/var/data/citra-emu/log" dir_prep "$mods_folder/Citra" "/var/data/citra-emu/load/mods" @@ -237,8 +231,7 @@ prepare_component() { log i "Initializing DOLPHIN" log i "----------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/dolphin-emu" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/dolphin-emu" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/dolphin-emu" cp -fvr "$emuconfigs/dolphin/"* "$multi_user_data_folder/$SteamAppUser/config/dolphin-emu/" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/dolphin-emu/Dolphin.ini" "BIOS" "$bios_folder" "dolphin" "GBA" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/dolphin-emu/Dolphin.ini" "SavesPath" "$saves_folder/gba" "dolphin" "GBA" @@ -247,8 +240,7 @@ prepare_component() { set_setting_value "$multi_user_data_folder/$SteamAppUser/config/dolphin-emu/Dolphin.ini" "WiiSDCardPath" "$saves_folder/wii/dolphin/sd.raw" "dolphin" "General" dir_prep "$multi_user_data_folder/$SteamAppUser/config/dolphin-emu" "/var/config/dolphin-emu" else # Single-user actions - rm -rf /var/config/dolphin-emu - mkdir -pv /var/config/dolphin-emu/ + create_dir -d /var/config/dolphin-emu/ cp -fvr "$emuconfigs/dolphin/"* /var/config/dolphin-emu/ set_setting_value "$dolphinconf" "BIOS" "$bios_folder" "dolphin" "GBA" set_setting_value "$dolphinconf" "SavesPath" "$saves_folder/gba" "dolphin" "GBA" @@ -292,8 +284,7 @@ prepare_component() { log i "Initializing DUCKSTATION" log i "------------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/duckstation" - mkdir -p "$multi_user_data_folder/$SteamAppUser/data/duckstation/" + create_dir -d "$multi_user_data_folder/$SteamAppUser/data/duckstation/" cp -fv "$emuconfigs/duckstation/"* "$multi_user_data_folder/$SteamAppUser/data/duckstation" set_setting_value "$multi_user_data_folder/$SteamAppUser/data/duckstation/settings.ini" "SearchDirectory" "$bios_folder" "duckstation" "BIOS" set_setting_value "$multi_user_data_folder/$SteamAppUser/data/duckstation/settings.ini" "Card1Path" "$saves_folder/psx/duckstation/memcards/shared_card_1.mcd" "duckstation" "MemoryCards" @@ -302,9 +293,8 @@ prepare_component() { set_setting_value "$multi_user_data_folder/$SteamAppUser/data/duckstation/settings.ini" "RecursivePaths" "$roms_folder/psx" "duckstation" "GameList" dir_prep "$multi_user_data_folder/$SteamAppUser/config/duckstation" "/var/config/duckstation" else # Single-user actions - rm -rf "/var/config/duckstation" - mkdir -p "/var/config/duckstation/" - mkdir -p "$saves_folder/psx/duckstation/memcards" + create_dir -d "/var/config/duckstation/" + create_dir "$saves_folder/psx/duckstation/memcards" cp -fv "$emuconfigs/duckstation/"* /var/config/duckstation set_setting_value "$duckstationconf" "SearchDirectory" "$bios_folder" "duckstation" "BIOS" set_setting_value "$duckstationconf" "Card1Path" "$saves_folder/psx/duckstation/memcards/shared_card_1.mcd" "duckstation" "MemoryCards" @@ -339,8 +329,7 @@ prepare_component() { log i "Initializing MELONDS" log i "----------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/melonDS" - mkdir -pv "$multi_user_data_folder/$SteamAppUser/config/melonDS/" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/melonDS/" cp -fvr $emuconfigs/melonds/melonDS.ini "$multi_user_data_folder/$SteamAppUser/config/melonDS/" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/melonDS/melonDS.ini" "BIOS9Path" "$bios_folder/bios9.bin" "melonds" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/melonDS/melonDS.ini" "BIOS7Path" "$bios_folder/bios7.bin" "melonds" @@ -349,8 +338,7 @@ prepare_component() { set_setting_value "$multi_user_data_folder/$SteamAppUser/config/melonDS/melonDS.ini" "SavestatePath" "$states_folder/nds/melonds" "melonds" dir_prep "$multi_user_data_folder/$SteamAppUser/config/melonDS" "/var/config/melonDS" else # Single-user actions - rm -rf /var/config/melonDS - mkdir -pv /var/config/melonDS/ + create_dir -d /var/config/melonDS/ cp -fvr $emuconfigs/melonds/melonDS.ini /var/config/melonDS/ set_setting_value "$melondsconf" "BIOS9Path" "$bios_folder/bios9.bin" "melonds" set_setting_value "$melondsconf" "BIOS7Path" "$bios_folder/bios7.bin" "melonds" @@ -359,8 +347,8 @@ prepare_component() { set_setting_value "$melondsconf" "SavestatePath" "$states_folder/nds/melonds" "melonds" fi # Shared actions - mkdir -pv "$saves_folder/nds/melonds" - mkdir -pv "$states_folder/nds/melonds" + create_dir "$saves_folder/nds/melonds" + create_dir "$states_folder/nds/melonds" dir_prep "$bios_folder" "/var/config/melonDS/bios" fi if [[ "$action" == "postmove" ]]; then # Run only post-move commands @@ -379,8 +367,7 @@ prepare_component() { log i "Initializing PCSX2" log i "----------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/PCSX2" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/PCSX2/inis" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/PCSX2/inis" cp -fvr "$emuconfigs/PCSX2/"* "$multi_user_data_folder/$SteamAppUser/config/PCSX2/inis/" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/PCSX2/inis/PCSX2.ini" "Bios" "$bios_folder" "pcsx2" "Folders" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/PCSX2/inis/PCSX2.ini" "Snapshots" "$screenshots_folder" "pcsx2" "Folders" @@ -389,8 +376,7 @@ prepare_component() { set_setting_value "$multi_user_data_folder/$SteamAppUser/config/PCSX2/inis/PCSX2.ini" "RecursivePaths" "$roms_folder/ps2" "pcsx2" "GameList" dir_prep "$multi_user_data_folder/$SteamAppUser/config/PCSX2" "/var/config/PCSX2" else # Single-user actions - rm -rf /var/config/PCSX2 - mkdir -pv "/var/config/PCSX2/inis" + create_dir -d "/var/config/PCSX2/inis" cp -fvr "$emuconfigs/PCSX2/"* /var/config/PCSX2/inis/ set_setting_value "$pcsx2conf" "Bios" "$bios_folder" "pcsx2" "Folders" set_setting_value "$pcsx2conf" "Snapshots" "$screenshots_folder" "pcsx2" "Folders" @@ -399,8 +385,8 @@ prepare_component() { set_setting_value "$pcsx2conf" "RecursivePaths" "$roms_folder/ps2" "pcsx2" "GameList" fi # Shared actions - mkdir -pv "$saves_folder/ps2/pcsx2/memcards" - mkdir -pv "$states_folder/ps2/pcsx2" + create_dir "$saves_folder/ps2/pcsx2/memcards" + create_dir "$states_folder/ps2/pcsx2" dir_prep "$texture_packs_folder/PCSX2" "/var/config/PCSX2/textures" # Reset default preset settings @@ -435,14 +421,12 @@ prepare_component() { log i "Initializing PPSSPPSDL" log i "------------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/ppsspp" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/ppsspp/PSP/SYSTEM/" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/ppsspp/PSP/SYSTEM/" cp -fv "$emuconfigs/ppssppsdl/"* "$multi_user_data_folder/$SteamAppUser/config/ppsspp/PSP/SYSTEM/" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/ppsspp/PSP/SYSTEM/ppsspp.ini" "CurrentDirectory" "$roms_folder/psp" "ppsspp" "General" dir_prep "$multi_user_data_folder/$SteamAppUser/config/ppsspp" "/var/config/ppsspp" else # Single-user actions - rm -rf /var/config/ppsspp - mkdir -p /var/config/ppsspp/PSP/SYSTEM/ + create_dir -d /var/config/ppsspp/PSP/SYSTEM/ cp -fv "$emuconfigs/ppssppsdl/"* /var/config/ppsspp/PSP/SYSTEM/ set_setting_value "$ppssppconf" "CurrentDirectory" "$roms_folder/psp" "ppsspp" "General" fi @@ -465,14 +449,12 @@ prepare_component() { log i "Initializing Primehack" log i "----------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/primehack" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/primehack" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/primehack" cp -fvr "$emuconfigs/primehack/"* "$multi_user_data_folder/$SteamAppUser/config/primehack/" set_setting_value ""$multi_user_data_folder/$SteamAppUser/config/primehack/Dolphin.ini"" "ISOPath0" "$roms_folder/gc" "primehack" "General" dir_prep "$multi_user_data_folder/$SteamAppUser/config/primehack" "/var/config/primehack" else # Single-user actions - rm -rf /var/config/primehack - mkdir -pv /var/config/primehack/ + create_dir -d /var/config/primehack/ cp -fvr "$emuconfigs/primehack/"* /var/config/primehack/ set_setting_value "$primehackconf" "ISOPath0" "$roms_folder/gc" "primehack" "General" fi @@ -482,7 +464,7 @@ prepare_component() { dir_prep "$saves_folder/gc/primehack/JP" "/var/data/primehack/GC/JAP" dir_prep "$screenshots_folder" "/var/data/primehack/ScreenShots" dir_prep "$states_folder/primehack" "/var/data/primehack/StateSaves" - mkdir -pv /var/data/primehack/Wii/ + create_dir /var/data/primehack/Wii/ dir_prep "$saves_folder/wii/primehack" "/var/data/primehack/Wii" dir_prep "$mods_folder/Primehack" "/var/data/primehack/Load/GraphicMods" dir_prep "$texture_packs_folder/Primehack" "/var/data/primehack/Load/Textures" @@ -509,16 +491,14 @@ prepare_component() { log i "Initializing RPCS3" log i "------------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/rpcs3" - mkdir -pv "$multi_user_data_folder/$SteamAppUser/config/rpcs3/" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/rpcs3/" cp -fr "$emuconfigs/rpcs3/"* "$multi_user_data_folder/$SteamAppUser/config/rpcs3/" # This is an unfortunate one-off because set_setting_value does not currently support settings with $ in the name. sed -i 's^\^$(EmulatorDir): .*^$(EmulatorDir): '"$bios_folder/rpcs3/"'^' "$multi_user_data_folder/$SteamAppUser/config/rpcs3/vfs.yml" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/rpcs3/vfs.yml" "/games/" "$roms_folder/ps3/" "rpcs3" dir_prep "$multi_user_data_folder/$SteamAppUser/config/rpcs3" "/var/config/rpcs3" else # Single-user actions - rm -rf /var/config/rpcs3 - mkdir -pv /var/config/rpcs3/ + create_dir -d /var/config/rpcs3/ cp -fr "$emuconfigs/rpcs3/"* /var/config/rpcs3/ # This is an unfortunate one-off because set_setting_value does not currently support settings with $ in the name. sed -i 's^\^$(EmulatorDir): .*^$(EmulatorDir): '"$bios_folder/rpcs3/"'^' "$rpcs3vfsconf" @@ -526,13 +506,13 @@ prepare_component() { dir_prep "$saves_folder/ps3/rpcs3" "$bios_folder/rpcs3/dev_hdd0/home/00000001/savedata" fi # Shared actions - mkdir -p "$bios_folder/rpcs3/dev_hdd0" - mkdir -p "$bios_folder/rpcs3/dev_hdd1" - mkdir -p "$bios_folder/rpcs3/dev_flash" - mkdir -p "$bios_folder/rpcs3/dev_flash2" - mkdir -p "$bios_folder/rpcs3/dev_flash3" - mkdir -p "$bios_folder/rpcs3/dev_bdvd" - mkdir -p "$bios_folder/rpcs3/dev_usb000" + create_dir "$bios_folder/rpcs3/dev_hdd0" + create_dir "$bios_folder/rpcs3/dev_hdd1" + create_dir "$bios_folder/rpcs3/dev_flash" + create_dir "$bios_folder/rpcs3/dev_flash2" + create_dir "$bios_folder/rpcs3/dev_flash3" + create_dir "$bios_folder/rpcs3/dev_bdvd" + create_dir "$bios_folder/rpcs3/dev_usb000" fi if [[ "$action" == "postmove" ]]; then # Run only post-move commands # This is an unfortunate one-off because set_setting_value does not currently support settings with $ in the name. @@ -550,7 +530,7 @@ prepare_component() { log i "------------------------" if [[ $multi_user_mode == "true" ]]; then rm -rf "$multi_user_data_folder/$SteamAppUser/config/Ryujinx" - #mkdir -p "$multi_user_data_folder/$SteamAppUser/config/Ryujinx/system" + #create_dir "$multi_user_data_folder/$SteamAppUser/config/Ryujinx/system" # TODO: add /var/config/Ryujinx/system system folder management cp -fv $emuconfigs/ryujinx/* "$multi_user_data_folder/$SteamAppUser/config/Ryujinx" sed -i 's#RETRODECKHOMEDIR#'$rdhome'#g' "$multi_user_data_folder/$SteamAppUser/config/Ryujinx/Config.json" @@ -561,7 +541,7 @@ prepare_component() { else # removing config directory to wipe legacy files rm -rf /var/config/Ryujinx - mkdir -p /var/config/Ryujinx/system + create_dir /var/config/Ryujinx/system cp -fv $emuconfigs/ryujinx/* /var/config/Ryujinx sed -i 's#RETRODECKHOMEDIR#'$rdhome'#g' "$ryujinxconf" # Linking switch nand/saves folder @@ -587,8 +567,7 @@ prepare_component() { if [[ $multi_user_mode == "true" ]]; then # Multi-user actions rm -rf /var/config/xemu rm -rf /var/data/xemu - rm -rf "$multi_user_data_folder/$SteamAppUser/config/xemu" - mkdir -pv "$multi_user_data_folder/$SteamAppUser/config/xemu/" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/xemu/" cp -fv $emuconfigs/xemu/xemu.toml "$multi_user_data_folder/$SteamAppUser/config/xemu/xemu.toml" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/xemu/xemu.toml" "screenshot_dir" "'$screenshots_folder'" "xemu" "General" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/xemu/xemu.toml" "bootrom_path" "'$bios_folder/mcpx_1.0.bin'" "xemu" "sys.files" @@ -608,7 +587,7 @@ prepare_component() { set_setting_value "$xemuconf" "eeprom_path" "'$saves_folder/xbox/xemu/xbox-eeprom.bin'" "xemu" "sys.files" set_setting_value "$xemuconf" "hdd_path" "'$bios_folder/xbox_hdd.qcow2'" "xemu" "sys.files" fi # Shared actions - mkdir -pv $saves_folder/xbox/xemu/ + create_dir $saves_folder/xbox/xemu/ # Preparing HD dummy Image if the image is not found if [ ! -f $bios_folder/xbox_hdd.qcow2 ] then @@ -630,8 +609,7 @@ prepare_component() { log i "Initializing YUZU" log i "----------------------" if [[ $multi_user_mode == "true" ]]; then # Multi-user actions - rm -rf "$multi_user_data_folder/$SteamAppUser/config/yuzu" - mkdir -p "$multi_user_data_folder/$SteamAppUser/config/yuzu" + create_dir -d "$multi_user_data_folder/$SteamAppUser/config/yuzu" cp -fvr "$emuconfigs/yuzu/"* "$multi_user_data_folder/$SteamAppUser/config/yuzu/" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/yuzu/qt-config.ini" "nand_directory" "$saves_folder/switch/yuzu/nand" "yuzu" "Data%20Storage" set_setting_value "$multi_user_data_folder/$SteamAppUser/config/yuzu/qt-config.ini" "sdmc_directory" "$saves_folder/switch/yuzu/sdmc" "yuzu" "Data%20Storage" @@ -639,8 +617,7 @@ prepare_component() { set_setting_value "$multi_user_data_folder/$SteamAppUser/config/yuzu/qt-config.ini" "Screenshots\screenshot_path" "$screenshots_folder" "yuzu" "UI" dir_prep "$multi_user_data_folder/$SteamAppUser/config/yuzu" "/var/config/yuzu" else # Single-user actions - rm -rf /var/config/yuzu - mkdir -pv /var/config/yuzu/ + create_dir -d /var/config/yuzu/ cp -fvr "$emuconfigs/yuzu/"* /var/config/yuzu/ set_setting_value "$yuzuconf" "nand_directory" "$saves_folder/switch/yuzu/nand" "yuzu" "Data%20Storage" set_setting_value "$yuzuconf" "sdmc_directory" "$saves_folder/switch/yuzu/sdmc" "yuzu" "Data%20Storage" @@ -655,7 +632,7 @@ prepare_component() { dir_prep "$logs_folder/yuzu" "/var/data/yuzu/log" dir_prep "$screenshots_folder" "/var/data/yuzu/screenshots" dir_prep "$mods_folder/Yuzu" "/var/data/yuzu/load" - mkdir -pv "$rdhome/customs/yuzu" + create_dir "$rdhome/customs/yuzu" # removing dead symlinks as they were present in a past version if [ -d $bios_folder/switch ]; then find $bios_folder/switch -xtype l -exec rm {} \; @@ -690,7 +667,7 @@ prepare_component() { else # Single-user actions # NOTE: the component is writing in "." so it must be placed in the rw filesystem. A symlink of the binary is already placed in /app/bin/Vita3K rm -rf "/var/data/Vita3K" - mkdir -p "/var/data/Vita3K/Vita3K" + create_dir "/var/data/Vita3K/Vita3K" cp -fvr "$emuconfigs/vita3k/config.yml" "/var/data/Vita3K" # component config cp -fvr "$emuconfigs/vita3k/ux0" "$bios_folder/Vita3K/Vita3K" # User config set_setting_value "$vita3kconf" "pref-path" "$rdhome/bios/Vita3K/Vita3K/" "vita3k" @@ -712,49 +689,49 @@ prepare_component() { log i "----------------------" # TODO: probably some of these needs to be put elsewhere - mkdir -p "$saves_folder/mame-sa" - mkdir -p "$saves_folder/mame-sa/nvram" - mkdir -p "$states_folder/mame-sa" - mkdir -p "$rdhome/screenshots/mame-sa" - mkdir -p "$saves_folder/mame-sa/diff" + create_dir "$saves_folder/mame-sa" + create_dir "$saves_folder/mame-sa/nvram" + create_dir "$states_folder/mame-sa" + create_dir "$rdhome/screenshots/mame-sa" + create_dir "$saves_folder/mame-sa/diff" - mkdir -p "/var/config/ctrlr" - mkdir -p "/var/config/mame/ini" - mkdir -p "/var/config/mame/cfg" - mkdir -p "/var/config/mame/inp" + create_dir "/var/config/ctrlr" + create_dir "/var/config/mame/ini" + create_dir "/var/config/mame/cfg" + create_dir "/var/config/mame/inp" - mkdir -p "/var/data/mame/plugin-data" - mkdir -p "/var/data/mame/hash" - mkdir -p "/var/data/mame/assets/samples" - mkdir -p "/var/data/mame/assets/artwork" - mkdir -p "/var/data/mame/assets/fonts" - mkdir -p "/var/data/mame/cheat" - mkdir -p "/var/data/mame/assets/crosshair" - mkdir -p "/var/data/mame/plugins" - mkdir -p "/var/data/mame/assets/language" - mkdir -p "/var/data/mame/assets/software" - mkdir -p "/var/data/mame/assets/comments" - mkdir -p "/var/data/mame/assets/share" - mkdir -p "/var/data/mame/dats" - mkdir -p "/var/data/mame/folders" - mkdir -p "/var/data/mame/assets/cabinets" - mkdir -p "/var/data/mame/assets/cpanel" - mkdir -p "/var/data/mame/assets/pcb" - mkdir -p "/var/data/mame/assets/flyers" - mkdir -p "/var/data/mame/assets/titles" - mkdir -p "/var/data/mame/assets/ends" - mkdir -p "/var/data/mame/assets/marquees" - mkdir -p "/var/data/mame/assets/artwork-preview" - mkdir -p "/var/data/mame/assets/bosses" - mkdir -p "/var/data/mame/assets/logo" - mkdir -p "/var/data/mame/assets/scores" - mkdir -p "/var/data/mame/assets/versus" - mkdir -p "/var/data/mame/assets/gameover" - mkdir -p "/var/data/mame/assets/howto" - mkdir -p "/var/data/mame/assets/select" - mkdir -p "/var/data/mame/assets/icons" - mkdir -p "/var/data/mame/assets/covers" - mkdir -p "/var/data/mame/assets/ui" + create_dir "/var/data/mame/plugin-data" + create_dir "/var/data/mame/hash" + create_dir "/var/data/mame/assets/samples" + create_dir "/var/data/mame/assets/artwork" + create_dir "/var/data/mame/assets/fonts" + create_dir "/var/data/mame/cheat" + create_dir "/var/data/mame/assets/crosshair" + create_dir "/var/data/mame/plugins" + create_dir "/var/data/mame/assets/language" + create_dir "/var/data/mame/assets/software" + create_dir "/var/data/mame/assets/comments" + create_dir "/var/data/mame/assets/share" + create_dir "/var/data/mame/dats" + create_dir "/var/data/mame/folders" + create_dir "/var/data/mame/assets/cabinets" + create_dir "/var/data/mame/assets/cpanel" + create_dir "/var/data/mame/assets/pcb" + create_dir "/var/data/mame/assets/flyers" + create_dir "/var/data/mame/assets/titles" + create_dir "/var/data/mame/assets/ends" + create_dir "/var/data/mame/assets/marquees" + create_dir "/var/data/mame/assets/artwork-preview" + create_dir "/var/data/mame/assets/bosses" + create_dir "/var/data/mame/assets/logo" + create_dir "/var/data/mame/assets/scores" + create_dir "/var/data/mame/assets/versus" + create_dir "/var/data/mame/assets/gameover" + create_dir "/var/data/mame/assets/howto" + create_dir "/var/data/mame/assets/select" + create_dir "/var/data/mame/assets/icons" + create_dir "/var/data/mame/assets/covers" + create_dir "/var/data/mame/assets/ui" dir_prep "$saves_folder/mame-sa/hiscore" "/var/config/mame/hiscore" cp -fvr "$emuconfigs/mame/mame.ini" "$mameconf" @@ -776,8 +753,8 @@ prepare_component() { log i "Initializing GZDOOM" log i "----------------------" - mkdir -p "/var/config/gzdoom" - mkdir -p "/var/data/gzdoom" + create_dir "/var/config/gzdoom" + create_dir "/var/data/gzdoom" cp -fvr "$emuconfigs/gzdoom/gzdoom.ini" "/var/config/gzdoom" cp -fvr "$emuconfigs/gzdoom/gzdoom.pk3" "/var/data/gzdoom" @@ -790,7 +767,7 @@ prepare_component() { log i "Initializing BOILR" log i "----------------------" - mkdir -p "/var/config/boilr" + create_dir "/var/config/boilr" cp -fvr "/app/libexec/steam-sync/config.toml" "/var/config/boilr" fi diff --git a/functions/presets.sh b/functions/presets.sh index d214461a..c5d8af4a 100644 --- a/functions/presets.sh +++ b/functions/presets.sh @@ -125,7 +125,7 @@ build_preset_config() { fi if [[ "$read_config_format" == "retroarch" && ! "$retroarch_all" == "true" ]]; then # If this is a RetroArch core, generate the override file if [[ ! -f "$read_target_file" ]]; then - mkdir -p "$(realpath "$(dirname "$read_target_file")")" + create_dir "$(realpath "$(dirname "$read_target_file")")" echo "$read_setting_name = \""$new_setting_value"\"" > "$read_target_file" else if [[ -z $(grep "$read_setting_name" "$read_target_file") ]]; then