From 9af25763c76918adfcf768156e697d99cbb901cd Mon Sep 17 00:00:00 2001 From: Sangam Kumar Shrestha <2shrestha22@gmail.com> Date: Thu, 22 Dec 2022 22:19:25 +0545 Subject: [PATCH] Update script (#1) * update script * update readme * update addon.d script to v3 --- .vscode/launch.json | 14 ++ README.md | 11 +- build.sh | 2 + .../META-INF/com/google/android/update-binary | 201 +++++++++++++++--- ...dialer-rro.sh => 20-lineage-dialer-rro.sh} | 19 +- .../vendor/overlay/lineage-dialer-rro.apk | Bin 6 files changed, 204 insertions(+), 43 deletions(-) create mode 100644 .vscode/launch.json create mode 100755 build.sh mode change 100644 => 100755 flashable/META-INF/com/google/android/update-binary rename flashable/system/addon.d/{99-lineage-dialer-rro.sh => 20-lineage-dialer-rro.sh} (56%) rename flashable/{ => system}/vendor/overlay/lineage-dialer-rro.apk (100%) diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..744b214 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,14 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "bashdb", + "request": "launch", + "name": "Bash-Debug (simplest configuration)", + "program": "${file}" + } + ] +} \ No newline at end of file diff --git a/README.md b/README.md index 5a3dc29..5ccfdd3 100644 --- a/README.md +++ b/README.md @@ -48,15 +48,20 @@ Align the APK. * After all the files have been copied, reboot the device: `adb reboot` -### Installation with Flashable zip (not tested/recommended) +### Installation with Flashable zip * Create zip: `7za a -tzip -r lineage-dialer-rro.zip ./flashable/*` * Sign: `java -jar ./bin/zipsigner.jar lineage-dialer-rro.zip lineage-dialer-rro-signed.zip` +* Reboot to sideload mode: +`adb reboot sideload` + +* Sideload zip: +`adb sideload lineage-dialer-rro-signed.zip` ## Resources: -update-binary: https://github.com/arovlad/bromite-webview-overlay +update-binary: MindTheGapps (http://downloads.codefi.re/jdcteam/javelinanddart/gapps) -zip-signer: https://forum.xda-developers.com/t/dev-template-complete-shell-script-flashable-zip-replacement-signing-script.2934449/ +zipsigner: https://github.com/topjohnwu/Magisk/tree/v20.4/signing, https://forum.xda-developers.com/t/dev-template-complete-shell-script-flashable-zip-replacement-signing-script.2934449/ diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..944cb33 --- /dev/null +++ b/build.sh @@ -0,0 +1,2 @@ +7za a -tzip -r lineage-dialer-rro.zip ./flashable/* +java -jar ./bin/zipsigner.jar lineage-dialer-rro.zip lineage-dialer-rro-signed.zip \ No newline at end of file diff --git a/flashable/META-INF/com/google/android/update-binary b/flashable/META-INF/com/google/android/update-binary old mode 100644 new mode 100755 index 15e43d1..45adb6e --- a/flashable/META-INF/com/google/android/update-binary +++ b/flashable/META-INF/com/google/android/update-binary @@ -1,46 +1,185 @@ #!/sbin/sh -# Exit immediately if the device is not Treble-enabled -if [ ! $(getprop ro.treble.enabled) ] - then echo -e "ui_print Your device is not Treble-enabled!" >> /proc/self/fd/${2} - exit 1 +# SCRIPT FROM MINDTHEGAPPS FLASHABLE ZIP + +OUTFD="/proc/self/fd/$2" +ZIP=$3 + +set_con() { + chcon -h u:object_r:"$1":s0 $2 + chcon u:object_r:"$1":s0 $2 +} + +set_perm() { + chmod $1 $2 +} + +set_owner() { + chown $1:$2 $3 +} + +ui_print() { + echo "ui_print $1" > "$OUTFD"; + echo "ui_print" > "$OUTFD"; +} + +cleanup() { + ui_print "Cleaning up files" + rm -rf $TMP/system + rm -rf $TMP/bin + + ui_print "Unmounting partitions" + umount -l "$SYSTEM_MNT" + umount -l /vendor || true +} + +error() { + ui_print "$1" + cleanup + exit 1 +} + +error_mounting() { + error "Could not mount $1! Aborting" +} + +get_block_for_mount_point() { + grep -v "^#" /etc/recovery.fstab | grep "[[:blank:]]$1[[:blank:]]" | tail -n1 | tr -s [:blank:] ' ' | cut -d' ' -f1 +} + +find_block() { + local name="$1" + local fstab_entry=$(get_block_for_mount_point "/$name") + # P-SAR hacks + [ -z "$fstab_entry" ] && [ "$name" = "system" ] && fstab_entry=$(get_block_for_mount_point "/") + [ -z "$fstab_entry" ] && [ "$name" = "system" ] && fstab_entry=$(get_block_for_mount_point "/system_root") + + local dev + if [ "$DYNAMIC_PARTITIONS" = "true" ]; then + if [ -n "$fstab_entry" ]; then + dev="${BLK_PATH}/${fstab_entry}${SLOT_SUFFIX}" + else + dev="${BLK_PATH}/${name}${SLOT_SUFFIX}" + fi + else + if [ -n "$fstab_entry" ]; then + dev="${fstab_entry}${SLOT_SUFFIX}" + else + dev="${BLK_PATH}/${name}${SLOT_SUFFIX}" + fi + fi + + if [ -b "$dev" ]; then + echo "$dev" + fi +} + + +ui_print "****************************" +ui_print "Lineage Dialer RRO installer" +ui_print "****************************" + +ui_print "Extracting files" +TMP=/tmp +cd "$TMP" || exit 1 +unzip -o "$ZIP" +rm -rf META-INF + +ui_print "Mounting partitions" + +# Ensure system is unmounted so mounting succeeds +umount /system || umount /mnt/system || true +umount /vendor || true + +# Find partitions +DYNAMIC_PARTITIONS=$(getprop ro.boot.dynamic_partitions) +if [ "$DYNAMIC_PARTITIONS" = "true" ]; then + BLK_PATH="/dev/block/mapper" +else + BLK_PATH=/dev/block/bootdevice/by-name fi -# Exit immediately if a command fails -set -e +CURRENTSLOT=$(getprop ro.boot.slot_suffix) +if [ ! -z "$CURRENTSLOT" ]; then + if [ "$CURRENTSLOT" == "_a" ]; then + SLOT_SUFFIX="_a" + else + SLOT_SUFFIX="_b" + fi +fi -# Extract the package to a temporary location -unzip -oq ${3} -d "/tmp/LineageDialerRRO" +SYSTEM_BLOCK=$(find_block "system") +VENDOR_BLOCK=$(find_block "vendor") -# Create faux mountpoints -mkdir /picodroid_system -mkdir /picodroid_vendor +# Disable rw protection on dynamic partitions +if [ "$DYNAMIC_PARTITIONS" = "true" ]; then + blockdev --setrw "$SYSTEM_BLOCK" + if [ -n "$VENDOR_BLOCK" ]; then + blockdev --setrw "$VENDOR_BLOCK" + fi +fi + +# Mount and define SYSTEM_OUT +SYSTEM_MNT=/mnt/system +mkdir -p "$SYSTEM_MNT" || true +if mount -o rw "$SYSTEM_BLOCK" "$SYSTEM_MNT"; then +ui_print "$SYSTEM_MNT mounted" +else +error_mounting "$SYSTEM_MNT" +fi +# System out is actual /system when devices is booted, +# while or recovery it can be /mnt/system/system, so the file structure look like +# /mnt/system/system -> /system +# /mnt/system/system/bin -> /system/bin +# /mnt/system/vendor -> /vendor -# Mount the neccesary partitions -mount -o rw $(readlink -f $(cd /dev && find /dev/block -type l -name system$(getprop ro.boot.slot_suffix) | head -n 1 )) /picodroid_system -mount -o rw $(readlink -f $(cd /dev && find /dev/block -type l -name vendor$(getprop ro.boot.slot_suffix) | head -n 1 )) /picodroid_vendor +SYSTEM_OUT="${SYSTEM_MNT}/system" -# Copy the overlay to the appropriate location -cp /tmp/LineageDialerRRO/vendor/overlay/lineage-dialer-rro.apk /picodroid_vendor/overlay +# Ignore {vendor} block devices in case they are symlinks +# This is common on devices where maintainers have chosen not to use +# real partitions because of their size being too small to be useful +if [ -L "${SYSTEM_MNT}/vendor" ]; then +VENDOR_BLOCK="" +fi -# Copy the OTA survival script to the appropriate location -if [ -d /picodroid_system/system/addon.d ] - then cp /tmp/LineageDialerRRO/system/addon.d/99-lineage-dialer-rro.sh /picodroid_system/system/addon.d +if [ -n "$VENDOR_BLOCK" ]; then + mkdir /vendor || true + if mount -o rw "$VENDOR_BLOCK" /vendor; then + ui_print "/vendor mounted" + else + error_mounting "/vendor" + fi fi -# Make the script executable -chmod 755 /picodroid_system/system/addon.d/99-lineage-dialer-rro.sh +# Enter inside Flashable system. +cd system || exit 1 + +ui_print "Preparing files for copying" +# Set correct permission for dirs +for d in $(find . -mindepth 1 -type d -type d); do + set_perm 0755 $d + set_owner root root $d +done +# Set correct permission for files +for f in $(find . -type f); do + type=$(echo "$f" | sed 's/.*\.//') + if [ "$type" == "sh" ] || [ "$type" == "$f" ]; then + set_perm 0755 $f + else + set_perm 0644 $f + fi + set_owner root root $f + set_con system_file $f +done -# Unmount the previously mounted partitions -umount -l /picodroid_system -umount -l /picodroid_vendor +ui_print "Copying files" +cp --preserve=a -r ./* "${SYSTEM_OUT}/" +if [ -n "$VENDOR_BLOCK" ]; then + cp --preserve=a -r ./vendor/* /vendor +fi -# Delete de faux mountpoints -rmdir /picodroid_system -rmdir /picodroid_vendor -# Clean up the installation files -rm -rf /tmp/LineageDialerRRO +cleanup -# Inform the user that the update has been successful -echo -e "ui_print Update successfully installed!" >> /proc/self/fd/${2} +ui_print "Done!" +exit 0 diff --git a/flashable/system/addon.d/99-lineage-dialer-rro.sh b/flashable/system/addon.d/20-lineage-dialer-rro.sh similarity index 56% rename from flashable/system/addon.d/99-lineage-dialer-rro.sh rename to flashable/system/addon.d/20-lineage-dialer-rro.sh index 8dc697f..3ceffd2 100644 --- a/flashable/system/addon.d/99-lineage-dialer-rro.sh +++ b/flashable/system/addon.d/20-lineage-dialer-rro.sh @@ -1,13 +1,9 @@ #!/sbin/sh # -# ADDOND_VERSION=2 +# ADDOND_VERSION=3 # -# /system/addon.d/99-lineage-dialer-rro.sh -# During a LineageOS upgrade, this script backs up /vendor/overlay/lineage-dialer-rro.apk, -# /system is formatted and reinstalled, then the file is restored. +# /system/addon.d/20-lineage-dialer-rro.sh # -# Copied from 50-lineage.sh - . /tmp/backuptool.functions list_files() { @@ -19,14 +15,14 @@ EOF case "$1" in backup) list_files | while read FILE DUMMY; do - backup_file $S/"$FILE" + backup_file $S/$FILE done ;; restore) list_files | while read FILE REPLACEMENT; do R="" [ -n "$REPLACEMENT" ] && R="$S/$REPLACEMENT" - [ -f "$C/$S/$FILE" ] && restore_file $S/"$FILE" "$R" + [ -f "$C/$S/$FILE" ] && restore_file $S/$FILE $R done ;; pre-backup) @@ -39,6 +35,11 @@ case "$1" in # Stub ;; post-restore) - # Stub + for i in $(list_files); do + f=$(get_output_path "$S/$i") + chown root:root $f + chmod 644 $f + chmod 755 $(dirname $f) + done ;; esac diff --git a/flashable/vendor/overlay/lineage-dialer-rro.apk b/flashable/system/vendor/overlay/lineage-dialer-rro.apk similarity index 100% rename from flashable/vendor/overlay/lineage-dialer-rro.apk rename to flashable/system/vendor/overlay/lineage-dialer-rro.apk