-
Notifications
You must be signed in to change notification settings - Fork 1
/
modmanager
executable file
·88 lines (71 loc) · 2.29 KB
/
modmanager
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
#!/system/bin/sh
PRELOAD_D=/opt/etc/preload.d/
if [ $# -eq 0 ]; then
sh $0 help
exit 1
fi
if [ $1 = "enable" ]; then
if [ $# -ne 3 ]; then
echo "illegal number of parameters"
sh $0 help
exit 1
fi
target="$2"
modlib="lib$3.so"
if [[ ! -f "${PRELOAD_D}${modlib}" ]] && [[ ! -L "${PRELOAD_D}${modlib}" ]]; then
echo "mod not found at ${PRELOAD_D}${modlib}"
exit 2
fi
if [[ -L "${PRELOAD_D}${target}" ]]; then
target=$(basename $(readlink "${PRELOAD_D}${target}"))
elif [[ ! -d "${PRELOAD_D}${target}" ]]; then
mkdir -p "${PRELOAD_D}${target}"
fi
if [[ -f "${PRELOAD_D}${target}/${modlib}" ]]; then
exit 0
fi
ln -sf "${PRELOAD_D}${modlib}" "${PRELOAD_D}${target}/${modlib}"
#this will force init to reload the service, which should auto enable it
killall ${target} > /dev/null 2>&1 || true
killall ${target}_original > /dev/null 2>&1 || true
elif [ $1 = "disable" ]; then
if [ $# -ne 3 ]; then
echo "illegal number of parameters"
sh $0 help
exit 1
fi
target="$2"
modlib="lib$3.so"
if [[ -L "${PRELOAD_D}${target}" ]]; then
target=$(basename $(readlink "${PRELOAD_D}${target}"))
elif [[ ! -d "${PRELOAD_D}${target}" ]]; then
mkdir -p "${PRELOAD_D}${target}"
fi
if [[ -L "${PRELOAD_D}${target}/${modlib}" ]]; then
rm -f "${PRELOAD_D}${target}/${modlib}"
killall ${target} > /dev/null 2>&1 || true
killall ${target}_original > /dev/null 2>&1 || true
else
echo "no such mod enabled"
fi
elif [ $1 = "list" ]; then
if [ $# -eq 1 ]; then
echo "mods available:"
find ${PRELOAD_D} -name "*.so" -maxdepth 1 -exec basename {} \; | busybox sed -r 's/^lib(.*).so$/\1/'
elif [ $# -eq 2 ]; then
echo "mods enabled for ${2}:"
find ${PRELOAD_D}${2}/ -name "*.so" -maxdepth 1 -type l -exec basename {} \; | busybox sed -r 's/^lib(.*).so$/\1/'
fi
else
echo "usage: 'modmanager command [args]' where command is one of
- enable target_name mod_name
- disable target_name mod_name
- list [target_name]
target_name is the name of the service, eg. dji_glasses
for your convience you may use the aliases 'diy_glasses'
and 'fpv_glasses'.
mod_name is the name of your mod, where the associated
'lib\${mod_name}.so' must be linked to (or located in)
/opt/etc/preload.d/
"
fi