forked from VR-25/acc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
install.sh
280 lines (206 loc) · 6.46 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
#!/system/bin/sh
# ACC Installer/Upgrader
# Copyright 2019-2020, VR25
# License: GPLv3+
#
# devs: triple hashtags (###) mark non-generic code
# override the official Magisk module installer
SKIPUNZIP=1
echo
id=acc
domain=vr25
umask 0077
data_dir=/sdcard/Documents/$domain/$id
# 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/.busybox/ls ] || {
mkdir -p /dev/.busybox
chmod 0700 /dev/.busybox
if [ -f /data/adb/bin/busybox ]; then
[ -x /data/adb/bin/busybox ] || chmod -R 0700 /data/adb/bin
/data/adb/bin/busybox --install -s /dev/.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/.busybox
elif which busybox > /dev/null; then
eval "$(which busybox) --install -s /dev/.busybox"
else
echo "(!) Install busybox or simply place it in /data/adb/bin/"
exit 3
fi
}
case $PATH in
/data/adb/bin:*) :;;
*) export PATH=/data/adb/bin:/dev/.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} perms=0600 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
}
set_perms_recursive() {
local owner=${2-0} target=""
find $1 2>/dev/null | while read target; do set_perms $target $owner; done
}
set -eu
# set source code directory
[ -f $PWD/${0##*/} ] && srcDir=$PWD || srcDir=${0%/*}
srcDir=${srcDir/#"${0##*/}"/"."}
# extract flashable zip if source code is unavailable
[ -f $srcDir/module.prop ] || {
srcDir=/dev/.$domain.${id}-install
rm -rf $srcDir 2>/dev/null || :
mkdir $srcDir
unzip "${3:-${ZIPFILE}}" -d $srcDir/ >&2
}
name=$(get_prop name)
author=$(get_prop author)
version=$(get_prop version)
magiskModDir=/data/adb/modules
versionCode=$(get_prop versionCode)
: ${installDir:=/data/data/mattecarra.${id}app/files} ###
config=$data_dir/config.txt
[ -d $magiskModDir ] && magisk=true || magisk=false
ls -d /data/app/mattecarra.${id}app* > /dev/null 2>&1 && acca=true || acca=false ###
# ensure AccA's files/ exists - to prevent unwanted ACC downgrades ###
if $acca && [ ! -d /data/data/mattecarra.${id}app/files ]; then
mkdir -p /data/data/mattecarra.${id}app/files
chmod 0777 /data/data/mattecarra.${id}app \
/data/data/mattecarra.${id}app/files
fi
# check/change parent installation directory
! $magisk || installDir=$magiskModDir
[ $installDir != /data/adb/vr25 ] || mkdir -p $installDir
[ -d $installDir ] || {
installDir=/data/adb/vr25
mkdir -p $installDir
}
###
echo "$name $version ($versionCode)
Copyright 2017-2020, $author
GPLv3+
(i) Installing in $installDir/$id/..."
# migrate #legacy data
if [ -d /data/adb/${id}-data ]; then
mv -f /data/adb/${id}-data/* /data/adb/${id}-data/.* \
$data_dir/ 2>/dev/null || :
elif [ -d /sdcard/Download/$id ]; then
mv -f /sdcard/Download/$id/* /sdcard/Download/$id/.* \
$data_dir/ 2>/dev/null || :
else
mv -f /sdcard/$domain/$id/* /sdcard/$domain/$id/.* \
$data_dir/ 2>/dev/null || :
fi
rm -rf $data_dir/info 2>/dev/null || :
mkdir -p /dev/.$domain
mv /dev/.$id /dev/.$domain/$id 2>/dev/null || :
/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 -fs $installDir/${id}.sh $installDir/system/bin/$id
ln -fs $installDir/${id}.sh $installDir/system/bin/${id}d,
ln -fs $installDir/${id}.sh $installDir/system/bin/${id}d.
ln -fs $installDir/${id}a.sh $installDir/system/bin/${id}a
ln -fs $installDir/service.sh $installDir/system/bin/${id}d
}
###
if $acca; then
! $magisk || {
ln -fs $installDir /data/data/mattecarra.${id}app/files/
# 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/Download \\
&& test .\$(getprop sys.boot_completed) = .1
do
sleep 60
done
sleep 60
[ -e /data/data/mattecarra.${id}app/files/$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/vr25
ln -s $installDir /data/adb/$domain/
}
# install binaries
cp -f $srcDir/bin/${id}-uninstaller.zip $data_dir/
# Termux, fix shebang
[[ $installDir != *com.termux* ]] && termux=false || {
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
}
# set perms
case $installDir in
/data/*/files/*$id)
pkg=${installDir%/files/*$id}
pkg=${pkg##/data*/}
owner=$(grep $pkg /data/system/packages.list | cut -d ' ' -f 2)
set_perms_recursive $installDir $owner
# 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
chmod -R 0755 ${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 -v) until system is rebooted.
- Daemon started."
[ $installDir = /data/adb ] && 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."
# initialize $id
/data/adb/$domain/$id/service.sh --init
exit 0