|
|
@ -2,19 +2,15 @@ |
|
|
|
|
|
|
|
|
|
|
|
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 |
|
|
|
print_message "ERROR: phone '$PHONE_ADB_SERIAL_NUMBER' is not connected" |
|
|
|
print_message "ERROR: phone '$PHONE_ADB_SERIAL_NUMBER' is not connected" |
|
|
@ -42,7 +38,7 @@ get_device_downloads_page() { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
get_build_url() { |
|
|
|
get_build_url() { |
|
|
|
curl --silent "$(get_device_downloads_page)" | |
|
|
|
curl --no-progress-meter "$(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" | |
|
|
@ -50,15 +46,12 @@ 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 --silent --location "$(get_build_url)?sha256" --output /tmp/lineageos.sha256 |
|
|
|
curl --location "$(get_build_url)?sha256" --output /tmp/lineageos.sha256 |
|
|
|
hash1=$( awk '{print $1}' /tmp/lineageos.sha256 ) |
|
|
|
hash1=$( awk '{print $1}' lineageos.sha256 ) |
|
|
|
hash2=$( sha256sum /tmp/lineageos.zip | awk '{print $1}' ) |
|
|
|
hash2=$( sha256sum lineageos.zip | awk '{print $1}' ) |
|
|
|
[[ -n $hash1 && -n $hash2 && $hash1 == $hash2 ]] |
|
|
|
[[ "$hash1" =~ "$hash2" ]] |
|
|
|
return |
|
|
|
return |
|
|
|
fi |
|
|
|
|
|
|
|
false |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
download_latest_lineageos_build() { |
|
|
|
download_latest_lineageos_build() { |
|
|
@ -158,14 +151,15 @@ 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 "Magisk app seems to be installed on selected phone" |
|
|
|
print_message " [OK] 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." |
|
|
|
print_message " [ERROR] Magisk app seems not installed on selected phone. Exiting." |
|
|
|
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 |
|
|
|
} |
|
|
|
} |
|
|
@ -181,11 +175,10 @@ 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 found, skipping download" |
|
|
|
print_message "Build archive already exists, skipping download" |
|
|
|
else |
|
|
|
else |
|
|
|
print_message "Build archive not found or hash mismatch, downloading from $(get_build_url)" |
|
|
|
print_message "Downloading build archive 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" |
|
|
|