fix mount system

This commit is contained in:
Guillaume Castagnino 2021-04-03 12:10:04 +02:00
parent a15dc8aa3f
commit a520fb3953
1 changed files with 70 additions and 9 deletions

View File

@ -20,27 +20,88 @@
echo -n -e 'ui_print Installing customization scripts...\n' > /proc/self/fd/$2
SYSTEM="/system"
get_block_for_mount_point() {
grep -v "^#" /etc/recovery.fstab | grep " $1 " | tail -n1 | tr -s ' ' | cut -d' ' -f1
}
mount_system() {
mount /system
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")
# Modern devices use /system as root ("/")
system_as_root=`getprop ro.build.system_root_image`
if [ "$system_as_root" == "true" ]; then
SYSTEM="/system/system"
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
}
cd /tmp
unzip -o "$3"
mount_system
# Ensure system is unmounted so mounting succeeds
umount /system || umount /mnt/system || 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
CURRENTSLOT=`getprop ro.boot.slot_suffix`
if [ ! -z "$CURRENTSLOT" ]; then
if [ "$CURRENTSLOT" == "_a" ]; then
SLOT_SUFFIX="_a"
else
SLOT_SUFFIX="_b"
fi
fi
SYSTEM_BLOCK=$(find_block "system")
# Disable rw protection on dynamic partitions
if [ "$DYNAMIC_PARTITIONS" = "true" ]; then
blockdev --setrw "$SYSTEM_BLOCK"
if [ -n "$PRODUCT_BLOCK" ]; then
blockdev --setrw "$PRODUCT_BLOCK"
fi
if [ -n "$SYSTEM_EXT_BLOCK" ]; then
blockdev --setrw "$SYSTEM_EXT_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
echo -n -e 'ui_print "$SYSTEM_MNT mounted\n"' > /proc/self/fd/$2
else
echo -n -e 'ui_print "Could not mount $SYSTEM_MNT! Aborting\n"' > /proc/self/fd/$2
exit 1
fi
SYSTEM="${SYSTEM_MNT}/system"
export SYSTEM
/tmp/cm.sh
umount /system
umount $SYSTEM_MNT
echo -n -e 'ui_print done\n' > /proc/self/fd/$2
echo -n -e 'ui_print\n' > /proc/self/fd/$2