diff --git a/restore.sh b/restore.sh index 087f962..4a37ec3 100755 --- a/restore.sh +++ b/restore.sh @@ -104,14 +104,15 @@ set_tool_paths() { # architecture check if [[ $(uname -m) == "a"* && $(getconf LONG_BIT) == 64 ]]; then - dir+="arm64" + platform_arch="arm64" elif [[ $(uname -m) == "a"* ]]; then - dir+="armhf" + platform_arch="armhf" elif [[ $(uname -m) == "x86_64" ]]; then - dir+="x86_64" + platform_arch="x86_64" else error "Your architecture ($(uname -m)) is not supported." fi + dir+="$platform_arch" # version check if [[ -n $UBUNTU_CODENAME ]]; then @@ -376,8 +377,48 @@ install_depends() { exit } +version_get() { + log "Checking for updates..." + github_api=$(curl https://api.github.com/repos/LukeZGD/Legacy-iOS-Kit/releases/latest 2>/dev/null) + version_latest=$(echo "$github_api" | $jq -r '.assets[] | select(.name|test("complete")) | .name' | cut -c 25- | cut -c -9) + git_hash_latest=$(echo "$github_api" | $jq -r '.assets[] | select(.name|test("git-hash")) | .name' | cut -c 21- | cut -c -7) +} + +version_update() { + local url + local req + read -p "$(input 'Do you want to update now? (Y/n): ')" opt + if [[ $opt == 'n' || $opt == 'N' ]]; then + exit + fi + if [[ -d .git ]]; then + log "Running git pull..." + git pull + log "Done! Please run the script again" + exit + elif (( $(ls bin | wc -l) > 1 )); then + req=".assets[] | select (.name|test(\"complete\")) | .browser_download_url" + elif [[ $platform == "linux" ]]; then + req=".assets[] | select (.name|test(\"${platform}_$platform_arch\")) | .browser_download_url" + else + req=".assets[] | select (.name|test(\"${platform}\")) | .browser_download_url" + fi + url="$(echo "$github_api" | $jq -r "$req")" + log "Downloading: $url" + curl -L $url -o tmp/latest.zip + if [[ ! -s tmp/latest.zip ]]; then + error "Download failed. Please run the script again" + fi + log "Updating..." + cp resources/firstrun tmp 2>/dev/null + rm -r bin/ resources/ LICENSE README.md restore* + unzip -q tmp/latest.zip -d . + cp tmp/firstrun resources 2>/dev/null + log "Done! Please run the script again" + exit +} + version_check() { - local github_api pushd .. >/dev/null if [[ -d .git ]]; then git_hash=$(git rev-parse HEAD | cut -c -7) @@ -392,8 +433,10 @@ version_check() { else log ".git directory and git_hash file not found, cannot determine version." if [[ $no_version_check != 1 ]]; then - error "Your copy of Legacy iOS Kit is downloaded incorrectly. Do not use the \"Code\" button in GitHub." \ - "* Please download Legacy iOS Kit using git clone or from GitHub releases: https://github.com/LukeZGD/Legacy-iOS-Kit/releases" + warn "Your copy of Legacy iOS Kit is downloaded incorrectly. Do not use the \"Code\" button in GitHub." + print "Please download Legacy iOS Kit using git clone or from GitHub releases: https://github.com/LukeZGD/Legacy-iOS-Kit/releases" + version_check + version_update fi fi @@ -402,10 +445,7 @@ version_check() { fi if [[ $no_version_check != 1 ]]; then - log "Checking for updates..." - 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 -e 's/\.$//') - git_hash_latest=$(echo "$github_api" | grep "latest/git-hash" | cut -c 119- | cut -c -7) + version_get 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 @@ -416,7 +456,7 @@ version_check() { 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 + version_update fi fi fi @@ -2771,7 +2811,7 @@ menu_print_info() { if [[ $no_version_check == 1 ]]; then warn "No version check flag detected, update check is disabled and no support will be provided." fi - if [[ $version_latest != "$version_current" ]]; then + if [[ $git_hash_latest != "$git_hash" ]]; then warn "Current version is newer/different than remote: $version_latest ($git_hash_latest)" fi print "* Platform: $platform ($platform_ver) $live_cdusb_r"