From 643bb1b0f2f3c4fc37d7e000a4643e4797a4e981 Mon Sep 17 00:00:00 2001 From: LukeZGD <26163116+LukeZGD@users.noreply.github.com> Date: Wed, 5 Apr 2023 12:03:16 +0800 Subject: [PATCH] Fix update check --- .github/workflows/build.yml | 6 +++--- restore.sh | 16 ++++++++++------ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1c33ecb..aa75527 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -84,10 +84,10 @@ jobs: - name: Zip complete files run: zip -r ${{ github.event.repository.name }}_complete_v${{ env.DATE }}.${{ env.COUNT }}.zip bin/ LICENSE resources/ restore.cmd restore.sh README.md - - name: Create this file to make upgrading backward-compatible + - name: Create this file to get latest git hash run: | echo "This file is for compatibility purposes only. Get Legacy-iOS-Kit_complete instead." > README.txt - zip -r iOS-OTA-Downgrader_complete_${{ env.DATE_OLD }}-${{ env.SHA_SHORT }}.zip README.txt + zip -r git-hash_${{ env.DATE_OLD }}-${{ env.SHA_SHORT }}.zip README.txt - name: Update latest release uses: pyTooling/Actions/releaser@main @@ -96,7 +96,7 @@ jobs: rm: true token: ${{ secrets.GITHUB_TOKEN }} files: | - iOS-OTA-Downgrader_complete_${{ env.DATE_OLD }}-${{ env.SHA_SHORT }}.zip + git-hash_${{ env.DATE_OLD }}-${{ env.SHA_SHORT }}.zip ${{ github.event.repository.name }}_complete_v${{ env.DATE }}.${{ env.COUNT }}.zip ${{ github.event.repository.name }}_macos_v${{ env.DATE }}.${{ env.COUNT }}.zip ${{ github.event.repository.name }}_linux_armhf_v${{ env.DATE }}.${{ env.COUNT }}.zip diff --git a/restore.sh b/restore.sh index 48a54ca..e87e3bb 100755 --- a/restore.sh +++ b/restore.sh @@ -356,7 +356,9 @@ install_depends() { } version_check() { + local github_api local version_latest + local git_hash_latest pushd .. >/dev/null if [[ -d .git ]]; then @@ -367,7 +369,7 @@ version_check() { version_current=v$(date +%y.%m).$(git rev-list --count HEAD --since=$(date --date="$(date +%Y-%m-01) - 1 second" +%s) | xargs printf "%02d") fi elif [[ -e ./resources/git_hash ]]; then - version="$(cat ./resources/version)" + version_current="$(cat ./resources/version)" git_hash="$(cat ./resources/git_hash)" else log ".git directory and git_hash file not found, cannot determine version." @@ -385,16 +387,18 @@ version_check() { warn "No version check flag detected, update check will be disabled and no support may be provided." else log "Checking for updates..." - version_latest=$(curl https://api.github.com/repos/LukeZGD/Legacy-iOS-Kit/releases/latest 2>/dev/null | grep "latest/Legacy-iOS-Kit_complete" | cut -c 123- | cut -c -9 | sed -r 's/\.$//') + github_api=$(curl https://api.github.com/repos/LukeZGD/Legacy-iOS-Kit/releases/latest 2>/dev/null) + version_latest=$(echo "$github_api" | grep "latest/Legacy-iOS-Kit_complete" | cut -c 123- | cut -c -9 | sed -r 's/\.$//') + git_hash_latest=$(echo "$github_api" | grep "latest/git-hash" | cut -c 119- | cut -c -7) if [[ -z $version_latest ]]; then : warn "Failed to check for updates. GitHub may be down or blocked by your network." elif [[ $version_latest != "$version_current" ]]; then if (( $(echo $version_current | cut -c 2- | sed -e 's/\.//g') >= $(echo $version_latest | cut -c 2- | sed -e 's/\.//g') )); then - warn "Current version is newer/different than remote: $version_latest ($(curl https://api.github.com/repos/LukeZGD/Legacy-iOS-Kit/releases/latest 2>/dev/null | grep "latest/iOS-OTA-Downgrader_complete" | cut -c 138- | cut -c -7))" - elif [[ $(echo $version_current | cut -c 12-) != $(echo $version_latest | cut -c 12-) ]]; then + warn "Current version is newer/different than remote: $version_latest ($git_hash_latest)" + else print "* A newer version of Legacy iOS Kit is available." - print "* Current version: $version_current" - print "* Latest version: $version_latest" + print "* Current version: $version_current ($git_hash)" + print "* Latest version: $version_latest ($git_hash_latest)" print "* Please download/pull the latest version before proceeding." exit fi