forked from Magisk-Modules-Repo/mm
-
Notifications
You must be signed in to change notification settings - Fork 13
/
mm
156 lines (119 loc) · 3.09 KB
/
mm
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
#!/sbin/sh
# Magisk Manager for Recovery Mode (mm)
# Copyright (C) 2018-2024, VR25 & Rikj000 @ xda-developers
# License: GPLv3+
main() {
tmpDir=/dev/_mm
tmpf=$tmpDir/tmpf
tmpf2=$tmpDir/tmpf2
mountPath=/_magisk
img=/data/adb/magisk.img
[ -f $img ] || img=/data/adb/modules
echo -e "\nMagisk Manager for Recovery Mode (mm) 2024.9.8
Copyright (C) 2018-2024, VR25 & Rikj000 @ xda-developers
License: GPLv3+\n"
trap 'exxit $?' EXIT
if is_mounted /storage/emulated; then
echo -e "(!) This is meant to be used in recovery environment only!\n"
exit 1
fi
umask 022
set -euo pipefail
mount /data 2>/dev/null || :
mount /cache 2>/dev/null || :
if [ ! -d /data/adb/magisk ]; then
echo -e "(!) No Magisk installation found or installed version is not supported.\n"
exit 1
fi
mkdir -p $tmpDir
mount -o remount,rw /
mkdir -p $mountPath
[ -f $img ] && e2fsck -fy $img 2>/dev/null 1>&2 || :
mount -o rw $img $mountPath
cd $mountPath
options
}
options() {
local opt=""
while :; do
echo -n "##########################
l) List installed modules
##########################
Toggle
c) Core only mode
m) Magic mount
d) Disable
r) Remove
##########################
q) Quit
##########################
?) "
read opt
echo
case $opt in
m) toggle_mnt;;
d) toggle_disable;;
l) echo -e "Installed Modules\n"; ls_mods;;
r) toggle_remove;;
q) exit 0;;
c) toggle_com;;
esac
break
done
echo -en "\n(i) Press <enter> to continue or \"q <enter>\" to quit... "
read opt
[ -z "$opt" ] || exit 0
echo
options
}
is_mounted() { grep -q "$1" /proc/mounts; }
ls_mods() { ls -1 $mountPath | grep -v 'lost+found' || echo "<None>"; }
exxit() {
set +euo pipefail
cd /
umount -f $mountPath
rmdir $mountPath
mount -o remount,ro /
rm -rf $tmpDir
[ ${1:-0} -eq 0 ] && { echo -e "\nGoodbye.\n"; exit 0; } || exit $1
} 2>/dev/null
toggle() {
local input="" mod=""
local file="$1" present="$2" absent="$3"
for mod in $(ls_mods | grep -v \<None\> || :); do
echo -n "$mod ["
[ -f $mountPath/$mod/$file ] && echo "$present]" || echo "$absent]"
done
echo -en "\nInput pattern(s) (e.g., a dot for all, acc, or fbind|xpo|viper): "
read input
echo
for mod in $(ls_mods | grep -v \<None\> || :); do
if echo $mod | grep -Eq "${input:-_noMatch_}"; then
[ -f $mountPath/$mod/$file ] && { rm $mountPath/$mod/$file; echo "$mod [$absent]"; } \
|| { touch $mountPath/$mod/$file; echo "$mod [$present]"; }
fi
done
}
toggle_mnt() {
echo -e "Toggle Magic Mount\n"
[ -f $img ] && { toggle auto_mount ON OFF || :; } \
|| toggle skip_mount OFF ON
}
toggle_disable() {
echo -e "Toggle ON/OFF\n"
toggle disable OFF ON
}
toggle_remove() {
echo -e "Mark for Removal ([X])\n"
toggle remove X " "
}
toggle_com() {
if [ -f /cache/.disable_magisk ] || [ -f /data/cache/.disable_magisk ]; then
rm /data/cache/.disable_magisk /cache/.disable_magisk 2>/dev/null || :
echo "(i) Core only mode [OFF]"
else
touch /data/cache/.disable_magisk /cache/.disable_magisk 2>/dev/null || :
echo "(i) Core only mode [ON]"
fi
}
main