From 451684b8df6ee44019cd8e6c700b399fb4c82094 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 19:56:34 -0300 Subject: [PATCH 01/17] dockerfile: changed image to slim version; added suppress warnings on pip install --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index cc1a3d6..06e86ad 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ -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 +RUN pip3 install protobuf -q COPY . /magisk WORKDIR /magisk CMD bash reinstall-magisk-on-lineageos -- 2.36.1 From d43498db87c2d0a62da850e27f28dd103d03effb Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 19:58:27 -0300 Subject: [PATCH 02/17] 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" -- 2.36.1 From c9e2104e30d2535bdfed7b658e6f40b0a7e2ccd6 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 20:33:48 -0300 Subject: [PATCH 03/17] dockerfile: remove -q option --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 06e86ad..52d9471 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ RUN apt-get update RUN apt-get install -y \ android-tools-adb \ android-tools-fastboot -RUN pip3 install protobuf -q +RUN pip3 install protobuf COPY . /magisk WORKDIR /magisk CMD bash reinstall-magisk-on-lineageos -- 2.36.1 From f1f33ae197972ab15d676d51685a70c6e10686b8 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 20:35:20 -0300 Subject: [PATCH 04/17] added adb serial found check --- reinstall-magisk-on-lineageos | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index d26d02a..a75f703 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -5,6 +5,10 @@ set -e 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 [[ -n $PHONE_ADB_SERIAL_NUMBER ]] + print_message "ERROR: no suitable phone connected" + exit 1 + fi fi print_message() { -- 2.36.1 From b789b9aef8791e3046aa098fff753214d921bc56 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 20:36:00 -0300 Subject: [PATCH 05/17] standardized messages --- reinstall-magisk-on-lineageos | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index a75f703..dd184ac 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -158,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 } -- 2.36.1 From e179876da783aac908c6dd89b5b676f945917e1a Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 20:38:57 -0300 Subject: [PATCH 06/17] fix syntax error --- 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 dd184ac..d466280 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -5,7 +5,7 @@ set -e 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 [[ -n $PHONE_ADB_SERIAL_NUMBER ]] + if [[ -n $PHONE_ADB_SERIAL_NUMBER ]]; then print_message "ERROR: no suitable phone connected" exit 1 fi -- 2.36.1 From 7336ccb08a2915bef5eeb6959e83dc28b59738b5 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 20:41:43 -0300 Subject: [PATCH 07/17] fix wrong option on checking empty variable --- 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 d466280..a8909e4 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -5,7 +5,7 @@ set -e 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 [[ -n $PHONE_ADB_SERIAL_NUMBER ]]; then + if [[ -z $PHONE_ADB_SERIAL_NUMBER ]]; then print_message "ERROR: no suitable phone connected" exit 1 fi -- 2.36.1 From 5ab69f335fabe9284512e66b490665998e4b33c4 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 20:43:00 -0300 Subject: [PATCH 08/17] changed print_messagem position --- reinstall-magisk-on-lineageos | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index a8909e4..d3da336 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -2,6 +2,10 @@ 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') @@ -11,10 +15,6 @@ if [$PHONE_ADB_SERIAL_NUMBER = '']; then 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" -- 2.36.1 From 3d15d5369b7c7923e4d5cc2615837a01cb45835d Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 21:22:13 -0300 Subject: [PATCH 09/17] added quotes to if check --- 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 d3da336..e6364b1 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -50,7 +50,7 @@ get_build_url() { } check_exists_latest_lineageos_build() { - if [[ -f /tmp/lineageos.zip ]]; then + 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 -- 2.36.1 From d5e49e686c2283a84c5d6fe17df8c437be867339 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 21:45:26 -0300 Subject: [PATCH 10/17] fix check build archive exists logic --- reinstall-magisk-on-lineageos | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index e6364b1..711b05d 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -57,8 +57,9 @@ check_exists_latest_lineageos_build() { hash1=$( awk '{print $1}' /tmp/lineageos.sha256 ) hash2=$( sha256sum /tmp/lineageos.zip | awk '{print $1}' ) [[ -n $hash1 && -n $hash2 && $hash1 == $hash2 ]] + return fi - return + false } download_latest_lineageos_build() { -- 2.36.1 From a6b24ea0b6be448f5841f2ab06c5fa16e83a7c43 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 21:50:59 -0300 Subject: [PATCH 11/17] dockerfile: add curl and unzip packages --- Dockerfile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 52d9471..839fb9d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,8 +2,10 @@ FROM python:3.9.15-slim-buster RUN apt-get update RUN apt-get install -y \ - android-tools-adb \ - android-tools-fastboot + android-tools-adb \ + android-tools-fastboot \ + unzip \ + curl RUN pip3 install protobuf COPY . /magisk WORKDIR /magisk -- 2.36.1 From ee7dd0970921114f2bd353f9183b9130d3fb0f07 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 22:05:51 -0300 Subject: [PATCH 12/17] fix curl wrong option --- 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 711b05d..ef42cee 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -42,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" | -- 2.36.1 From 7a002b3f4dc7990092985bc268c06d00edf25d90 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 22:10:47 -0300 Subject: [PATCH 13/17] dockerfile: add git package --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 839fb9d..dca5cbf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -5,7 +5,8 @@ RUN apt-get install -y \ android-tools-adb \ android-tools-fastboot \ unzip \ - curl + curl \ + git RUN pip3 install protobuf COPY . /magisk WORKDIR /magisk -- 2.36.1 From f51bf593da46ae1b73235e854d9837e71d2314ce Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 22:35:15 -0300 Subject: [PATCH 14/17] trying to fix six module dependency --- Dockerfile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index dca5cbf..c3bedd3 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,7 +6,8 @@ RUN apt-get install -y \ android-tools-fastboot \ unzip \ curl \ - git + git \ + python3-six RUN pip3 install protobuf COPY . /magisk WORKDIR /magisk -- 2.36.1 From 56980bd12ee9d20a800a5d9ad53da420a33a26aa Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 23:13:52 -0300 Subject: [PATCH 15/17] trying to fix six module dependency - 2nd try --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index c3bedd3..70e2df8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,9 +6,9 @@ RUN apt-get install -y \ android-tools-fastboot \ unzip \ curl \ - git \ - python3-six -RUN pip3 install protobuf + git +RUN pip3 install protobuf \ + six COPY . /magisk WORKDIR /magisk CMD bash reinstall-magisk-on-lineageos -- 2.36.1 From 716ed4adbeacb53c7fe253336f83e1d27842c249 Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 23:15:50 -0300 Subject: [PATCH 16/17] remove debug print message; added curl silent --- reinstall-magisk-on-lineageos | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/reinstall-magisk-on-lineageos b/reinstall-magisk-on-lineageos index ef42cee..48e4e21 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -52,8 +52,7 @@ get_build_url() { check_exists_latest_lineageos_build() { 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 + 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 ]] -- 2.36.1 From 4d4b1b6cfaaf6c67e0aa624dc8bb70ec3b5e0c8c Mon Sep 17 00:00:00 2001 From: Ivo Capanema Date: Wed, 9 Nov 2022 23:41:47 -0300 Subject: [PATCH 17/17] better error message --- 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 48e4e21..ee3104a 100755 --- a/reinstall-magisk-on-lineageos +++ b/reinstall-magisk-on-lineageos @@ -10,7 +10,7 @@ PHONE_ADB_SERIAL_NUMBER=${ADB_DEVICE} # The adb serial number can be found by ru 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 suitable phone connected" + print_message "ERROR: no phone connected or connection unauthorized" exit 1 fi fi -- 2.36.1