diff --git a/functions/checks.sh b/functions/checks.sh index 7a664017..55b24df3 100644 --- a/functions/checks.sh +++ b/functions/checks.sh @@ -40,6 +40,7 @@ check_is_steam_deck() { } check_for_version_update() { + # TODO logging # This function will perform a basic online version check and alert the user if there is a new version available. log d "Entering funtcion check_for_version_update" @@ -47,34 +48,18 @@ check_for_version_update() { wget -q --spider "https://api.github.com/repos/$git_organization_name/$update_repo/releases/latest" if [ $? -eq 0 ]; then - local online_version=$(curl --silent "https://api.github.com/repos/$git_organization_name/$update_repo/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + + # Check if $selected_branch is not set + if [[ -z "$selected_branch" ]]; then + # If $selected_branch is not set, get the latest release tag from GitHub API + local online_version=$(curl --silent "https://api.github.com/repos/$git_organization_name/$update_repo/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/') + else + local online_version=$(curl -s "https://api.github.com/repos/$git_organization_name/$update_repo/releases" | jq -r --arg bn "$branch_name" 'sort_by(.published_at) | .[] | select(.tag_name | contains($bn)) | .tag_name' | tail -n 1) + fi if [[ ! "$update_ignore" == "$online_version" ]]; then if [[ "$update_repo" == "RetroDECK" ]] && [[ $(sed -e 's/[\.a-z]//g' <<< $version) -le $(sed -e 's/[\.a-z]//g' <<< $online_version) ]]; then - # choice=$(rd_zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="Yes" --extra-button="No" --extra-button="Ignore this version" \ - # --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ - # --title "RetroDECK Update Available" \ - # --text="There is a new version of RetroDECK on the stable release channel $online_version. Would you like to update to it?\n\n(depending on your internet speed this could takes several minutes).") - # 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 == "Ignore this version" ]]; then - # set_setting_value $rd_conf "update_ignore" "$online_version" retrodeck "options" # Store version to ignore for future checks - # fi - # else # User clicked "Yes" - # 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." - # ( - # flatpak-spawn --host flatpak update --noninteractive -y net.retrodeck.retrodeck - # ) | - # rd_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 Updater" \ - # --text="Upgrade in process please wait (this could takes several minutes)." - # configurator_generic_dialog "RetroDECK Online Update" "The update process is now complete!\n\nPlease restart RetroDECK to keep the fun going." - # exit 1 - # fi - # TODO: add the logic to check and update the branch from the configuration file - log i "Showing new version found dialog" - choice=$(rd_zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="OK" --extra-button="Ignore this version" \ + choice=$(zenity --icon-name=net.retrodeck.retrodeck --info --no-wrap --ok-label="OK" --extra-button="Ignore this version" \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ --title "RetroDECK - New Update Available" \ --text="There is a new version of RetroDECK available: $online_version.\nYou can easily update from the app store you have installed, examples: KDE Discover or Gnome Software.\n\nIf you would like to ignore this notification, click the \"Ignore this version\" button.") @@ -96,57 +81,7 @@ check_for_version_update() { set_setting_value $rd_conf "update_ignore" "$online_version" retrodeck "options" # Store version to ignore for future checks. fi else # User clicked "Yes" - log i "Selected: \"Yes\"" - 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/RetroDECK/Cooker/releases/latest | grep '"browser_download_url":.*flatpak' | grep -v '\.sha' | sed -E 's/.*"([^"]+)".*/\1/') - local temp_folder="$rdhome/RetroDECK_Updates" - create_dir $temp_folder - log i "Downloading version \"$online_version\" in \"$temp_folder/RetroDECK-cooker.flatpak\" from url: \"$latest_cooker_download\"" - # Downloading the flatpak file - wget -P "$temp_folder" "$latest_cooker_download" - # And its sha - wget -P "$temp_folder" "$latest_cooker_download.sha" - - # Get the expected SHA checksum from the SHA file - local expected_sha=$(cat "$temp_folder/$(basename "$latest_cooker_download").sha" | awk '{print $1}') - - # Check if the file exists - if [ -f "$temp_folder/RetroDECK-cooker.flatpak" ]; then - # Calculate the actual SHA checksum of the file - actual_sha=$(sha256sum "$temp_folder/RetroDECK-cooker.flatpak" | awk '{print $1}') - - # Log the found and expected SHA checksums - log d "Found SHA: $actual_sha" - log d "Expected SHA: $expected_sha" - - # Check if the SHA checksum matches - if [ "$actual_sha" = "$expected_sha" ]; then - log d "Flatpak file \"$temp_folder/RetroDECK-cooker.flatpak\" found and SHA checksum matches, proceeding." - log d "Uninstalling old RetroDECK flatpak" - # Remove current version before installing new one, to avoid duplicates - flatpak-spawn --host flatpak remove --noninteractive -y net.retrodeck.retrodeck && log d "Uninstallation successful" - log d "Installing new flatpak file from: \"$temp_folder/RetroDECK-cooker.flatpak\"" - flatpak-spawn --host flatpak install --user --bundle --noninteractive -y "$temp_folder/RetroDECK-cooker.flatpak" && log d "Installation successful" - else - log e "Flatpak file \"$temp_folder/RetroDECK-cooker.flatpak\" found but SHA checksum does not match. Quitting." - configurator_generic_dialog "RetroDECK Online Update" "There was an error during the update: flatpak file found but SHA checksum does not match. Please check the log file." - exit 1 - fi - else - log e "Flatpak file \"$temp_folder/RetroDECK-cooker.flatpak\" NOT FOUND. Quitting." - configurator_generic_dialog "RetroDECK Online Update" "There was an error during the update: flatpak file not found. Please check the log file." - exit 1 - fi - - rm -rf "$temp_folder" # Cleanup old bundles to save space - ) | - rd_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 Updater" \ - --text="RetroDECK is updating to the latest version, please wait." - configurator_generic_dialog "RetroDECK Online Update" "The update process is now complete!\n\nPlease restart RetroDECK to keep the fun going." - exit 1 + install_release $online_version fi fi fi diff --git a/functions/global.sh b/functions/global.sh index 1eb39f12..eaa9b9bf 100644 --- a/functions/global.sh +++ b/functions/global.sh @@ -55,6 +55,7 @@ incompatible_presets_reference_list="$config/retrodeck/reference_lists/incompati pretty_system_names_reference_list="$config/retrodeck/reference_lists/pretty_system_names.cfg" # An internal translation list for turning internal names (eg. gbc) to "pretty" names (Nintendo GameBoy Color) 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 diff --git a/functions/other_functions.sh b/functions/other_functions.sh index 4676c174..72e26845 100644 --- a/functions/other_functions.sh +++ b/functions/other_functions.sh @@ -599,6 +599,62 @@ easter_eggs() { cp -f "$new_splash_file" "$current_splash_file" # Deploy assigned splash screen } +install_release() { + # Logging the release tag and URL + log d "Attempting to install release: $1 from repo $update_repo" + + # Construct the URL for the flatpak file + + if [ "$(get_setting_value "$rd_conf" "update_repo" "retrodeck" "options")" == "RetroDECK" ]; then + iscooker="" + else + iscooker="-cooker" + fi + + local flatpak_url="https://github.com/$git_organization_name/$update_repo/releases/download/$1/RetroDECK$iscooker.flatpak" + log d "Constructed flatpak URL: $flatpak_url" + + # Confirm installation with the user + zenity --question --icon-name=net.retrodeck.retrodeck --no-wrap \ + --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ + --title "RetroDECK Updater" \ + --text="$1 will be now installed.\nThe 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.\n\nDo you want to continue?" + + rc=$? # Capture return code + if [[ $rc == "1" ]]; then # If the user clicks "Cancel" + return 0 + fi + + ( + mkdir -p "$rdhome/RetroDECK_Updates" + + # Download the flatpak file + wget -P "$rdhome/RetroDECK_Updates" $flatpak_url -O "$rdhome/RetroDECK_Updates/RetroDECK$iscooker.flatpak" + + # Check if the download was successful + if [[ $? -ne 0 ]]; then + configurator_generic_dialog "Error" "Failed to download the flatpak file. Please check the release tag and try again." + return 1 + fi + + # Remove the current version before installing the new one to avoid duplicates + flatpak-spawn --host flatpak remove --noninteractive -y net.retrodeck.retrodeck + + # Install the new version + flatpak-spawn --host flatpak install --user --bundle --noninteractive -y "$rdhome/RetroDECK_Updates/RetroDECK$iscooker.flatpak" + + # Cleanup old bundles to save space + rm -rf "$rdhome/RetroDECK_Updates" + ) | + 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 Updater" \ + --text="RetroDECK is updating to the selected version, please wait." + + configurator_generic_dialog "RetroDECK Online Update" "The update process is now complete!\n\nRetroDECK will now quit." + quit_retrodeck +} + ponzu() { # This function is used to extract some specific appimages # Check if any of the specified files exist @@ -702,62 +758,106 @@ ponzu_remove() { configurator_retrodeck_tools_dialog } -# TODO: this function is not yet used -branch_selector() { - log d "Fetch branches from GitHub API excluding \"main\"" - branches=$(curl -s https://api.github.com/repos/RetroDECK/RetroDECK/branches | grep '"name":' | awk -F '"' '$4 != "main" {print $4}') +release_selector() { + log d "Fetching releases from GitHub API for repository $cooker_repository_name" + + # Fetch the main release from the RetroDECK repository + log d "Fetching latest main release from GitHub API for repository RetroDECK" + local main_release=$(curl -s https://api.github.com/repos/$git_organization_name/RetroDECK/releases/latest) - # Create an array to store branch names - branch_array=() + if [[ -z "$main_release" ]]; then + log e "Failed to fetch the main release" + configurator_generic_dialog "Error" "Unable to fetch the main release. Please check your network connection or try again later." + return 1 + fi - # Loop through each branch and add it to the array - while IFS= read -r branch; do - branch_array+=("$branch") - done <<< "$branches" - # TODO: logging - Creating array of branch names + main_tag_name=$(echo "$main_release" | jq -r '.tag_name') + main_published_at=$(echo "$main_release" | jq -r '.published_at') - # Display branches in a Zenity list dialog - selected_branch=$( + # Convert published_at to human-readable format for the main release + main_human_readable_date=$(date -d "$main_published_at" +"%d %B %Y %H:%M") + + # Add the main release as the first entry in the release array + local release_array=("Main Release" "$main_tag_name" "$main_human_readable_date") + + # Fetch all releases from the Cooker repository + local releases=$(curl -s https://api.github.com/repos/$git_organization_name/$cooker_repository_name/releases) + + if [[ -z "$releases" ]]; then + log e "Failed to fetch releases or no releases available" + configurator_generic_dialog "Error" "Unable to fetch releases. Please check your network connection or try again later." + return 1 + fi + + # Loop through each release and add to the release array + while IFS= read -r release; do + tag_name=$(echo "$release" | jq -r '.tag_name') + published_at=$(echo "$release" | jq -r '.published_at') + + # Convert published_at to human-readable format + human_readable_date=$(date -d "$published_at" +"%d %B %Y %H:%M") + + # Ensure fields are properly aligned for Zenity + release_array+=("Cooker Channel" "$tag_name" "$human_readable_date") + + done < <(echo "$releases" | jq -c '.[]' | sort -t: -k3,3r) + + if [[ ${#release_array[@]} -eq 0 ]]; then + configurator_generic_dialog "RetroDECK Updater" "No available releases found, exiting." + log d "No available releases found" + return 1 + fi + + log d "Showing available releases" + + # Display releases in a Zenity list dialog with three columns + selected_release=$( rd_zenity --list \ --icon-name=net.retrodeck.retrodeck \ --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ - --title "RetroDECK Configurator Cooker Branch - Select Branch" \ - --column="Branch" --width=1280 --height=800 "${branch_array[@]}" + --title "RetroDECK Configurator Cooker Releases - Select Release" \ + --column="Branch" --column="Release Tag" --column="Published Date" --width=1280 --height=800 \ + --separator="|" --print-column='ALL' "${release_array[@]}" ) - # TODO: logging - Displaying branches in Zenity list dialog - # Display warning message - if [ $selected_branch ]; then - rd_zenity --question --icon-name=net.retrodeck.retrodeck --no-wrap \ - --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ - --title "RetroDECK Configurator Cooker Branch - Switch Branch" \ - --text="Are you sure you want to move to \"$selected_branch\" branch?" - # Output selected branch - echo "Selected branch: $selected_branch" # TODO: logging - Outputting selected branch + log i "Selected release: $selected_release" + + if [[ -z "$selected_release" ]]; then + log d "No release selected, user exited." + return 1 + fi + + # Parse the selected release using the pipe separator + IFS='|' read -r selected_branch selected_tag selected_date <<< "$selected_release" + selected_branch=$(echo "$selected_branch" | xargs) # Trim any extra spaces + selected_tag=$(echo "$selected_tag" | xargs) + selected_date=$(echo "$selected_date" | xargs) + + log d "Selected branch: $selected_branch, release: $selected_tag, date: $selected_date" + + rd_zenity --question --icon-name=net.retrodeck.retrodeck --no-wrap \ + --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ + --title "RetroDECK Configurator Cooker Release - Confirm Selection" \ + --text="Are you sure you want to install the following release?\n\n$selected_branch: \"$selected_tag\"\nPublished on $selected_date?" + + if [[ $? -eq 0 ]]; then + log d "User confirmed installation of release $selected_tag" + + if echo "$selected_release" | grep -q "Main Release"; then + set_setting_value $rd_conf "update_repo" "$main_repository_name" retrodeck "options" + log i "Switching to main channel" + else + set_setting_value $rd_conf "update_repo" "$cooker_repository_name" retrodeck "options" + log i "Switching to cooker channel" + fi + set_setting_value "$rd_conf" "branch" "$selected_branch" "retrodeck" "options" - branch="feat/sftp" - # Get the latest release for the specified branch - latest_release=$(curl -s "https://api.github.com/repos/RetroDECK/Cooker/releases" | jq ".[] | select(.target_commitish == \"$branch_name\") | .tag_name" | head -n 1) - # TODO: this will fail because the builds coming from the PRs are not published yet, we should fix them - # TODO: form a proper url: $flatpak_file_url - 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/') - 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" - rm -rf "$rdhome/RetroDECK_Updates" # Cleanup old bundles to save space - ) | - rd_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 Updater" \ - --text="RetroDECK is updating to the latest \"$selected_branch\" version, please wait." - configurator_generic_dialog "RetroDECK Online Update" "The update process is now complete!\n\nPlease restart RetroDECK to keep the fun going." - exit 1 + log d "Set branch to $selected_branch in configuration" + install_release $selected_tag + else - configurator_generic_dialog "No branch selected, exiting." - # TODO: logging + log d "User canceled installation" + return 0 fi } diff --git a/tools/configurator.sh b/tools/configurator.sh index 466f8a55..e77b6f35 100644 --- a/tools/configurator.sh +++ b/tools/configurator.sh @@ -99,7 +99,7 @@ source /app/libexec/global.sh # - Add to Steam # - Developer Options (Hidden) # - Change Multi-user mode -# - Change Update channel +# - Install Specific Release # - Browse the wiki # - Install: RetroDECK Starter Pack # - Tool: USB Import @@ -1287,7 +1287,7 @@ configurator_developer_dialog() { --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" --width=1200 --height=720 \ --column="Choice" --column="Description" \ "Change Multi-user mode" "Enable or disable multi-user support" \ - "Change Update Channel" "Change between normal and cooker builds" \ + "Install Specific Release" "Install any cooker release or the latest main available" \ "Browse the Wiki" "Browse the RetroDECK wiki online" \ "Install RetroDECK Starter Pack" "Install the optional RetroDECK starter pack" \ "Tool: USB Import" "Prepare a USB device for ROMs or import an existing collection" \ @@ -1300,7 +1300,7 @@ configurator_developer_dialog() { configurator_retrodeck_multiuser_dialog ;; - "Change Update Channel" ) + "Install Specific Release" ) log i "Configurator: opening \"$choice\" menu" configurator_online_update_channel_dialog ;; @@ -1378,17 +1378,8 @@ configurator_online_update_channel_dialog() { configurator_developer_dialog fi else - rd_zenity --question \ - --no-wrap --window-icon="/app/share/icons/hicolor/scalable/apps/net.retrodeck.retrodeck.svg" \ - --title "RetroDECK Configurator - RetroDECK Change Update Branch" \ - --text="You are currently on the cooker branch of RetroDECK updates. Would you like to switch to the production branch?\n\nAfter installing a production build, you may need to remove the \"cooker\" branch install of RetroDECK to avoid overlap." - - if [ $? == 0 ] # User clicked "Yes" - then - set_setting_value $rd_conf "update_repo" "RetroDECK" retrodeck "options" - else # User clicked "Cancel" - configurator_developer_dialog - fi + set_setting_value $rd_conf "update_repo" "RetroDECK" retrodeck "options" + release_selector fi }