diff --git a/Dockerfile b/Dockerfile index cc1a3d6..70e2df8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,14 @@ -FROM python:3.9.15-buster +FROM python:3.9.15-slim-buster RUN apt-get update RUN apt-get install -y \ - android-tools-adb \ - android-tools-fastboot -RUN pip3 install protobuf + android-tools-adb \ + android-tools-fastboot \ + unzip \ + curl \ + git +RUN pip3 install protobuf \ + six COPY . /magisk WORKDIR /magisk CMD bash reinstall-magisk-on-lineageos diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index 085fc40..ee3104a 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -2,15 +2,19 @@ set -e +print_message() { + printf "$1\n" +} + PHONE_ADB_SERIAL_NUMBER=${ADB_DEVICE} # The adb serial number can be found by running `adb devices`. if [$PHONE_ADB_SERIAL_NUMBER = '']; then PHONE_ADB_SERIAL_NUMBER=$(echo $(adb devices) | sed -rn 's/(^|(.* ))([^ ]*) device(( .*)|$)/\3/; T; p; q') + if [[ -z $PHONE_ADB_SERIAL_NUMBER ]]; then + print_message "ERROR: no phone connected or connection unauthorized" + exit 1 + fi fi -print_message() { - printf "$1\n" -} - check_phone_is_connected() { if ! adb devices | grep --silent "$PHONE_ADB_SERIAL_NUMBER"; then print_message "ERROR: phone '$PHONE_ADB_SERIAL_NUMBER' is not connected" @@ -38,7 +42,7 @@ get_device_downloads_page() { } get_build_url() { - curl --no-progress-meter "$(get_device_downloads_page)" | + curl --silent "$(get_device_downloads_page)" | grep --only-matching --ignore-case \ "https://mirrorbits.lineageos.org/[^\"]*"$( )"$(get_lineage_version)-signed.zip" | @@ -46,12 +50,15 @@ 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" ]] - return + if [[ -f "/tmp/lineageos.zip" ]]; then + # The --location lets curl follow the redirection. + curl --silent --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 ]] + return + fi + false } download_latest_lineageos_build() { @@ -151,15 +158,14 @@ check_magisk_app() { magisk_package_name_count=$(adb -s "$PHONE_ADB_SERIAL_NUMBER" shell pm list packages "$magisk_package_name" | wc -l) if [ "${magisk_package_name_count}" -eq 1 ] then - print_message " [OK] Magisk app seems to be installed on selected phone" + print_message "Magisk app seems to be installed on selected phone" elif [ "${magisk_package_name_count}" -eq 0 ] then - print_message " [ERROR] Magisk app seems not installed on selected phone. Exiting." + print_message "ERROR: Magisk app seems not installed on selected phone." exit -1 else - print_message " [ERROR] More than one Magisk app entry is present:" + print_message "ERROR: More than one Magisk app entry is present:" adb -s "$PHONE_ADB_SERIAL_NUMBER" shell pm list packages "$magisk_package_name" - print_message "Exiting." exit -1 fi } @@ -175,10 +181,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"