1
1
#! /system/bin/sh
2
2
# $id Installer/Upgrader
3
- # Copyright (c) 2019, VR25 (xda-developers.com )
3
+ # Copyright (c) 2019-2020 , VR25 (xda-developers)
4
4
# License: GPLv3+
5
5
6
+ # override the official Magisk module installer
7
+ SKIPUNZIP=1
8
+
6
9
set +x
7
10
echo
8
11
id=acc
@@ -16,23 +19,25 @@ set -x
16
19
trap ' e=$?; echo; exit $e' EXIT
17
20
18
21
# set up busybox
22
+ # BB#
19
23
if [ -d /sbin/.magisk/busybox ]; then
20
- [[ $PATH == /sbin/.magisk/busybox* ]] || PATH=/sbin/.magisk/busybox:$PATH
21
- elif [ -d /sbin/.core/busybox ]; then
22
- [[ $PATH == /sbin/.core/busybox* ]] || PATH=/sbin/.core/busybox:$PATH
24
+ [[ $PATH == /sbin/.magisk/busybox:* ]] || PATH=/sbin/.magisk/busybox:$PATH
23
25
else
24
- [[ $PATH == /dev/.busybox* ]] || PATH=/dev/.busybox:$PATH
25
- if ! mkdir -m 700 /dev/.busybox 2> /dev/null; then
26
- if [ -x /data/adb/magisk/busybox ]; then
27
- /data/adb/magisk/busybox --install -s /dev/.busybox
28
- elif which busybox > /dev/null; then
26
+ mkdir -p -m 700 /dev/.busybox
27
+ [[ $PATH == /dev/.busybox:* ]] || PATH=/dev/.busybox:$PATH
28
+ if [ ! -x /dev/.busybox/busybox ]; then
29
+ if which busybox > /dev/null; then
29
30
busybox --install -s /dev/.busybox
31
+ elif [ -f /data/adb/busybox ]; then
32
+ chmod 700 /data/adb/busybox
33
+ /data/adb/busybox --install -s /dev/.busybox
30
34
else
31
35
echo " (!) Install busybox binary first"
32
36
exit 3
33
37
fi
34
38
fi
35
39
fi
40
+ # /BB#
36
41
37
42
# root check
38
43
if [ $( id -u) -ne 0 ]; then
43
48
print () { sed -n " s|^$1 =||p" ${2:- $srcDir / module.prop} ; }
44
49
45
50
set_perms () {
46
- local owner=${2:- 0} perms=0600 target=$( readlink -f $1 )
47
- if echo $target | grep -q ' .*\.sh$' || [ -d $target ]; then perms=0700 ; fi
51
+ local owner=${2:- 0} perms=600 target=$( readlink -f $1 )
52
+ if echo $target | grep -q ' .*\.sh$' || [ -d $target ]; then perms=700 ; fi
48
53
chmod $perms $target
49
54
chown $owner :$owner $target
50
55
restorecon $target > /dev/null 2>&1 || :
@@ -55,118 +60,135 @@ set_perms_recursive() {
55
60
find $1 2> /dev/null | while read target; do set_perms $target $owner ; done
56
61
}
57
62
58
- set -euo pipefail
63
+ set -euo pipefail 2> /dev/null || :
59
64
60
65
# set source code directory
61
66
[ -f $PWD /${0##*/ } ] && srcDir=$PWD || srcDir=${0%/* }
67
+ srcDir=${srcDir/# " ${0##*/ } " / " ." }
62
68
63
69
# unzip flashable zip if source code is unavailable
64
70
if [ ! -f $srcDir /module.prop ]; then
65
71
srcDir=/dev/.tmp
66
72
rm -rf $srcDir 2> /dev/null || :
67
73
mkdir $srcDir
68
- unzip -o ${ZIP:- ${3: - } } -d $srcDir / >&2
74
+ unzip ${ZIP:- ${3-} } -d $srcDir / >&2
69
75
fi
70
76
71
77
name=$( print name)
72
78
author=$( print author)
73
79
version=$( print version)
74
80
versionCode=$( print versionCode)
75
- installDir=${installDir0:-/ data/ data/ mattecarra.accapp/ files}
76
- config=/data/media/0/$id /${id} .conf
77
-
78
- # migrate/restore config
79
- [ -f $config ] || mv ${config%/* } /config.txt $config 2> /dev/null || :
80
- if [ -d ${config%/* } ] && [ ! -d /data/adb/${id} -data ]; then
81
- mv $config ${config%/* } /config.txt 2> /dev/null || :
82
- (cd /data/media/0; mv ${config%/* } ${id} -data
83
- tar -cf - ${id} -data | tar -xf - -C /data/adb)
84
- rm -rf ${id} -data
85
- fi
81
+ installDir=${installDir0:=/ data/ data/ mattecarra.accapp/ files}
86
82
config=/data/adb/${id} -data/config.txt
83
+
84
+ # restore config backup
87
85
[ -f $config ] || cp /data/media/0/.${id} -config-backup.txt $config 2> /dev/null || :
88
86
89
- configVer=$( print versionCode $config 2> /dev/null || :)
87
+ configVer=$( print configVerCode $config 2> /dev/null || :)
90
88
91
89
# check/set parent installation directory
92
90
[ -d $installDir ] || installDir=/sbin/.magisk/modules
93
- [ -d $installDir ] || installDir=/sbin/.core/img
94
91
[ -d $installDir ] || installDir=/data/adb
95
92
[ -d $installDir ] || { echo " (!) /data/adb/ not found\n" ; exit 1; }
96
93
97
94
95
+ # install
96
+
98
97
cat << EOF
99
98
$name $version
100
- Copyright (c) 2017-2019 , $author
99
+ Copyright (c) 2017-2020 , $author
101
100
License: GPLv3+
102
101
103
102
(i) Installing in $installDir /$id /...
104
103
EOF
105
104
105
+ /sbin/.acc-en --daemon stop > /dev/null 2>&1 || :
106
106
107
- (pkill -9 -f " /$id (-|--)|/${id} d.sh" ) || :
107
+ rm -rf $( readlink -f /sbin/.$id /$id || :) $installDir /$id \
108
+ /data/adb/$id /sbin/.magisk/modules/$id 2> /dev/null || :
108
109
109
- # install
110
- rm -rf $( readlink -f /sbin/.$id /$id ) $installDir /$id 2> /dev/null || :
111
110
cp -R $srcDir /$id / $installDir /
112
- installDir=$installDir /$id
113
- [ ${installDir0:- x} == x ] && installDir0=/data/data/mattecarra.accapp/files/$id || installDir0=$installDir0 /$id
111
+ installDir=$( readlink -f $installDir /$id )
112
+ installDir0=$installDir0 /$id
113
+ [ ! -d $installDir0 ] || installDir0=$( readlink -f $installDir0 )
114
114
cp $srcDir /module.prop $installDir /
115
115
116
116
mkdir -p ${config%/* } /info
117
117
cp -f $srcDir /* .md ${config%/* } /info
118
+ [ $installDir == /data/adb/$id ] || ln -s $installDir /data/adb/
118
119
119
- case $installDir in
120
- /data/adb/$id |$installDir0 )
121
- mv $installDir /service.sh $installDir /${id} -init.sh;;
122
- * )
123
- ln $installDir /service.sh $installDir /post-fs-data.sh;;
124
- esac
125
120
126
- # patch/upgrade config
121
+ if [ $installDir != /sbin/.magisk/modules/$id ]; then
122
+ mv $installDir /service.sh $installDir /${id} -init.sh
123
+
124
+ # enable upgrading through Magisk Manager
125
+ ln -s $installDir /sbin/.magisk/modules/$id 2> /dev/null || :
126
+
127
+ # set up alternate initializer (Magisk service.d)
128
+ cat << EOF > /data/adb/service.d/${id} -init.sh
129
+ #!/system/bin/sh
130
+ # alternate $id initializer
131
+ (until [ -d /storage/emulated/0/?ndroid ]; do sleep 10; done
132
+ if [ -f $installDir /${id} -init.sh ]; then
133
+ $installDir /${id} -init.sh
134
+ else
135
+ rm \$ 0
136
+ fi
137
+ exit 0 &) &
138
+ exit 0
139
+ EOF
140
+ chmod 700 /data/adb/service.d/${id} -init.sh
141
+
142
+ # set up cleanup script
143
+ cat << EOF > /data/adb/service.d/${id} -cleanup.sh
144
+ #!/system/bin/sh
145
+ # $id post-uninstall cleanup
146
+ (until [ -d /storage/emulated/0/?ndroid ]; do sleep 15; done
147
+ if [ ! -f $installDir /module.prop ]; then
148
+ rm /data/adb/$id /data/adb/${id} -data /data/adb/modules/$id \$ 0 2>/dev/null
149
+ fi
150
+ exit 0 &) &
151
+ exit 0
152
+ EOF
153
+ chmod 700 /data/adb/service.d/${id} -cleanup.sh
154
+ fi
155
+
156
+
157
+ touch /sbin/.magisk/modules/$id /skip_mount 2> /dev/null || :
158
+
159
+ # patch/reset config
127
160
if [ -f $config ]; then
128
- if [ ${configVer:- 0} -lt 201910130 ] \
129
- || [ ${configVer:- 0} -gt $( print versionCode $installDir /default-config.txt) ]
130
- then
131
- rm $config
132
- # else
133
- # if [ $configVer -lt 201906290 ]; then
134
- # echo prioritizeBattIdleMode=false >> $config
135
- # sed -i '/^versionCode=/s/=.*/=201906290/' $config
136
- # fi
137
- # if [ $configVer -lt 201907080 ]; then
138
- # sed -i '/^loopDelay=/s/=.*/=10,30/' $config
139
- # sed -i '/^versionCode=/s/=.*/=201907080/' $config
140
- # fi
141
- # if [ $configVer -lt 201907090 ]; then
142
- # sed -i '/^rebootOnUnplug=/d' $config
143
- # sed -i '/^versionCode=/s/=.*/=201907090/' $config
144
- # fi
145
- # if [ $configVer -lt 201909260 ]; then
146
- # sed -i '/^loopDelay=/s/,30/,15/' $config
147
- # sed -i '/^versionCode=/s/=.*/=201909260/' $config
148
- # fi
161
+ dConfVer=$( print configVerCode $installDir /default-config.txt)
162
+ if [[ ${configVer:- 0} -gt $dConfVer || ${configVer:- 0} -lt 202002220 ]]; then
163
+ rm $config /sdcard/acc-logs-* .tar.bz2 2> /dev/null || :
164
+ # else
165
+ # if [ $configVer -lt 201906290 ]; then
166
+ # echo prioritizeBattIdleMode=false >> $config
167
+ # sed -i '/^configVerCode=/s/=.*/=201906290/' $config
168
+ # fi
149
169
fi
170
+ unset dConfVer
150
171
fi
151
172
173
+ # flashable uninstaller
152
174
cp -f $srcDir /bin/${id} -uninstaller.zip /data/media/0/
153
175
154
176
# set perms
155
177
set_perms_recursive ${config%/* }
156
- chmod 0666 /data/media/0/${id} -uninstaller.zip
178
+ chmod 666 /data/media/0/${id} -uninstaller.zip
157
179
case $installDir in
158
180
/data/* /files/$id )
159
181
pkg=${installDir%/ files/ $id }
160
182
pkg=${pkg##/ data*/ }
161
- owner=$( grep $pkg /data/system/packages.list | awk ' {print $2} ' )
183
+ owner=$( grep $pkg /data/system/packages.list | cut -d ' ' -f 2 )
162
184
set_perms_recursive ${installDir%/* } $owner
163
185
;;
164
186
* )
165
187
set_perms_recursive $installDir
166
188
;;
167
189
esac
168
190
169
- set +euo pipefail
191
+ set +euo pipefail 2> /dev/null || :
170
192
171
193
172
194
cat << EOF
@@ -178,25 +200,26 @@ EOF
178
200
179
201
180
202
# print changelog
181
- tail -n +$( grep -n \( $versionCode \) ${config%/* } /info/README.md | cut -d: -f1) \
182
- ${config%/* } /info/README.md | sed ' s/^/ /'
203
+ sed -n " \|\($versionCode \)|,\$ s|^| |p" ${config%/* } /info/README.md
183
204
184
205
185
206
cat << EOF
186
207
187
208
LINKS
188
- - ACC app: github .com/MatteCarra/AccA/
209
+ - ACC app: GitHub .com/MatteCarra/AccA/
189
210
- Battery University: batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/
190
- - Donate: paypal.me/vr25xda/
191
- - Daily Job Scheduler: github.com/VR-25/djs/
192
- - Facebook page: facebook.com/VR25-at-xda-developers-258150974794782/
193
- - Git repository: github.com/VR-25/$id /
211
+ - Daily Job Scheduler: GitHub.com/VR-25/djs/
212
+ - Facebook page: fb.me/vr25xda/
213
+ - Git repository: GitHub.com/VR-25/$id /
214
+ - Liberapay: liberapay.com/VR25/
215
+ - Patreon: patreon.com/vr25/
216
+ - PayPal: paypal.me/vr25xda/
194
217
- Telegram channel: t.me/vr25_xda/
195
218
- Telegram group: t.me/${id} _group/
196
219
- Telegram profile: t.me/vr25xda/
197
220
- XDA thread: forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427/
198
221
199
- (i) Important info : https://bit.ly/2TRqRz0
222
+ (i) Power supply logs (help needed) : https://bit.ly/2TRqRz0
200
223
201
224
(i) Rebooting is unnecessary.
202
225
- $id can be used right now.
209
232
echo
210
233
trap - EXIT
211
234
235
+ # remove bootloop lock file
236
+ rm /data/adb/${id} -data/logs/.bootlooped 2> /dev/null
237
+
212
238
# initialize $id
213
239
if grep -q /storage/emulated /proc/mounts; then
214
240
if [ -f $installDir /service.sh ]; then
0 commit comments