-
Notifications
You must be signed in to change notification settings - Fork 0
/
mm-ksu
161 lines (127 loc) · 3.31 KB
/
mm-ksu
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
#!/sbin/sh
# KernelSU Manager for Recovery Mode (mm)
# Copyright (C) 2017-2019, VR25 @ xda-developers
# License: GPLv3+
main() {
tmpDir=/dev/_mm
tmpf=$tmpDir/tmpf
tmpf2=$tmpDir/tmpf2
mountPath=/_magisk
img=/data/adb/ksu/modules.img
[ -f $img ] || img=/data/adb/ksu
echo -e "\nKernelSU Manager for Recovery Mode (mm) 2019.4.4
Copyright (C) 2017-2019, VR25 @ 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/ksu ]; then
echo -e "(!) No KernelSU 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 ON
e) Core only mode OFF
d) Disable
r) Remove
##########################
q) Quit
##########################
?) "
read opt
echo
case $opt in
d) toggle_disable;;
l) echo -e "Installed Modules\n"; ls_mods;;
r) toggle_remove;;
q) exit 0;;
c) toggle_com;;
e) untoggle_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_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() {
# Use find command to get all subdirectories in /_magisk
find /_magisk -maxdepth 1 -mindepth 1 -type d | while read -r dir; do
# Check if the entry is a directory
if [ -d "$dir" ]; then
# Create a file named "disable" inside the directory
touch "$dir/disable"
fi
done
echo "(i) Core only mode [ON]"
}
untoggle_com() {
# Use find command to get all subdirectories in /_magisk
find /_magisk -maxdepth 1 -mindepth 1 -type d | while read -r dir; do
# Check if the entry is a directory
if [ -d "$dir" ]; then
# Delete the "disable" file inside the directories
rm -rf "$dir/disable"
fi
done
echo "(i) Core only mode [OFF]"
}
main