From 1235c292330b65b7ecbe4dcc889ba6d4b0b3d9c1 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 00:44:44 -0300 Subject: [PATCH 1/7] added check magisk app instead of folder --- reinstall-magisk-on-lineageos | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index 863a052..3e56a72 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -139,8 +139,22 @@ reboot_phone() { fastboot -s "$PHONE_ADB_SERIAL_NUMBER" reboot } -check_magisk_folder() { - adb -s "$PHONE_ADB_SERIAL_NUMBER" shell ls /data/adb/magisk/ +check_magisk_app() { + magisk_package_name="com.topjohnwu.magisk" + 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" + elif [ "${magisk_package_name_count}" -eq 0 ] + then + print_message " [ERROR] Magisk app seems not installed on selected phone. Exiting." + exit -1 + else + 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 } is_rooted_debugging_enabled() { @@ -152,8 +166,8 @@ main() { check_phone_is_connected print_message "Checking on phone if rooted debugging is enabled" is_rooted_debugging_enabled - print_message "Checking on phone if Magisk folder is present listing /data/adb/magisk/" - check_magisk_folder + print_message "Checking on phone if Magisk is installed" + check_magisk_app print_message "Downloading build archive from $(get_build_url)" download_latest_lineageos_build print_message "Extracting 'boot.img' from build archive in /tmp/boot.img" From e7d977143f51cf6f92258aa0b135e6c2991e5785 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 00:46:09 -0300 Subject: [PATCH 2/7] dockerfile: install python3, python3-pip and protobuf module --- Dockerfile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8b84a7b..b1d75d8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,10 @@ FROM debian:stable-slim RUN apt-get update RUN apt-get install -y \ android-tools-adb \ - android-tools-fastboot + android-tools-fastboot \ + python3 \ + python3-pip +RUN pip3 install protobuf COPY . /magisk WORKDIR /magisk CMD bash reinstall-magisk-on-lineageos From b3592929d24072f19df45687e69edce18f2c59b3 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 00:47:06 -0300 Subject: [PATCH 3/7] removed protobuf module install (already in dockerfile) --- reinstall-magisk-on-lineageos | 5 ----- 1 file changed, 5 deletions(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index 3e56a72..58dd225 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -63,10 +63,6 @@ extract_boot_image_from_file_based_ota() { exit 1 } -install_python_protobuf() { - sudo python3 -m pip install protobuf -} - extract_payload_from_payload_based_ota() { unzip -od /tmp /tmp/lineageos.zip payload.bin } @@ -76,7 +72,6 @@ generate_random_alnum_string_of_length_6() { } extract_boot_image_from_payload_file() { - install_python_protobuf # For cases in which the repo has already been cloned, I prefer to create a random directory name to clone into, instead of deleting any file or directory on the user's machine. scripts_directory_name="scripts_$(generate_random_alnum_string_of_length_6)" git clone https://github.com/LineageOS/scripts /tmp/$scripts_directory_name From 49f51d60691073a163693d1e07190d35331518fa Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 00:47:27 -0300 Subject: [PATCH 4/7] changed python to python3 --- reinstall-magisk-on-lineageos | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index 58dd225..086f9d4 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -75,7 +75,7 @@ extract_boot_image_from_payload_file() { # For cases in which the repo has already been cloned, I prefer to create a random directory name to clone into, instead of deleting any file or directory on the user's machine. scripts_directory_name="scripts_$(generate_random_alnum_string_of_length_6)" git clone https://github.com/LineageOS/scripts /tmp/$scripts_directory_name - python /tmp/$scripts_directory_name/update-payload-extractor/extract.py --partitions boot --output_dir /tmp/ /tmp/payload.bin + python3 /tmp/$scripts_directory_name/update-payload-extractor/extract.py --partitions boot --output_dir /tmp/ /tmp/payload.bin } extract_boot_image_from_payload_based_ota() { From 3d156e316138c051b2acdd03f741029237a7ee4e Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 00:52:03 -0300 Subject: [PATCH 5/7] added build archive exists check --- reinstall-magisk-on-lineageos | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index 086f9d4..6fc9576 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -42,6 +42,15 @@ get_build_url() { head -1 } +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 +} + download_latest_lineageos_build() { # The --location lets curl follow the redirection. curl --location "$(get_build_url)" --output /tmp/lineageos.zip @@ -163,8 +172,12 @@ main() { is_rooted_debugging_enabled print_message "Checking on phone if Magisk is installed" check_magisk_app - print_message "Downloading build archive from $(get_build_url)" - download_latest_lineageos_build + if check_exists_latest_lineageos_build; then + print_message "Build archive already exists, skipping download" + else + print_message "Downloading build archive from $(get_build_url)" + download_latest_lineageos_build + fi print_message "Extracting 'boot.img' from build archive in /tmp/boot.img" extract_boot_image print_message "Copying from PC to phone the boot image in /sdcard/Download/boot.img" From 01b95af7f303b0dc6796ce9063206076788fe09e Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 00:59:07 -0300 Subject: [PATCH 6/7] dockerfile: remove python3 install because base img already contains --- Dockerfile | 2 -- 1 file changed, 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02d6231..512ff37 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,8 +4,6 @@ RUN apt-get update RUN apt-get install -y \ android-tools-adb \ android-tools-fastboot \ - python3 \ - python3-pip RUN pip3 install protobuf COPY . /magisk WORKDIR /magisk From efc80d0bde1ed90e06fc198d0c46ff1bad2e9a59 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 01:04:41 -0300 Subject: [PATCH 7/7] fix dockerfile syntax --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 512ff37..cc1a3d6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ FROM python:3.9.15-buster RUN apt-get update RUN apt-get install -y \ android-tools-adb \ - android-tools-fastboot \ + android-tools-fastboot RUN pip3 install protobuf COPY . /magisk WORKDIR /magisk