From d43498db87c2d0a62da850e27f28dd103d03effb Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 19:58:27 -0300 Subject: [PATCH] improved build archive existance verification --- reinstall-magisk-on-lineageos | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index 085fc40..d26d02a 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -46,11 +46,14 @@ get_build_url() { } check_exists_latest_lineageos_build() { - # The --location lets curl follow the redirection. - curl --location "$(get_build_url)?sha256" --output /tmp/lineageos.sha256 - hash1=$( awk '{print $1}' lineageos.sha256 ) - hash2=$( sha256sum lineageos.zip | awk '{print $1}' ) - [[ "$hash1" =~ "$hash2" ]] + if [[ -f /tmp/lineageos.zip ]]; then + # The --location lets curl follow the redirection. + print_message "$(get_build_url)?sha256" + curl --location "$(get_build_url)?sha256" --output /tmp/lineageos.sha256 + hash1=$( awk '{print $1}' /tmp/lineageos.sha256 ) + hash2=$( sha256sum /tmp/lineageos.zip | awk '{print $1}' ) + [[ -n $hash1 && -n $hash2 && $hash1 == $hash2 ]] + fi return } @@ -175,10 +178,11 @@ main() { is_rooted_debugging_enabled print_message "Checking on phone if Magisk is installed" check_magisk_app + print_message "Checking if build archive already exists" if check_exists_latest_lineageos_build; then - print_message "Build archive already exists, skipping download" + print_message "Build archive found, skipping download" else - print_message "Downloading build archive from $(get_build_url)" + print_message "Build archive not found or hash mismatch, downloading from $(get_build_url)" download_latest_lineageos_build fi print_message "Extracting 'boot.img' from build archive in /tmp/boot.img"