-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-fs-data.sh.in
62 lines (58 loc) · 2.01 KB
/
post-fs-data.sh.in
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/system/bin/sh
MODDIR="${0%/*}"
LOGFILE="${MODDIR}/post-fs-data.log"
PATCHER="${MODDIR}/gnss_patcher"
MODFILE="${MODDIR}/patched_oplusstanvbk"
SLOT="$(resetprop ro.boot.slot_suffix)"
PATH="/dev/block/bootdevice/by-name/oplusstanvbk${SLOT}"
exec > "$LOGFILE"
exec 2>&1
echo "@PROJECT_NAME@ v@PROJECT_VERSION@ by @MAGISK_AUTHOR@"
echo
echo "Slot: ${SLOT}"
echo
ls -laZ "$PATH"
echo
if [ -L "$PATH" ]; then
rm -f "$MODFILE"
ORIG="$(readlink -fn "$PATH")"
DEV="${ORIG}_mod"
chmod +x "$PATCHER"
echo "Running patcher"
"$PATCHER" -i "$ORIG" -o "$MODFILE"
ret=$?
if [ $ret -ne 0 ]; then
echo "Patcher failed!!!"
else
echo
# The loop device path must be in the form '/dev/block/sdX...' because mark_boot_successful()
# will ultimately call gpt_get_header() in gpt-utils and it will try to open the device name
# truncated to length 'sizeof("/dev/block/sda") - 1'. This means that if the original partition
# is '/dev/block/sdX00', it will try to open '/dev/block/sdX', so if we just use the next available
# loop device, it will fail opening '/dev/block/loo'. Using the same prefix as the original
# partition will solve the issue, but requires a "hack" to work.
# We first associate our patched file with the next available loop device, then we rename it.
# I'm not sure if it's still needed, since we don't replace '/dev/block/by-name/oplusstanvbk' anymore.
LOOP_DEV="$(/system/bin/losetup -sf "$MODFILE")"
if [ -z "$LOOP_DEV" ]; then
echo "ERROR: Cannot create loop device"
else
mv -f "$LOOP_DEV" "$DEV"
ret=$?
if [ $ret -ne 0 ]; then
echo "ERROR: Cannot rename loop device"
else
chcon -v "u:object_r:vendor_custom_ab_block_device:s0" "$DEV" # Set correct SELinux context
echo "Created loop device ${DEV}"
ls -laZ "$DEV"
echo
# Create symlink to newly created loop device
ln -sfv "$DEV" "$PATH"
echo
ls -laZ "$PATH"
fi
fi
fi
else
echo "ERROR: ${PATH} doesn't exist!!!"
fi