From 6619191a1530ede3c423709b77e5ee8cf2ed03bd Mon Sep 17 00:00:00 2001 From: icenine451 Date: Thu, 20 Apr 2023 10:51:17 -0400 Subject: [PATCH] Add universal function wrapper Upgrade cooker update flow Upgrade update_rd_conf, no more patch file since they are all bash vars --- functions.sh | 31 ++++++++++++++--------------- global.sh | 11 ++++++++++ net.retrodeck.retrodeck.yml | 2 ++ post_update.sh | 8 ++------ retrodeck.sh | 8 +++----- tools/retrodeck_function_wrapper.sh | 25 +++++++++++++++++++++++ 6 files changed, 58 insertions(+), 27 deletions(-) create mode 100644 tools/retrodeck_function_wrapper.sh diff --git a/functions.sh b/functions.sh index b9dbb3c9..548b601e 100644 --- a/functions.sh +++ b/functions.sh @@ -99,7 +99,7 @@ move() { zenity --icon-name=net.retrodeck.retrodeck --progress --no-cancel --pulsate --auto-close \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ --title "RetroDECK Configurator Utility - Move in Progress" \ - --text="Moving directory $1 to new location of $2, please wait." + --text="Moving directory $(basename "$1") to new location of $2, please wait." else zenity --icon-name=net.retrodeck.retrodeck --error --no-wrap \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ @@ -779,14 +779,11 @@ update_rd_conf() { # This function will import a default retrodeck.cfg file and update it with any current settings. This will allow us to expand the file over time while retaining current user settings. # USAGE: update_rd_conf + conf_read # Read current settings into memory mv -f $rd_conf $rd_conf_backup # Backup config file before update - - generate_single_patch $rd_defaults $rd_conf_backup $rd_update_patch retrodeck - sed -i '/change^^version/d' $rd_update_patch # Remove version line from temporary patch file, so old value isn't kept - deploy_single_patch $rd_defaults $rd_update_patch $rd_conf - set_setting_value $rd_conf "version" "$hard_version" retrodeck # Set version of currently running RetroDECK to updated retrodeck.cfg - rm -f $rd_update_patch # Cleanup temporary patch file - conf_read + cp $rd_defaults $rd_conf # Copy defaults file into place + conf_write # Write old values into new default file + conf_read # Read all settings into memory } resolve_preset_conflicts() { @@ -1172,15 +1169,17 @@ update_splashscreens() { } deploy_helper_files() { + # This script will distribute helper documentation files throughout the filesystem according to the $helper_files_list + # USAGE: deploy_helper_files -while IFS='^' read -r file dest -do - if [[ ! "$file" == "#"* ]] && [[ ! -z "$file" ]]; then - eval current_dest="$dest" - cp -f "$helper_files_folder/$file" "$current_dest/$file" - fi + while IFS='^' read -r file dest + do + if [[ ! "$file" == "#"* ]] && [[ ! -z "$file" ]]; then + eval current_dest="$dest" + cp -f "$helper_files_folder/$file" "$current_dest/$file" + fi -done < "$helper_files_list" + done < "$helper_files_list" } prepare_emulator() { @@ -1966,7 +1965,7 @@ finit() { mkdir -p "/var/config/emulationstation/.emulationstation/gamelists/doom" cp "/app/retrodeck/rd_prepacks/doom/gamelist.xml" "/var/config/emulationstation/.emulationstation/gamelists/doom/gamelist.xml" mkdir -p "$media_folder/doom" - unzip -q "/app/retrodeck/rd_prepacks/doom/doom.zip" -d "$media_folder/doom/" + unzip -oq "/app/retrodeck/rd_prepacks/doom/doom.zip" -d "$media_folder/doom/" tools_init prepare_emulator "reset" "all" diff --git a/global.sh b/global.sh index 3a903232..58151bb3 100755 --- a/global.sh +++ b/global.sh @@ -116,6 +116,11 @@ then 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 + if grep -qF "cooker" <<< $hard_version; then # If newly-installed version is a "cooker" build + set_setting_value $rd_conf "update_repo" "RetroDECK-cooker" retrodeck "options" + set_setting_value $rd_conf "update_check" "true" retrodeck "options" + fi + echo "Setting config file permissions" chmod +rw $rd_conf echo "RetroDECK config file initialized. Contents:" @@ -127,6 +132,12 @@ then else echo "Found RetroDECK config file in $rd_conf" echo "Loading it" + + if grep -qF "cooker" <<< $hard_version; then # If newly-installed version is a "cooker" build + set_setting_value $rd_conf "update_repo" "RetroDECK-cooker" retrodeck "options" + set_setting_value $rd_conf "update_check" "true" retrodeck "options" + fi + conf_read # Verify rdhome is where it is supposed to be. diff --git a/net.retrodeck.retrodeck.yml b/net.retrodeck.retrodeck.yml index 7d0c7105..29be7c74 100644 --- a/net.retrodeck.retrodeck.yml +++ b/net.retrodeck.retrodeck.yml @@ -1220,6 +1220,8 @@ modules: - cp tools/configurator.sh /app/tools/configurator.sh - chmod +x /app/tools/configurator.sh - cp es-configs/tools-gamelist.xml /app/retrodeck/tools-gamelist.xml + - cp tools/retrodeck_function_wrapper.sh /app/tools/retrodeck_function_wrapper.sh + - chmod +x /app/tools/retrodeck_function_wrapper.sh # Function libraries - mkdir -p /app/libexec diff --git a/post_update.sh b/post_update.sh index 68a54425..0c944afa 100644 --- a/post_update.sh +++ b/post_update.sh @@ -86,15 +86,11 @@ post_update() { dir_prep "$rdhome/gamelists" "/var/config/emulationstation/.emulationstation/gamelists" - sed -i '/version=.*/G' $rd_conf - sed -i '3i [paths]' $rd_conf - sed -i '/^power_user_warning=.*/i [options]' $rd_conf - 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" - cp "/app/retrodeck/rd_prepacks/doom/gamelist.xml" "/var/config/emulationstation/.emulationstation/gamelists/doom/gamelist.xml" + cp -f "/app/retrodeck/rd_prepacks/doom/gamelist.xml" "/var/config/emulationstation/.emulationstation/gamelists/doom/gamelist.xml" mkdir -p "$media_folder/doom" - unzip -q "/app/retrodeck/rd_prepacks/doom/doom.zip" -d "$media_folder/doom/" + unzip -oq "/app/retrodeck/rd_prepacks/doom/doom.zip" -d "$media_folder/doom/" fi # The following commands are run every time. diff --git a/retrodeck.sh b/retrodeck.sh index b6dc2969..6de347fe 100644 --- a/retrodeck.sh +++ b/retrodeck.sh @@ -104,15 +104,12 @@ then if [ "$hard_version" != "$version" ]; then echo "Config file's version is $version but the actual version is $hard_version" - if grep -qF "cooker" <<< $hard_version; then # If newly-installed version is a "cooker" build - set_setting_value $rd_conf "update_repo" "RetroDECK-cooker" retrodeck "options" - set_setting_value $rd_conf "update_check" "true" retrodeck "options" - cooker_base_version=$(echo $hard_version | cut -d'-' -f2 | sed 's/\([0-9]\.[0-9][a-z]\).*/\1/') + cooker_base_version=$(echo $hard_version | cut -d'-' -f2) choice=$(zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="Upgrade" --extra-button="Don't Upgrade" --extra-button="Fresh Install" \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ --title "RetroDECK Cooker Upgrade" \ - --text="You appear to be upgrading to a \"cooker\" build of RetroDECK.\n\nWould you like to perform the standard post-update process, skip the post-update process or remove ALL existing RetroDECK data to start from a fresh install?") + --text="You appear to be upgrading to a \"cooker\" build of RetroDECK.\n\nWould you like to perform the standard post-update process, skip the post-update process or remove ALL existing RetroDECK data to start from a fresh install?\n\nPerforming the normal post-update process multiple times may lead to unexpected results.") rc=$? # Capture return code, as "Yes" button has no text value if [[ $rc == "1" ]]; then # If any button other than "Yes" was clicked if [[ $choice == "Don't Upgrade" ]]; then # If user wants to bypass the post_update.sh process this time. @@ -122,6 +119,7 @@ then echo "Removing RetroDECK data and starting fresh" rm -rf /var rm -rf "$HOME/retrodeck" + source /app/libexec/global.sh finit fi else diff --git a/tools/retrodeck_function_wrapper.sh b/tools/retrodeck_function_wrapper.sh new file mode 100644 index 00000000..98148ab8 --- /dev/null +++ b/tools/retrodeck_function_wrapper.sh @@ -0,0 +1,25 @@ +#!/bin/bash + +# This wrapper will run a single RetroDECK function with any number of arguments +# USAGE: /bin/bash retrodeck_function_wrapper.sh ... + +source /app/libexec/global.sh + +# Check if a function was specified +if [[ $# -lt 1 ]]; then + echo "Usage: $0 function_name [args...]" + exit 1 +fi + +# Get the function name and remove it from the list of arguments +function_name="$1" +shift + +# Check if the function exists +if ! declare -f "$function_name" >/dev/null 2>&1; then + echo "Function '$function_name' not found" + exit 1 +fi + +# Call the function with any remaining arguments +"$function_name" "$@"