-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
install.sh
287 lines (214 loc) · 6.5 KB
/
install.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
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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
#!/system/bin/sh
# $id Installer/Upgrader
# Copyright 2019-2021, VR25
# License: GPLv3+
#
# devs: triple hashtags (###) mark non-generic code
# override the official Magisk module installer
SKIPUNZIP=1
echo
id=djs
domain=vr25
data_dir=/data/adb/$domain/${id}-data
# log
[ -z "${LINENO-}" ] || export PS4='$LINENO: '
mkdir -p $data_dir/logs
exec 2>$data_dir/logs/install.log
set -x
exxit() {
local e=$?
set +eu
rm -rf /dev/.$domain.${id}-install /data/adb/modules_update/$id
(abort) > /dev/null
echo
exit $e
} 2>/dev/null
trap exxit EXIT
# set up busybox
#BB#
[ -x /dev/.vr25/busybox/ls ] || {
mkdir -p /dev/.vr25/busybox
chmod 0700 /dev/.vr25/busybox
if [ -f /data/adb/$domain/bin/busybox ]; then
[ -x /data/adb/$domain/bin/busybox ] || chmod -R 0700 /data/adb/$domain/bin
/data/adb/$domain/bin/busybox --install -s /dev/.vr25/busybox
elif [ -f /data/adb/magisk/busybox ]; then
[ -x /data/adb/magisk/busybox ] || chmod 0700 /data/adb/magisk/busybox
/data/adb/magisk/busybox --install -s /dev/.vr25/busybox
elif which busybox > /dev/null; then
eval "$(which busybox) --install -s /dev/.vr25/busybox"
else
echo "(!) Install busybox or simply place it in /data/adb/$domain/bin/"
exit 3
fi
}
case $PATH in
/data/adb/$domain/bin:*) :;;
*) export PATH=/data/adb/$domain/bin:/dev/.vr25/busybox:$PATH;;
esac
#/BB#
# root check
[ $(id -u) -ne 0 ] && {
echo "(!) $0 must run as root (su)"
exit 4
}
get_prop() { sed -n "s|^$1=||p" ${2:-$srcDir/module.prop}; }
set_perms() {
local owner=${2:-0}
local perms=0600
local target=
target=$(readlink -f $1)
if echo $target | grep -q '.*\.sh$' || [ -d $target ]; then perms=0700; fi
chmod $perms $target
chown $owner:$owner $target
chcon u:object_r:system_file:s0 $target 2>/dev/null || :
}
set_perms_recursive() {
local owner=${2-0}
local target=
find $1 2>/dev/null | while read target; do set_perms $target $owner; done
}
set -eu
# set source code directory
srcDir="$(cd "${0%/*}" 2>/dev/null || :; echo "$PWD")"
# extract flashable zip if source code is unavailable
[ -d $srcDir/$id ] || {
srcDir=/dev/.$domain.${id}-install
rm -rf $srcDir 2>/dev/null || :
mkdir $srcDir
unzip "${APK:-${ZIPFILE:-$3}}" -d $srcDir/ >&2
}
name=$(get_prop name)
author=$(get_prop author)
version=$(get_prop version)
magiskModDir=/data/adb/modules
versionCode=$(get_prop versionCode)
accaFiles=/data/data/mattecarra.accapp/files ###
: ${installDir:=$accaFiles} ###
config=$data_dir/config.txt
# install in front-end's internal path by default
if [ "$installDir" != "$accaFiles" ]; then
case "$installDir" in
/data/data/*|/data/user/*)
accaFiles="$installDir"
;;
esac
fi
[ -d $magiskModDir ] && magisk=true || magisk=false
ls -d ${accaFiles%/*}* > /dev/null 2>&1 && acca=true || acca=false ###
# ensure AccA's files/ exists - to prevent unwanted downgrades ###
if $acca && [ ! -d $accaFiles ]; then
if mkdir $accaFiles 2>/dev/null; then
chown $(stat -c %u:%g ${accaFiles%/*}) $accaFiles
chmod $(stat -c %a ${accaFiles%/*}) $accaFiles
/system/bin/restorecon $accaFiles
fi
fi
# check/change parent installation directory
! $magisk || installDir=$magiskModDir
[ $installDir != /data/adb/$domain ] || mkdir -p $installDir
[ -d $installDir ] || {
installDir=/data/adb/$domain
mkdir -p $installDir
}
###
echo "$name $version ($versionCode)
Copyright 2019-2021, $author
GPLv3+
(i) Installing in $installDir/$id/..."
/system/bin/sh $srcDir/$id/uninstall.sh install
cp -R $srcDir/$id/ $installDir/
installDir=$(readlink -f $installDir/$id)
cp $srcDir/module.prop $installDir/
cp -f $srcDir/README.md $data_dir/
###
! $magisk || {
# symlink executables
mkdir -p $installDir/system/bin
ln -sf $installDir/djs-config.sh $installDir/system/bin/djsc
ln -sf $installDir/djs-config.sh $installDir/system/bin/djs-config
ln -sf $installDir/service.sh $installDir/system/bin/djsd
ln -sf $installDir/service.sh $installDir/system/bin/djs-daemon
ln -sf $installDir/djs-status.sh $installDir/system/bin/djs,
ln -sf $installDir/djs-status.sh $installDir/system/bin/djs-status
ln -sf $installDir/djs-stop.sh $installDir/system/bin/djs.
ln -sf $installDir/djs-stop.sh $installDir/system/bin/djs-stop
ln -sf $installDir/djs-version.sh $installDir/system/bin/djsv
ln -sf $installDir/djs-version.sh $installDir/system/bin/djs-version
}
###
if $acca; then
! $magisk || {
ln -fs $installDir $accaFiles/
# AccA post-uninstall cleanup script
mkdir -p /data/adb/service.d || {
rm /data/adb/service.d
mkdir /data/adb/service.d
}
echo "#!/system/bin/sh
# AccA post-uninstall cleanup script
until test -d /sdcard/Android \\
&& test .\$(getprop sys.boot_completed) = .1
do
sleep 60
done
sleep 60
[ -e $accaFiles/$id ] || rm -rf \$0 /data/adb/$domain/$id /data/adb/modules/$id 2>/dev/null
exit 0" | sed 's/^ //' > /data/adb/service.d/${id}-cleanup.sh
chmod 0700 /data/adb/service.d/${id}-cleanup.sh
}
fi
[ $installDir = /data/adb/$domain/$id ] || {
mkdir -p /data/adb/$domain
ln -s $installDir /data/adb/$domain/
}
# install binaries
cp -f $srcDir/bin/${id}-uninstaller.zip $data_dir/
# Termux, fix shebang
termux=false
case "$installDir" in
*/com.termux*)
termux=true
for f in $installDir/*.sh; do
! grep -q '^#\!/.*/sh' $f \
|| sed -i 's|^#!/.*/sh|#!/data/data/com.termux/files/usr/bin/bash|' $f
done
;;
esac
# set perms
case $installDir in
/data/data/*|/data/user/*)
set_perms_recursive $installDir $(stat -c %u ${installDir%/$id})
# Termux:Boot
! $termux || {
mkdir -p ${installDir%/*}/.termux/boot
ln -sf $installDir/service.sh ${installDir%/*}/.termux/boot/${id}-init.sh
chown -R $(stat -c %u:%g /data/data/com.termux) ${installDir%/*}/.termux
/system/bin/restorecon -R ${installDir%/*}/.termux > /dev/null 2>&1 || :
}
;;
*)
set_perms_recursive $installDir
;;
esac
set +eu
echo "- Done
"
# print links and changelog
sed -En "\|^## LINKS|,\$p" $srcDir/README.md \
| grep -v '^---' | sed 's/^## //'
###
echo "
(i) Rebooting is unnecessary
- $id commands may require the "/dev/.$domain/$id/" prefix (e.g., /dev/.$domain/$id/${id}c) until system is rebooted.
- Daemon started."
case $installDir in
/data/adb/modules*)
;;
*) echo "
(i) Non-Magisk users can enable $id auto-start by running /data/adb/$domain/$id/service.sh, a copy of, or a link to it - with init.d or an app that emulates it."
;;
esac
# initialize $id
/data/adb/$domain/$id/service.sh
exit 0