-
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfunction.sh
More file actions
215 lines (213 loc) · 5.43 KB
/
Copy pathfunction.sh
File metadata and controls
215 lines (213 loc) · 5.43 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# function
remove_cache() {
FILES=`find $MODPATH -type f -name *.apk | sed 's|.apk||g'`
APPS=`for FILE in $FILES; do basename $FILE; done`
for APP in $APPS; do
rm -f `find /data/system/package_cache\
/data/dalvik-cache /data/resource-cache\
-type f -name *$APP*`
done
}
apex_list() {
APXS=`ls -dp /apex/* | grep '/$' | sed -e 's|/$||' -e 's|^/apex/sharedlibs$||'`
}
mount_partitions_in_recovery() {
if [ "$BOOTMODE" != true ]; then
BLOCK=/dev/block/bootdevice/by-name
BLOCK2=/dev/block/mapper
ui_print "- Recommended to mount all partitions first"
ui_print " before installing this module"
ui_print " "
DIR=/vendor
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR$SLOT $DIR\
|| mount -o rw -t auto $BLOCK2$DIR$SLOT $DIR\
|| mount -o rw -t auto $BLOCK/cust $DIR\
|| mount -o rw -t auto $BLOCK2/cust $DIR
fi
DIRS="/product /system_ext /odm"
for DIR in $DIRS; do
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR$SLOT $DIR\
|| mount -o rw -t auto $BLOCK2$DIR$SLOT $DIR
fi
done
# apex_list
DIRS="/my_product /cache /persist /metadata /cust /klogdump
$APXS"
for DIR in $DIRS; do
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK$DIR $DIR\
|| mount -o rw -t auto $BLOCK2$DIR $DIR
fi
done
DIR=/data
if [ -d $DIR ] && ! is_mounted $DIR; then
mount -o rw -t auto $BLOCK/userdata $DIR\
|| mount -o rw -t auto $BLOCK2/userdata $DIR
fi
fi
}
get_device() {
DEV="`cat /proc/self/mountinfo | awk '{ if ( $5 == "'$1'" ) print $3 }' | head -1 | sed 's/:/ /g'`"
}
mount_mirror() {
RAN="`head -c6 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9'`"
while [ -e /dev/$RAN ]; do
RAN="`head -c6 /dev/urandom | base64 | tr -dc 'a-zA-Z0-9'`"
done
mknod /dev/$RAN b `get_device "$1"; echo $DEV`
if mount -t ext4 -o ro /dev/$RAN "$2"\
|| mount -t erofs -o ro /dev/$RAN "$2"\
|| mount -t f2fs -o ro /dev/$RAN "$2"\
|| mount -t auto -o ro /dev/$RAN "$2"; then
blockdev --setrw /dev/$RAN
rm -f /dev/$RAN
return 0
fi
rm -f /dev/$RAN
return 1
}
unmount_mirror() {
if [ "$BOOTMODE" == true ]\
&& [ "$HASMIRROR" == false ]; then
FOLDS="$MIRROR/apex/* $MIRROR/* $MIRROR"
for FOLD in $FOLDS; do
umount $FOLD
done
rm -rf $MIRROR/*
fi
}
remount_partitions() {
PARS="/ /system /vendor /product /system_ext /odm
/my_product $APXS"
for PAR in $PARS; do
mount -o ro,remount $PAR
done
}
mount_system_to_mirror() {
DIR=/system
if [ ! -d $MIRROR$DIR ]; then
HASMIRROR=false
remount_partitions
unmount_mirror
ui_print "- Mounting $MIRROR$DIR..."
if [ "$SYSTEM_ROOT" == true ]\
|| [ "$SYSTEM_AS_ROOT" == true ]; then
mkdir -p $MIRROR/system_root
if mount_mirror / $MIRROR/system_root; then
rm -rf $MIRROR$DIR
ln -sf $MIRROR/system_root$DIR $MIRROR
else
ui_print " ! Failed"
ui_print " Try to reboot device first"
rm -rf $MIRROR/system_root
abort
fi
else
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " ! Failed"
ui_print " Try to reboot device first"
rm -rf $MIRROR$DIR
abort
fi
fi
ui_print " "
else
HASMIRROR=true
fi
}
mount_parts_to_mirror() {
DIRS="/vendor /product /system_ext"
for DIR in $DIRS; do
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " Creating symlink instead"
rm -rf $MIRROR$DIR
if [ -d $MIRROR/system$DIR ]; then
ln -sf $MIRROR/system$DIR $MIRROR
fi
fi
ui_print " "
fi
done
}
mount_odm_to_mirror() {
DIR=/odm
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " Creating symlink instead"
rm -rf $MIRROR$DIR
if [ -d $MIRROR/system_root$DIR ]; then
ln -sf $MIRROR/system_root$DIR $MIRROR
elif [ -d $MIRROR/vendor$DIR ]; then
ln -sf $MIRROR/vendor$DIR $MIRROR
elif [ -d $MIRROR/system/vendor$DIR ]; then
ln -sf $MIRROR/system/vendor$DIR $MIRROR
fi
fi
ui_print " "
fi
}
mount_my_product_to_mirror() {
DIR=/my_product
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " Creating symlink instead"
rm -rf $MIRROR$DIR
if [ -d $MIRROR/system_root$DIR ]; then
ln -sf $MIRROR/system_root$DIR $MIRROR
fi
fi
ui_print " "
fi
}
mount_apex_to_mirror() {
for DIR in $APXS; do
if [ -d $DIR ] && [ ! -d $MIRROR$DIR ]; then
ui_print "- Mounting $MIRROR$DIR..."
mkdir -p $MIRROR$DIR
if ! mount_mirror $DIR $MIRROR$DIR; then
ui_print " ! Failed"
rm -rf $MIRROR$DIR
fi
ui_print " "
fi
done
}
mirror_setup() {
if [ "$BOOTMODE" == true ]; then
MAGISKTMP=`magisk --path`
if [ "$MAGISKTMP" ]; then
mount -o rw,remount $MAGISKTMP
INTERNALDIR=$MAGISKTMP/.magisk
MIRROR=$INTERNALDIR/mirror
else
INTERNALDIR=/mnt
mount -o rw,remount $INTERNALDIR
MIRROR=$INTERNALDIR/mirror
fi
# apex_list
mount_system_to_mirror
mount_parts_to_mirror
mount_odm_to_mirror
mount_my_product_to_mirror
mount_apex_to_mirror
fi
}
remove_sepolicy_rule() {
rm -rf /metadata/magisk/"$MODID"\
/mnt/vendor/persist/magisk/"$MODID"\
/persist/magisk/"$MODID"\
/data/unencrypted/magisk/"$MODID"\
/cache/magisk/"$MODID"\
/cust/magisk/"$MODID"\
/klogdump/magisk/"$MODID"
}