diff --git a/automation_tools/pre_build_automation.sh b/automation_tools/pre_build_automation.sh index bcca05c4..895f2074 100755 --- a/automation_tools/pre_build_automation.sh +++ b/automation_tools/pre_build_automation.sh @@ -8,11 +8,21 @@ # Needs the URL of the file, in this line format: hash^PLACEHOLDERTEXT^url # latestcommit: Finds the most recent commit of a git repo and updated the placeholder in the manifest. # Needs the URL of the repo and the branch to find the latest commit from, in this line format: latestcommit^PLACEHOLDERTEXT^url^branch -# latestappimage: Finds the download URL and SHA256 hash of the latest AppImage release from a git repo. -# Needs the API URL of the repo, in this line format: latestappimage^PLACEHOLDERTEXT^https://api.github.com/repos///releases/latest +# latestghrelease: Finds the download URL and SHA256 hash of the latest release from a git repo. +# Needs the API URL of the repo, in this line format: latestappimage^PLACEHOLDERTEXT^https://api.github.com/repos///releases/latest^ # As this command updates two different placeholders (one for the URL, one for the file hash) in the manifest, # the URL that would be used in the above example is "PLACEHOLDERTEXT" and the hash placeholder text would be "HASHPLACEHOLDERTEXT" # The "HASH" prefix of the placeholder text is hardcoded in the script +# The will be the file extension or other identifying suffix at the end of the file name that can be used to select from multiple releases. +# Example: If there are these file options for a given release: +# yuzu-mainline-20240205-149629642.AppImage +# yuzu-linux-20240205-149629642-source.tar.xz +# yuzu-linux-20240205-149629642-debug.tar.xz +# Entering "AppImage" (without quotes) for the will identify yuzu-mainline-20240205-149629642.AppImage +# Entering "source-.tar.xz" (without quotes) for the will identify yuzu-linux-20240205-149629642-source.tar.xz +# Entering "debug-tar.xz" (without quotes) for the will identify yuzu-linux-20240205-149629642-debug.tar.xz +# As a file extension like ".tar.zx" can apply to multiple file options, the entire part that is appended to each release name should be included. +# The will also only consider entries where the given suffix is at the end of the file name. So "AppImage" will identify "file.AppImage" but not "file.AppImage.zsync" # outside_file: Prints the contents of a file from the build environment (such as the buildid file) and replaces the placeholder text with those contents. # outside_env_var: Gets the value of an environmental variable from the build environment (the output of "echo $var" from the terminal) and replaces the placeholder text with that value. # custom_command: Runs a single command explicitly as written in the $URL field of the task list, including variable and command expansion. This should work the same as if you were runnig the command directly from the terminal. @@ -72,17 +82,17 @@ do /bin/sed -i 's^'"$placeholder"'^'"$commit"'^' $rd_manifest ;; - "latestappimage" ) + "latestghrelease" ) echo echo "Placeholder text: $placeholder" echo "Repo to look for AppImage releases: $url" echo - appimageurl=$(curl -s "$url" | grep browser_download_url | grep "\.AppImage\"" | cut -d : -f 2,3 | tr -d \" | sed -n 1p | tr -d ' ') - echo "AppImage URL found: $appimageurl" - /bin/sed -i 's^'"$placeholder"'^'"$appimageurl"'^' $rd_manifest - appimagehash=$(curl -sL "$appimageurl" | sha256sum | cut -d ' ' -f1) - echo "AppImage hash found: $appimagehash" - /bin/sed -i 's^'"HASHFOR$placeholder"'^'"$appimagehash"'^' $rd_manifest + ghreleaseurl=$(curl -s "$url" | grep browser_download_url | grep "$branch\""$ | cut -d : -f 2,3 | tr -d \" | sed -n 1p | tr -d ' ') + echo "GitHub release URL found: $ghreleaseurl" + /bin/sed -i 's^'"$placeholder"'^'"$ghreleaseurl"'^' $rd_manifest + ghreleasehash=$(curl -sL "$ghreleaseurl" | sha256sum | cut -d ' ' -f1) + echo "GitHub release hash found: $ghreleasehash" + /bin/sed -i 's^'"HASHFOR$placeholder"'^'"$ghreleasehash"'^' $rd_manifest ;; "outside_file" ) diff --git a/functions/functions.sh b/functions/functions.sh index e3456793..8178fad0 100644 --- a/functions/functions.sh +++ b/functions/functions.sh @@ -100,6 +100,43 @@ move() { fi } +download_file() { + # Function to download file from the Internet, with Zenity progress bar + # USAGE: download_file $source_url $file_dest $file_name + # source_url is the location the file is downloaded from + # file_dest is the destination the file should be in the filesystem, needs filename included! + # file_name is a user-readable file name or description to be put in the Zenity dialog + + # Run wget in the background and redirect the progress to a temporary file + ( + wget "$1" -O "$2" -q --show-progress --progress=dot 2>&1 | sed -n -e 's/^.* \([0-9]*\)%.*$/\1/p' > "/var/cache/tmp/download_progress" & + wget_pid=$! + + progress="0" + echo "$progress" # Initial progress value. sent to Zenity + while true; do + progress=$(tail -n 2 "/var/cache/tmp/download_progress" | head -1) # Read the second-to-last value written to the pipe, to avoid reading data that is half written + echo "$progress" # Send value to Zenity + if [[ "$(tail -n 1 "/var/cache/tmp/download_progress")" == "100" ]]; then # Read last line every time to check for download completion + echo "100" + break + fi + sleep 0.5 + done + + # Wait for wget process to finish + wait "$wget_pid" + ) | + zenity --progress \ + --title="Downloading File" \ + --text="Downloading $3..." \ + --percentage=0 \ + --auto-close + + # Cleanup temp file + rm -f "/var/cache/tmp/download_progress" +} + 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 @@ -247,15 +284,9 @@ dir_prep() { } update_rpcs3_firmware() { - ( mkdir -p "$roms_folder/ps3/tmp" chmod 777 "$roms_folder/ps3/tmp" - wget "$rpcs3_firmware" -P "$roms_folder/ps3/tmp/" - ) | - 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 RPCS3 Firmware Download" \ - --text="RetroDECK downloading the RPCS3 firmware, please wait." + download_file "$rpcs3_firmware" "$roms_folder/ps3/tmp/PS3UPDAT.PUP" "RPCS3 Firmware" rpcs3 --installfw "$roms_folder/ps3/tmp/PS3UPDAT.PUP" rm -rf "$roms_folder/ps3/tmp" }