Add version check

This commit is contained in:
LukeZGD 2022-10-11 09:26:33 +08:00
parent 3adcd8bd2d
commit f8c2bfcf11

View File

@ -16,6 +16,8 @@ for i in "$@"; do
NoColor=1 NoColor=1
elif [[ $i == "NoDevice" ]]; then elif [[ $i == "NoDevice" ]]; then
NoDevice=1 NoDevice=1
elif [[ $i == "NoVersionCheck" ]]; then
NoVersionCheck=1
elif [[ $i == "PwnedDevice" ]]; then elif [[ $i == "PwnedDevice" ]]; then
PwnedDevice=1 PwnedDevice=1
fi fi
@ -82,16 +84,19 @@ Main() {
if [[ -d .git ]]; then if [[ -d .git ]]; then
if [[ $platform == "macos" ]]; then if [[ $platform == "macos" ]]; then
Echo "Version: $(date -r $(git log -1 --format="%at") +%Y-%m-%d)-$(git rev-parse HEAD | cut -c -7)" CurrentVersion="$(date -r $(git log -1 --format="%at") +%Y-%m-%d)-$(git rev-parse HEAD | cut -c -7)"
else else
Echo "Version: $(date -d @$(git log -1 --format="%at") --rfc-3339=date)-$(git rev-parse HEAD | cut -c -7)" CurrentVersion="$(date -d @$(git log -1 --format="%at") --rfc-3339=date)-$(git rev-parse HEAD | cut -c -7)"
fi fi
Echo "Version: $CurrentVersion"
elif [[ -e resources/git_hash ]]; then elif [[ -e resources/git_hash ]]; then
Echo "Version: $(cat resources/git_hash)" Echo "Version: $(cat resources/git_hash)"
else else
Echo "Version: Unknown" Echo "Version: Unknown"
Error "git_hash or .git not found. Your copy of iOS-OTA-Downgrader is downloaded incorrectly." \ if [[ $NoVersionCheck != 1 ]]; then
"Please download iOS-OTA-Downgrader from the GitHub releases page or using git clone." Error "git_hash or .git not found. Your copy of iOS-OTA-Downgrader is downloaded incorrectly." \
"Please download iOS-OTA-Downgrader from the GitHub releases page or using git clone."
fi
fi fi
SetToolPaths SetToolPaths
@ -113,6 +118,26 @@ Main() {
if [[ $? != 0 ]]; then if [[ $? != 0 ]]; then
Error "Please check your Internet connection before proceeding." Error "Please check your Internet connection before proceeding."
fi fi
if [[ $NoVersionCheck == 1 ]]; then
Log "WARNING - NoVersionCheck detected, update check will be disabled and no support may be provided."
else
Log "Checking for updates..."
LatestVersion=$(curl https://api.github.com/repos/LukeZGD/iOS-OTA-Downgrader/releases/latest 2>/dev/null | grep "latest/iOS-OTA-Downgrader_complete" | cut -c 131- | cut -c -18)
if [[ -z $LatestVersion ]]; then
Log "WARNING - Failed to check for updates. GitHub may be down or blocked by your network."
elif [[ $LatestVersion != $CurrentVersion ]]; then
if (( $(echo $CurrentVersion | cut -c -10 | sed -e 's/-//g') > $(echo $LatestVersion | cut -c -10 | sed -e 's/-//g') )); then
Log "WARNING - Current version is newer than remote ($LatestVersion)"
else
Echo "* A newer version of iOS-OTA-Downgrader is available."
Echo "* Current version: $CurrentVersion"
Echo "* Latest version: $LatestVersion"
Echo "* Please download the latest version before continuing."
ExitWin 0
fi
fi
fi
if [[ $platform == "macos" && $(uname -m) != "x86_64" ]]; then if [[ $platform == "macos" && $(uname -m) != "x86_64" ]]; then
Log "Apple Silicon Mac detected. Support may be limited, proceed at your own risk." Log "Apple Silicon Mac detected. Support may be limited, proceed at your own risk."
@ -135,7 +160,7 @@ Main() {
Clean Clean
mkdir tmp mkdir tmp
if [[ -n $1 && $1 != "NoColor" && $1 != *"Device" ]]; then if [[ -n $1 && $1 != "No"* && $1 != *"Device" ]]; then
Mode="$1" Mode="$1"
else else
[[ $NoDevice != 1 ]] && Selection+=("Downgrade Device") [[ $NoDevice != 1 ]] && Selection+=("Downgrade Device")