forked from atcha9035/Magic-Charging-Switch
-
Notifications
You must be signed in to change notification settings - Fork 4
/
config.sh
361 lines (298 loc) · 10.8 KB
/
config.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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
##########################################################################################
#
# Magisk Module Template Config Script
# by topjohnwu
#
##########################################################################################
##########################################################################################
#
# Instructions:
#
# 1. Place your files into system folder (delete the placeholder file)
# 2. Fill in your module's info into module.prop
# 3. Configure the settings in this file (config.sh)
# 4. If you need boot scripts, add them into common/post-fs-data.sh or common/service.sh
# 5. Add your additional or modified system properties into common/system.prop
#
##########################################################################################
##########################################################################################
# Configs
##########################################################################################
# Set to true if you need to enable Magic Mount
# Most mods would like it to be enabled
AUTOMOUNT=true
# Set to true if you need to load system.prop
PROPFILE=false
# Set to true if you need post-fs-data script
POSTFSDATA=false
# Set to true if you need late_start service script
LATESTARTSERVICE=true
##########################################################################################
# Installation Message
##########################################################################################
# Set what you want to show when installing your mod
print_modname() {
ui_print " "
ui_print "$(i name) $(i version)"
ui_print "$(i author)"
ui_print " "
}
##########################################################################################
# Replace list
##########################################################################################
# List all directories you want to directly replace in the system
# Check the documentations for more info about how Magic Mount works, and why you need this
# This is an example
REPLACE="
/system/app/Youtube
/system/priv-app/SystemUI
/system/priv-app/Settings
/system/framework
"
# Construct your own list here, it will override the example above
# !DO NOT! remove this if you don't need to replace anything, leave it empty as it is now
REPLACE="
"
##########################################################################################
# Permissions
##########################################################################################
set_permissions() {
# Only some special files require specific permissions
# The default permissions should be good enough for most cases
# Here are some examples for the set_perm functions:
# set_perm_recursive <dirname> <owner> <group> <dirpermission> <filepermission> <contexts> (default: u:object_r:system_file:s0)
# set_perm_recursive $MODPATH/system/lib 0 0 0755 0644
# set_perm <filename> <owner> <group> <permission> <contexts> (default: u:object_r:system_file:s0)
# set_perm $MODPATH/system/bin/app_process32 0 2000 0755 u:object_r:zygote_exec:s0
# set_perm $MODPATH/system/bin/dex2oat 0 2000 0755 u:object_r:dex2oat_exec:s0
# set_perm $MODPATH/system/lib/libart.so 0 0 0644
# The following is default permissions, DO NOT remove
set_perm_recursive $MODPATH 0 0 0755 0644
# Permissions for executables
for f in $MODPATH/bin/* $MODPATH/system/*bin/* $MODPATH/*.sh; do
[ -f "$f" ] && set_perm $f 0 0 0755
done
}
##########################################################################################
# Custom Functions
##########################################################################################
# This file (config.sh) will be sourced by the main flash script after util_functions.sh
# If you need custom logic, please add them here as functions, and call these functions in
# update-binary. Refrain from adding code directly into update-binary, as it will make it
# difficult for you to migrate your modules to newer template versions.
# Make update-binary as clean as possible, try to only do function calls in it.
install_module() {
umask 000
set -euxo pipefail
trap debug_exit EXIT
config=/data/media/0/$MODID/config.txt
# magisk.img mount path
if $BOOTMODE; then
MOUNTPATH0=/sbin/.magisk/img
[ -e $MOUNTPATH0 ] || MOUNTPATH0=/sbin/.core/img
if [ ! -e $MOUNTPATH0 ]; then
ui_print " "
ui_print "(!) \$MOUNTPATH0 未找到"
ui_print " "
exit 1
fi
else
MOUNTPATH0=$MOUNTPATH
fi
curVer=$(grep_prop versionCode $MOUNTPATH0/$MODID/module.prop || :)
[ -z "$curVer" ] && curVer=0
if [ $curVer -eq $(i versionCode) ] && ! $BOOTMODE; then
touch $MODPATH/disable
ui_print " "
ui_print "(i) 模块已禁用"
ui_print " "
set +euo pipefail
unmount_magisk_img
$BOOTMODE || recovery_cleanup
set -u
rm -rf $TMPDIR
exit 0
fi
# cleanup & create module paths
cleanup
rm -rf $MODPATH 2>/dev/null || :
mkdir -p ${config%/*}/info ${config%/*}/logs
[ -d /system/xbin ] && mkdir -p $MODPATH/system/xbin \
|| mkdir -p $MODPATH/system/bin
# remove legacy (mcs)
rm -rf /data/media/mcs 2>/dev/null || :
touch $MOUNTPATH0/mcs/remove 2>/dev/null || :
# extract module files
ui_print "- Extracting module files"
cd $INSTALLER
unzip -o "$ZIP" -x common/addon.d.sh -d ./ >&2
mv common/$MODID $MODPATH/system/*bin/
mv common/* $MODPATH/
rm $MODPATH/addon.d.sh
cp -f $MODPATH/service.sh $(echo -n $MODPATH/system/*bin)/accd
$LATESTARTSERVICE && LATESTARTSERVICE=false \
|| rm $MODPATH/service.sh
mv -f License* README* ${config%/*}/info/
[ -f $config ] || cp $MODPATH/default_config.txt $config
set +euxo pipefail
ui_print "- [Background] Generating ${config%/*}/logs/acc-power_supply-$(getprop ro.product.device | grep .. || getprop ro.build.product).log"
(debug &) &
}
install_system() {
umask 000
set -euxo pipefail
trap debug_exit EXIT
local modId=acc
local modPath=/system/etc/$modId
config=/data/media/0/$modId/config.txt
grep_prop() {
local REGEX="s/^$1=//p"
shift
local FILES=$@
[ -z "$FILES" ] && FILES='/system/build.prop'
sed -n "$REGEX" $FILES 2>/dev/null | head -n 1
}
set_perm() {
chown 0:0 "$@"
chmod 0755 "$@"
}
mount -o rw /system 2>/dev/null || mount -o remount,rw /system
curVer=$(grep_prop versionCode $modPath/module.prop || :)
[ -z "$curVer" ] && curVer=0
# set OUTFD
if [ -z $OUTFD ] || readlink /proc/$$/fd/$OUTFD | grep -q /tmp; then
for FD in `ls /proc/$$/fd`; do
if readlink /proc/$$/fd/$FD | grep -q pipe; then
if ps | grep -v grep | grep -q " 3 $FD "; then
OUTFD=$FD
break
fi
fi
done
fi
ui_print() { echo -e "ui_print $1\nui_print" >> /proc/self/fd/$OUTFD; }
print_modname
# uninstall
if [ $curVer -eq $(i versionCode) ]; then
ui_print "(i) 卸载中"
rm -rf /system/etc/init.d/$modId* \
/system/etc/$modId \
/system/addon.d/$modId* \
/system/*bin/$modId* 2>/dev/null || :
ui_print " "
else
# cleanup & create paths
cleanup
mkdir -p $modPath
mkdir -p ${config%/*}/info ${config%/*}/logs
# remove legacy (mcs)
rm -rf /system/etc/init.d/mcs* \
/system/etc/mcs \
/system/addon.d/mcs* \
/system/*bin/mcs* \
/data/media/mcs 2>/dev/null || :
# install
ui_print "- 安装中"
cd $INSTALLER
unzip -o "$ZIP" -d ./ >&2
mv -f common/service.sh $modPath/autorun.sh
set_perm $modPath/autorun.sh
if [ -d /system/xbin ]; then
mv -f common/$modId /system/xbin/
ln -sf $modPath/autorun.sh /system/xbin/accd
else
mv -f common/$modId /system/bin/
ln -sf $modPath/autorun.sh /system/bin/accd
fi
set_perm /system/*bin/$modId
[ -e /system/etc/init.d ] && $LATESTARTSERVICE \ && ln -sf $modPath/autorun.sh /system/etc/init.d/$modId || :
if [ -e /system/addon.d ]; then
mv -f common/addon.d.sh /system/addon.d/$modId.sh
set_perm /system/addon.d/$modId.sh
fi
mv -f common/* module.prop $modPath/
set_perm $modPath/accd
mv -f License* README* ${config%/*}/info/
[ -f $config ] || cp $modPath/default_config.txt $config
set +euxo pipefail
ui_print "- [Background] Generating ${config%/*}/logs/acc-power_supply-$(getprop ro.product.device | grep .. || getprop ro.build.product).log"
(debug &) &
MAGISK_VER=0
version_info
fi
exit 0
}
debug() {
local target=""
date
echo "Version code: $(i versionCode)"
echo; echo
for target in $(find /sys /proc 2>/dev/null | grep -Ei 'batt|ch.*rg|power_supply'); do
if [ -f $target ]; then
echo $target
sed 's/^/ /' $target 2>/dev/null
echo
fi
done 2>/dev/null
echo
getprop | grep product
echo
getprop | grep version
} >${config%/*}/logs/acc-power_supply-$(getprop ro.product.device | grep . || getprop ro.build.product).log
debug_exit() {
local exitCode=$?
echo -e "\n***EXIT $exitCode***\n"
set +euxo pipefail
set
echo
echo "SELinux status: $(getenforce 2>/dev/null || sestatus 2>/dev/null)" \
| sed 's/En/en/;s/Pe/pe/'
if [ $e -ne 0 ]; then
unmount_magisk_img
$BOOTMODE || recovery_cleanup
set -u
rm -rf $TMPDIR
fi 1>/dev/null 2>&1
echo
exit $exitCode
} 1>&2
# module.prop reader
i() {
local p=$INSTALLER/module.prop
[ -f $p ] || p=$MODPATH/module.prop
grep_prop $1 $p
}
cleanup() {
if [ $curVer -lt 201901090 ] || [ $curVer -gt $(i versionCode) ]; then
rm -rf /data/media/0/acc 2>/dev/null || :
fi
}
version_info() {
local line=""
local println=false
# a note on untested Magisk versions
if [ ${MAGISK_VER/.} -gt 180 ]; then
ui_print " "
ui_print " (!) 这个Magisk版本尚未经过@VR25测试 "
ui_print " - 如果您遇到任何问题,请报告。"
fi
ui_print " "
ui_print " WHAT'S NEW"
cat ${config%/*}/info/README.md | while read line; do
echo "$line" | grep -q '\*\*.*\(.*\)\*\*' && println=true
$println && echo "$line" | grep -q '^$' && break
$println && echo " $line" | grep -v '\*\*.*\(.*\)\*\*'
done
ui_print " "
ui_print " LINKS"
ui_print " - Battery University: batteryuniversity.com/learn/article/how_to_prolong_lithium_based_batteries/"
ui_print " - Facebook page: facebook.com/VR25-at-xda-developers-258150974794782/"
ui_print " - Git repository: github.com/Magisk-Modules-Repo/acc/"
ui_print " - Telegram channel: t.me/vr25_xda/"
ui_print " - Telegram profile: t.me/vr25xda/"
ui_print " - XDA thread: forum.xda-developers.com/apps/magisk/module-magic-charging-switch-cs-v2017-9-t3668427/"
ui_print " "
ui_print "(i) 您现在可以关闭它,但在重新启动之前,请等待至少一两分钟以完成后台作业。"
ui_print " "
}
acc --daemon stop 1>/dev/null 2>&1