diff options
Diffstat (limited to 'META-INF/com/google/android/update-binary')
-rwxr-xr-x | META-INF/com/google/android/update-binary | 93 |
1 files changed, 48 insertions, 45 deletions
diff --git a/META-INF/com/google/android/update-binary b/META-INF/com/google/android/update-binary index ea44708..0dd5955 100755 --- a/META-INF/com/google/android/update-binary +++ b/META-INF/com/google/android/update-binary @@ -57,9 +57,11 @@ setup_mountpoint() { } is_mounted() { $bb mount | $bb grep -q " $1 "; } umount_all() { - ($BOOTMODE || umount_apex; - $bb umount /system; - $bb umount -l /system; + (if ! $BOOTMODE; then + umount_apex; + $bb umount /system; + $bb umount -l /system; + fi; if [ -e /system_root ]; then $bb umount /system_root; $bb umount -l /system_root; @@ -72,55 +74,56 @@ umount_all() { fi) 2>/dev/null; } mount_apex() { - [ -d /system/apex ] || return 1 - [ -L /apex ] && rm -f /apex - if [ -f "/system/apex/com.android.runtime.release.apex" ]; then - local j=0 - [ -e /dev/block/loop1 ] && local minorx=$(ls -l /dev/block/loop1 | $bb awk '{print $6}') || local minorx=1 - for i in /system/apex/*.apex; do - local dest="/apex/$(basename $i | sed 's/.apex$//')" - [ "$dest" == "/apex/com.android.runtime.release" ] && dest="/apex/com.android.runtime" - mkdir -p $dest - $bb unzip -qo $i apex_payload.img -d /apex - mv -f /apex/apex_payload.img $dest.img - while [ $j -lt 50 ]; do - loop=/dev/loop$j - $bb mknod $loop b 7 $((j * minorx)) 2>/dev/null - $bb losetup $loop $dest.img 2>/dev/null - j=$((j + 1)) - $bb losetup $loop | grep -q $dest.img && break - done; - uloop="$uloop $((j - 1))" - $bb mount -t ext4 -o loop,noatime,ro $loop $dest || return 1 - done - # Already extracted payload imgs present, just mount the folders - elif [ -d "/system/apex/com.android.runtime.release" ]; then - for i in /system/apex/*; do - local dest="/apex/$(basename $i)" - [ "$dest" == "/apex/com.android.runtime.release" ] && dest="/apex/com.android.runtime" - mkdir -p $dest - $bb mount -o bind,ro $i $dest - done - fi + test -d /system/apex || return 1; + local apex dest loop minorx num; + setup_mountpoint /apex; + test -e /dev/block/loop1 && minorx=$(ls -l /dev/block/loop1 | $bb awk '{ print $6 }') || minorx=1; + num=0; + for apex in /system/apex/*; do + dest=/apex/$(basename $apex .apex); + test "$dest" == /apex/com.android.runtime.release && dest=/apex/com.android.runtime; + mkdir -p $dest; + case $apex in + *.apex) + $bb unzip -qo $apex apex_payload.img -d /apex; + $bb mv -f /apex/apex_payload.img $dest.img; + $bb mount -t ext4 -o ro,noatime $dest.img $dest 2>/dev/null; + if [ $? != 0 ]; then + while [ $num -lt 64 ]; do + loop=/dev/block/loop$num; + ($bb mknod $loop b 7 $((num * minorx)); + $bb losetup $loop $dest.img) 2>/dev/null; + num=$((num + 1)); + $bb losetup $loop | $bb grep -q $dest.img && break; + done; + $bb mount -t ext4 -o ro,loop,noatime $loop $dest; + if [ $? != 0 ]; then + $bb losetup -d $loop 2>/dev/null; + fi; + fi; + ;; + *) $bb mount -o bind $apex $dest;; + esac; + done; } umount_apex() { - [ -d /apex ] || return 1 - for i in /apex/*; do - $bb umount -l $i 2>/dev/null - done - if [ -f "/system/apex/com.android.runtime.release.apex" ]; then - for i in $uloop; do - local loop=/dev/loop$i - losetup -d $loop 2>/dev/null || break - done - fi - rm -rf /apex + test -d /apex || return 1; + local dest loop; + for dest in $($bb find /apex -type d -mindepth 1 -maxdepth 1); do + if [ -f $dest.img ]; then + loop=$($bb mount | $bb grep $dest | $bb cut -d" " -f1); + fi; + ($bb umount -l $dest; + $bb losetup -d $loop) 2>/dev/null; + done; + rm -rf /apex; } restore_env() { test "$savedpath" && export LD_LIBRARY_PATH="$savedpath"; test "$savedpre" && export LD_PRELOAD="$savedpre"; umount_all; - ($bb mv -f /system_link /system; + ($bb mv -f /apex_link /apex; + $bb mv -f /system_link /system; $bb mv -f /system_root_link /system_root; $bb umount -l /dev/random) 2>/dev/null; } |