forked from Magisk-Modules-Repo/vold-posix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.sh
135 lines (111 loc) · 3.36 KB
/
uninstall.sh
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/system/bin/sh
##########################################################################################
# Preparation
##########################################################################################
MODDIR=${0%/*}
log_print() {
echo "Vold-posix: $1" >> /cache/magisk.log
}
error() {
echo "Vold-posix: error: $1" >> /cache/magisk.log
exit 1
}
require_new_magisk() {
log_print "***********************************"
log_print " Please install the latest Magisk! "
log_print "***********************************"
exit 1
# Default permissions
umask 022
# Load utility functions
if [ -f /data/adb/magisk/util_functions.sh ]; then
. /data/adb/magisk/util_functions.sh
NVBASE=/data/adb
else
require_new_magisk
fi
restore_boot() {
TMPDIR=/dev/tmp
INSTALLER=$TMPDIR/install
if [ ! $MAGISKVER -eq 171 ] && [ $MAGISKVER -lt 200 ]; then
error "! Only support Magisk 17.1 or 20+."
fi
# Initial cleanup
rm -rf $TMPDIR 2>/dev/null
mkdir -p $INSTALLER
# Preperation for flashable zips
setup_flashable
# Mount partitions
mount_partitions
# Setup busybox and binaries
$BOOTMODE && boot_actions
get_flags
find_boot_image
find_manager_apk
eval $BOOTSIGNER -verify < $BOOTIMAGE && BOOTSIGNED=true
$BOOTSIGNED && log_print "- Boot image is signed with AVB 1.0"
[ -z $BOOTIMAGE ] && error "! Unable to detect target image"
log_print "- Target image: $BOOTIMAGE"
[ -e "$BOOTIMAGE" ] || error "$BOOTIMAGE does not exist!"
log_print "- Unpacking boot image"
/data/adb/magisk/magiskboot --unpack "$BOOTIMAGE"
case $? in
1 )
error "! Unable to unpack boot image"
;;
2 )
log_print "- ChromeOS boot image detected"
error "! Unsupport type"
;;
3 )
log_print "! Sony ELF32 format detected"
error "! Unsupport type"
;;
4 )
log_print "! Sony ELF64 format detected"
error "! Unsupport type"
esac
log_print "- Checking ramdisk status"
if [ -e ramdisk.cpio ]; then
/data/adb/magisk/magiskboot --cpio ramdisk.cpio test
STATUS=$?
else
# Stock A only system-as-root
STATUS=0
fi
case $((STATUS & 3)) in
0 ) # Stock boot
log_print "- Stock boot image detected"
error "! Please install Magisk first"
;;
1 ) # Magisk patched
log_print "- Magisk patched boot image detected"
;;
2 ) # Other patched
log_print "! Boot image patched by unsupported programs"
error "! Please restore stock boot image"
;;
esac
if [ $((STATUS & 8)) -ne 0 ]; then
# Possibly using 2SI, export env var
export TWOSTAGEINIT=true
fi
log_print "- Patching ramdisk"
/data/adb/magisk/magiskboot cpio ramdisk.cpio \
"rm -r overlay.d/sbin"
if [ $((STATUS & 4)) -ne 0 ]; then
log_print "- Compressing ramdisk"
/data/adb/magisk/magiskboot --cpio ramdisk.cpio compress
fi
log_print "- Repacking boot image"
$MODDIR/magiskboot --repack "$BOOTIMAGE" || error "! Unable to repack boot image!"
log_print "- Flashing new boot image"
if ! flash_image new-boot.img "$BOOTIMAGE"; then
log_print "- Compressing ramdisk to fit in partition"
/data/adb/magisk/magiskboot --cpio ramdisk.cpio compress
/data/adb/magisk/magiskboot --repack "$BOOTIMAGE"
flash_image new-boot.img "$BOOTIMAGE" || error "! Insufficient partition size"
log_print "- Done, reboot to apply."
rm -rf $TMPDIR
}
restore_boot