WIP: Ready container execution #2

Open
ivooc wants to merge 19 commits from dev-ivo into main
  1. 10
      Dockerfile
  2. 37
      reinstall-magisk-on-lineageos

10
Dockerfile

@ -1,10 +1,14 @@
FROM python:3.9.15-buster FROM python:3.9.15-slim-buster
Review

Quais são as diferenças, vc sabe? Deve ser tipo, gcc, git, devtools?

Quais são as diferenças, vc sabe? Deve ser tipo, gcc, git, devtools?
RUN apt-get update RUN apt-get update
RUN apt-get install -y \ RUN apt-get install -y \
android-tools-adb \ android-tools-adb \
android-tools-fastboot android-tools-fastboot \
RUN pip3 install protobuf unzip \
curl \
git
RUN pip3 install protobuf \
six
COPY . /magisk COPY . /magisk
WORKDIR /magisk WORKDIR /magisk
CMD bash reinstall-magisk-on-lineageos CMD bash reinstall-magisk-on-lineageos

37
reinstall-magisk-on-lineageos

@ -2,14 +2,18 @@
set -e set -e
print_message() {
printf "$1\n"
}
PHONE_ADB_SERIAL_NUMBER=${ADB_DEVICE} # The adb serial number can be found by running `adb devices`. PHONE_ADB_SERIAL_NUMBER=${ADB_DEVICE} # The adb serial number can be found by running `adb devices`.
if [$PHONE_ADB_SERIAL_NUMBER = '']; then if [$PHONE_ADB_SERIAL_NUMBER = '']; then
PHONE_ADB_SERIAL_NUMBER=$(echo $(adb devices) | sed -rn 's/(^|(.* ))([^ ]*) device(( .*)|$)/\3/; T; p; q') 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 fi
print_message() {
printf "$1\n"
}
check_phone_is_connected() { check_phone_is_connected() {
if ! adb devices | grep --silent "$PHONE_ADB_SERIAL_NUMBER"; then if ! adb devices | grep --silent "$PHONE_ADB_SERIAL_NUMBER"; then
@ -38,7 +42,7 @@ get_device_downloads_page() {
} }
get_build_url() { get_build_url() {
curl --no-progress-meter "$(get_device_downloads_page)" | curl --silent "$(get_device_downloads_page)" |
grep --only-matching --ignore-case \ grep --only-matching --ignore-case \
"https://mirrorbits.lineageos.org/[^\"]*"$( "https://mirrorbits.lineageos.org/[^\"]*"$(
)"$(get_lineage_version)-signed.zip" | )"$(get_lineage_version)-signed.zip" |
@ -46,12 +50,15 @@ get_build_url() {
} }
check_exists_latest_lineageos_build() { check_exists_latest_lineageos_build() {
if [[ -f "/tmp/lineageos.zip" ]]; then
# The --location lets curl follow the redirection. # The --location lets curl follow the redirection.
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}' lineageos.sha256 ) hash1=$( awk '{print $1}' /tmp/lineageos.sha256 )
hash2=$( sha256sum lineageos.zip | awk '{print $1}' ) hash2=$( sha256sum /tmp/lineageos.zip | awk '{print $1}' )
[[ "$hash1" =~ "$hash2" ]] [[ -n $hash1 && -n $hash2 && $hash1 == $hash2 ]]
return return
fi
false
} }
download_latest_lineageos_build() { 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) 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 ] if [ "${magisk_package_name_count}" -eq 1 ]
then 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 ] elif [ "${magisk_package_name_count}" -eq 0 ]
then 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 exit -1
else 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" adb -s "$PHONE_ADB_SERIAL_NUMBER" shell pm list packages "$magisk_package_name"
print_message "Exiting."
exit -1 exit -1
fi fi
} }
@ -175,10 +181,11 @@ main() {
is_rooted_debugging_enabled is_rooted_debugging_enabled
print_message "Checking on phone if Magisk is installed" print_message "Checking on phone if Magisk is installed"
check_magisk_app check_magisk_app
print_message "Checking if build archive already exists"
if check_exists_latest_lineageos_build; then if check_exists_latest_lineageos_build; then
print_message "Build archive already exists, skipping download" print_message "Build archive found, skipping download"
else 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 download_latest_lineageos_build
fi fi
print_message "Extracting 'boot.img' from build archive in /tmp/boot.img" print_message "Extracting 'boot.img' from build archive in /tmp/boot.img"

Loading…
Cancel
Save