forked from People-11/FuckGJZS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Util_Functions.sh
839 lines (759 loc) · 27.6 KB
/
Util_Functions.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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
#Custom variable
export Util_Functions_Code=2024051818
export SDdir=/data/media/0
export Modules_Dir=/data/adb/modules
export Script_Dir=$TMPDIR/tmp
export install_MOD=$ShellScript/Magisk_Module/install_Module_Script.sh
export install_Frame=$ShellScript/Geek/install_Frame_Script.sh
export Install_Method=$ShellScript/Geek/Installation_Check.sh
export APK_Name_list=$Data_Dir/APK_Name.log
export APK_Name_list2=$Data_Dir/APK_Name2.log
export jian="$Script_Dir/update-binary"
export jian2="$Script_Dir/updater-script"
export Frame_Dir=/data/misc/$Package_name
export Charging_control=/sys/class/power_supply/battery/input_suspend
export Charging_control2=/sys/class/power_supply/battery/charging_enabled
export Game_Toolbox_File=/data/data/com.miui.securitycenter/files/gamebooster/freeformlist
export Status=$Data_Dir/Status.log
export Termux=$DATA_DIR/com.termux/files
export BOOTMODE=true
export Choice=0
export New_Version=7.1.2
export New_Code=2023111016
export ChongQi Configuration File File_Name Download_File File_MD5 id name version versionCode author description MODID MODNAME MODPATH MAGISK_VER MAGISK_VER_CODE LOCKED
#Dynamic variable
export Time=`date '+%s'`
export ABI=`getprop ro.product.cpu.abi`
[[ -z "$ABI" ]] && export ABI=`getprop ro.product.cpu.abi2`
if [[ -f "$Data_Dir/GJZS_PATH" ]]; then
export GJZS=$(cat "$Data_Dir/GJZS_PATH")
else
export GJZS="$SD_PATH/Download/$Package_name"
fi
export lu=$GJZS/Batch_installation
export lu2=$GJZS/Add_Modules
export lu3=$GJZS/XianShua
#Function
mask() {
export Magisk=`$which magisk`
export MAGISKTMP=`$Magisk --path 2>/dev/null`
[[ -z "$MAGISKTMP" ]] && export MAGISKTMP=/sbin
if [[ "$1" == '-v' ]]; then
if [[ -x $Magisk ]]; then
MAGISK_VER=`$Magisk -v | sed 's/:.*//'`
MAGISK_VER_CODE=`$Magisk -V`
else
abort "未检测到Magisk,请确定已安装Magisk"
fi
elif [[ "$1" == '-vc' ]]; then
if [[ -x $Magisk ]]; then
MAGISK_VER=`$Magisk -v | sed 's/:.*//'`
MAGISK_VER_CODE=`$Magisk -V`
else
abort "未检测到Magisk,请确定已安装Magisk"
fi
if [[ -d $Modules_Dir ]]; then
echo "已安装Magisk版本:$MAGISK_VER($MAGISK_VER_CODE)"
[[ $MAGISK_VER_CODE -lt 19000 ]] && abort "未适配Magisk 19.0以下的版本,19.0以下版本采用magisk.img方式挂载模块"
echo "---------------------------------------------------------"
[[ `sh $ShellScript/support/Missing_file.sh` = 1 ]] && abort -e "已检测到Magisk需要修复运行环境\n缺失Magisk正常工作所需的文件,如果不修复您将无法使用模块功能,可在Magisk Manger里修复也可以在Magisk专区一键修复Magisk运行环境" || return 0
fi
elif [[ -n "$1" ]]; then
Module="$Modules_Dir/$1"
Module_XinXi="$Module/module.prop"
Module_S="$Module/post-fs-data.sh"
Module_S2="$Module/service.sh"
Module_us="$Module/uninstall.sh"
Module_prop="$Module/system.prop"
Module_Disable="$Module/disable"
Module_Remove="$Module/remove"
Module_Skip_Mount="$Module/skip_mount"
Module_Update="$Module/update"
if [[ -f $Module_XinXi ]]; then
version=`grep_prop version "$Module_XinXi"`
versionCode=`grep_prop versionCode "$Module_XinXi"`
fi
fi
}
adb() (
local ADB=`$which adb`
if [[ $# -eq 0 ]]; then
exec "$ADB"
fi
case "$1" in
help | --help | kill-server | start-server | reconnect | devices | keygen | tcpip | connect | disconnect | usb | wait-for-*)
exec "$ADB" "$@"
;;
-reset)
"$ADB" kill-server
exec "$ADB" start-server
esac
[[ -z `"$ADB" devices | egrep -vi 'List of.*'` ]] && error "无设备连接" && exit 126
exec "$ADB" "$@"
)
fastboot() (
local FASTBOOT=`$which fastboot`
if [[ $# -eq 0 ]]; then
exec "$FASTBOOT"
fi
case "$1" in
help | --help | -h | devices)
: ;;
*)
[[ -z `"$FASTBOOT" devices` ]] && error "无设备连接" && exit 126
;;
esac
exec "$FASTBOOT" "$@"
)
error() {
echo "$@" 1>&2
}
abort() {
error "$@"
exit 1
}
abort2() {
abort -e "$@\n\n错误代码:`cat $Status`"
}
show_progress() {
[[ -n $2 ]] && echo "Progress:[$1/$2]" || echo "Progress:[$1/100]"
}
adb2() {
if [[ "$#" -eq 0 ]]; then
adb shell
if [[ $? -ne 0 ]]; then
abort "没有设备连接"
fi
elif [[ "$1" = "-s" && "$#" -eq 2 ]]; then
shift
adb shell < "$1"
elif [[ "$1" = "-c" ]]; then
shift
adb shell "$@"
fi
}
adbsu() {
local a b
a=`adb shell su --help | grep '\-c'`
[[ -n "$a" ]] && b=true || b=false
if [[ "$#" -eq 0 ]]; then
adb shell su
elif [[ "$1" = "-s" && "$#" -eq 2 ]]; then
shift
adb shell su < "$1"
elif [[ "$1" = "-c" ]]; then
shift
$b && adb shell su -c \'"$@"\' || echo "Link@" | adb shell su
fi
}
Install_curl() {
curl -where &>/dev/null && return 0
unzip --help &>/dev/null || return 1
wget -where &>/dev/null || return 1
[[ ! -f $Load ]] && return 1
local jian jian2
. $Load curl
jian=$TMPDIR/curl.zip
jian2=$Script_Dir/META-INF/com/google/android/update-binary
[[ ! -f "$jian" ]] && abort "没有找到curl"
echo "- 开始安装curl"
rm -rf $Script_Dir
mkdir -p $Script_Dir
unzip -oq "$jian" 'META-INF/com/google/android/update-binary' -d $Script_Dir
if [[ -f "$jian2" ]]; then
sh "$jian2" $Package_name 1 "$jian"
PATH="$PATH"
else
abort "解压文件失败"
fi
rm -f $jian
}
Install_Applet() {
JCe="$PeiZhi_File/Applet_Installed.log"
[[ -f "$JCe" ]] && JCe3=`cat $JCe`
Start_Install2() {
Download "$@"
if [[ -f "$Download_File" ]]; then
[[ ! -d $ELF2_Path ]] && mkdir -p "$ELF2_Path" && chown $APP_USER_ID:$APP_USER_ID $ELF2_Path || rm -rf $ELF2_Path/*
unzip -oq "$Download_File" -d "$ELF2_Path"
if [[ $? = 0 ]]; then
echo "$versionCode" >$JCe
chmod -R 700 $ELF2_Path/*
chown -R $APP_USER_ID:$APP_USER_ID $ELF2_Path/*
case "$ABI" in
arm64*)
mv -f "$ELF2_Path/arm64/"* "$ELF2_Path"
;;
arm*)
mv -f "$ELF2_Path/arm/"* "$ELF2_Path"
;;
*)
echo "未知的架构 ${ABI},无法安装ADB & Fastboot"
rm -f "$ELF2_Path/adb"
[[ $ABI = x86* ]] && mv -f "$ELF2_Path/x86/"* "$ELF2_Path"
;;
esac
echo "- $name-$versionCode安装成功。"
rm -rf "$Download_File" $ELF2_Path/{arm,arm64,x86}
fi
fi
}
if [[ -z "$JCe3" || ! -f "$ELF2_Path/CQ" ]]; then
echo "- 开始安装$name-$versionCode"
Start_Install2 "$@"
elif [[ "$JCe3" -lt "$versionCode" ]]; then
echo "- 开始更新$name-$versionCode"
Start_Install2 "$@"
fi
}
Cloud_Update() {
local File S
File="$PeiZhi_File/Cloud.zip"
JCe="${PeiZhi_File}/Cloud_Version.log"
[[ -f "$JCe" ]] && JCe5=`cat "$JCe"`
unset S
if [[ -z "$JCe5" || ! -f "$Pages/Home.xml" ]]; then
S=初始化
elif [[ "$JCe5" -lt "$Cloud_Version" ]]; then
S=更新
fi
if [[ -n "$S" ]]; then
echo "- 正在$S云端页面:$Cloud_Version"
XiaZai -s "$CODING/$Cloud_ID" "$File"
if [[ -f "$File" ]]; then
Check_MD5=`md5sum "$File" 2>/dev/null | sed 's/ .*//g'`
if [[ "$Check_MD5" != "$Cloud_MD5" ]]; then
rm -f $File
abort2 "- 更新云端页面失败"
else
unzip -oq "$File" -d ~
if [[ $? = 0 ]]; then
echo "- $S云端页面成功"
echo "$Cloud_Version" >"$JCe"
find ~ -exec chmod 700 {} \; -exec chown $APP_USER_ID:$APP_USER_ID {} \; &
rm -f "$File"
else
echo "$S云端页面失败"
fi
fi
else
abort "未连接到网络"
fi
fi
}
Start_Installing_Busybox() {
JCe=$PeiZhi_File/busybox_Installed.log
[[ -f $JCe ]] && JCe2=`cat $JCe`
case "$ABI" in
arm64*) Type=arm64;;
arm*) Type=arm;;
x86_64*) Type=x86_64;;
x86*) Type=x86;;
mips64*) Type=mips64;;
mips*) Type=mips;;
*) echo "未知的架构 ${ABI},无法安装Busybox"; return 1;;
esac
Start_Install() { CloudBusybox="$8"; }
. "$Load" Install_busybox
Start_Install() {
Download "$@"
if [[ -f "$Download_File" ]]; then
BusyBox2=$ELF4_Path/busybox
[[ ! -d $ELF4_Path ]] && mkdir -p "$ELF4_Path" && chown $APP_USER_ID:$APP_USER_ID $ELF4_Path || rm -f $ELF4_Path/*
cp "$Download_File" "$BusyBox2" && chmod 700 $BusyBox2
echo "正在安装Busybox-$Type版-$7($8)"
"$BusyBox2" --install -s "$ELF4_Path" &>/dev/null
if [[ -L "$ELF4_Path/true" ]]; then
echo "Busybox-$Type版-$7($8)安装成功。"
echo "$8" >$JCe
chown $APP_USER_ID:$APP_USER_ID "$BusyBox2"
rm -f $Download_File
else
echo "Busybox安装失败"
rm -f "$BusyBox2"
fi
fi
}
if [[ -z "$JCe2" || ! -L $ELF4_Path/true ]]; then
echo "- 开始安装Busybox"
. "$Load" Install_busybox
elif [[ "$JCe2" -lt "$CloudBusybox" ]]; then
echo "- 开始更新Busybox"
. "$Load" Install_busybox
fi
}
Installing_Busybox() {
Install_curl
Start_Installing_Busybox
. $Load Install_Applet
[[ ! -d $lu ]] && mkdir -p $lu &>/dev/null
[[ ! -d $lu2 ]] && mkdir -p $lu2 &>/dev/null
[[ ! -d $lu3 ]] && mkdir -p $lu3 &>/dev/null
Cloud_Update
}
Start_Time() {
Start_ns=`date +'%s%N'`
}
End_Time() {
#小时、分钟、秒、毫秒、纳秒
local h min s ms ns End_ns time ms1 ms2
End_ns=`date +'%s%N'`
time=`expr $End_ns - $Start_ns`
[[ -z "$time" ]] && return 0
ns=${time:0-9}
s=${time%$ns}
ms1=`expr $ns / 1000000`
ms2=`expr $ns % 1000000`
[[ -n "$ms2" ]] && ms=$ms1.$ms2 || ms=$ms1
if [[ $s -ge 3600 ]]; then
h=`expr $s / 3600`
h=`expr $s % 3600`
if [[ $s -ge 60 ]]; then
min=`expr $s / 60`
s=`expr $s % 60`
fi
echo "- 本次$1用时:$h小时$min分钟$s秒$ms毫秒"
elif [[ $s -ge 60 ]]; then
min=`expr $s / 60`
s=`expr $s % 60`
echo "- 本次$1用时:$min分钟$s秒$ms毫秒"
elif [[ -n $s ]]; then
echo "- 本次$1用时:$s秒$ms毫秒"
else
echo "- 本次$1用时:$ms毫秒"
fi
}
CURL() {
local v=`getprop ro.build.version.release`
local model="`getprop ro.product.model`"
[[ -z "$v" ]] && v=10
[[ -z "$model" ]] && model='Redmi K30 5G'
curl -LA "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" -H "Referer: https://sharewh1.xuexi365.com/" "$@"
}
WGET() {
local v=`getprop ro.build.version.release`
local model="`getprop ro.product.model`"
[[ -z "$v" ]] && v=10
[[ -z "$model" ]] && model='Redmi K30 5G'
wget -LU "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36" "$@"
}
XiaZai() {
local code
echo none >"$Status"
if [[ "$#" -lt 3 ]]; then
echo 2 >"$Status"
abort "!没有参数无法下载"
fi
local dir
dir=${3%/*}
if [[ ! -d "$dir" ]]; then
echo 2 >"$Status"
abort "!No such \"$dir\" directory"
fi
CURL $1 -C - -o "$3" -w "- HTTP状态码:%{http_code}\n" -kL "$2"
code=$?
echo "$code" >"$Status"
[[ $code -eq 6 ]] && error "未连接到互联网"
[[ $code -ne 0 ]] && error "错误代码:$code"
}
EndMD5() {
md5_down=`md5sum "$Download_File" | sed 's/ .*//g'`
if [[ "$File_MD5" != "$md5_down" ]]; then
Deleting_file
abort2 "! ["$File_Name"] MD5校验失败,如果一直无法下载请刷新云端状态后重试"
else
echo "- ["$File_Name"]文件MD5校验成功"
echo "- MD5=$md5_down"
return 0
fi
}
Start_Download() {
Check_command2() {
$1 -where &>/dev/null
return $?
}
local Download_File2 File_Type YiXZ YiXZ_2 YiXZ_SuDu Remaining_Time Percentage Size2 md5_down code
Download_File2="$2"
if Check_command2 awk && Check_command2 wc && Check_command2 md5sum; then
Start_Time
XiaZai -s "$@" &
code=`cat "$Status"`
[[ $code = 2 || $code = 6 ]] && abort
until [[ -f "$Download_File2" ]]; do
[[ `cat "$Status"` != none ]] && break
done
echo "连接服务器成功"
if [[ $File_Size -ge 1048576 ]]; then
File_Type=`awk "BEGIN{print $File_Size/1048576}"`MB
elif [[ $File_Size -ge 1024 ]]; then
File_Type=`awk "BEGIN{print $File_Size/1024}"`KB
elif [[ $File_Size -le 1024 ]]; then
File_Type=${File_Size}B
fi
echo "正在下载 [$File_Name2],文件总大小:${File_Type}"
echo -e "\n-----------------------------------------"
[[ `cat "$Status"` != none ]] && End_Time 下载 && EndMD5
until [[ $code != none ]]; do
YiXZ=`ls -l "$Download_File2" | awk '{print $5}'`
sleep 0.2
YiXZ_2=`ls -l "$Download_File2" | awk '{print $5}'`
if [[ $YiXZ -gt 0 ]]; then
YiXZ_SuDu=`awk "BEGIN{print ($YiXZ_2-$YiXZ)*5}"`
Remaining_Time=`awk "BEGIN{print ($File_Size-$YiXZ_2)/$YiXZ_SuDu}" 2>/dev/null`
Percentage=`awk "BEGIN{print $YiXZ_2/($File_Size/100)}" 2>/dev/null`
#show_progress ${Percentage%.*}
if [[ $YiXZ_2 -ge 1048576 ]]; then
Size2=`awk "BEGIN{print $YiXZ_2/1048576}"`MB
elif [[ $YiXZ_2 -ge 1024 ]]; then
Size2=`awk "BEGIN{print $YiXZ_2/1024}"`KB
elif [[ $YiXZ_2 -le 1024 ]]; then
Size2=${YiXZ_2}b
fi
Schedule() { echo "- 已下载:${Size2}/$File_Type 已完成:${Percentage}%" ; echo "-----------------------------------------"; }
if [[ $YiXZ_SuDu -ge 1048576 ]]; then
echo -n "- 正在下载:`awk "BEGIN{print $YiXZ_SuDu/1048576}"`MB/s"; echo " 剩余时间:${Remaining_Time}s"; Schedule
elif [[ $YiXZ_SuDu -ge 1024 ]]; then
echo -n "- 正在下载:`awk "BEGIN{print $YiXZ_SuDu/1024}"`KB/s"; echo " 剩余时间:${Remaining_Time}s"; Schedule
elif [[ $YiXZ_SuDu -lt 1024 && $YiXZ_SuDu -gt 0 ]]; then
echo -n "- 正在下载:${YiXZ_SuDu}B/s"; echo " 剩余时间:${Remaining_Time}s"; Schedule
elif [[ $YiXZ_SuDu -eq 0 ]]; then
code=`cat "$Status"`
if [[ $code = 0 ]]; then
[[ $Options = -split ]] && break
echo "下载完成,开始MD5校验"
End_Time 下载
EndMD5
else
Schedule
fi
fi
fi
done
else
echo "正在下载 [$File_Name2]配置文件……文件总大小:${File_Size}b"
Start_Time
XiaZai -# "$@"
End_Time 下载
EndMD5
fi
}
parse_download_url() {
local html_content="$1"
local download_url=$(echo "$html_content" | grep 'var downloadUrl =' | awk -F"'" '{print $2}')
echo "$download_url"
}
Download() {
if [[ "$#" -lt 5 ]]; then
abort "没有参数无法提供下载"
fi
Deleting_file() {
rm -rf "$PeiZhi_File/$Delete"*
}
MD5() {
if [[ -f "$Download_File" ]]; then
md5_down=`md5sum "$Download_File" | sed 's/ .*//g'`
if [[ "$File_MD5" != "$md5_down" ]]; then
Deleting_file
echo "文件已升级正在重新下载"
return 1
else
return 0
fi
else
Deleting_file
echo "正在连接服务器"
return 1
fi
}
local Han Options ID File_Name2 File_Size Delete split_size Total_size n size xsize PeiZhi_File0
Han=0
Options="$1"
ID="$2"
case "$Options" in
-url)
shift
Link="$ID"
;;
-net)
shift
Link="https://bincat-my.sharepoint.com/personal/people11_bincat_onmicrosoft_com/_layouts/52/download.aspx?share=$ID"
;;
-chaoxing)
shift
Link="https://sharewh1.xuexi365.com/share/download/$ID"
# Fetch the HTML content
html_content=$(curl -s "$Link")
# Parse the download URL
Link=$(parse_download_url "$html_content")
;;
*)
abort "暂不支持下载"
;;
esac
File_Name="$2"
File_Size="$3"
File_MD5="$4"
Delete="$5"
Download_File="$PeiZhi_File/$File_Name"
MD5
[[ $? -eq 0 ]] && return 0
File_Name2="$File_Name"
Start_Download "$Link" "$Download_File"
}
Mount_Write() {
GZai=$1
Result=1
echo "开始使用`which mount`挂载$2可读写$3"
mount -o rw,remount $GZai
if [[ -w /$2 ]]; then
system=/system
vendor=/vendor
Result=0
return 0
elif [[ -w "$GZai" ]]; then
Result=0
if [[ "$GZai" = / ]]; then
unset GZai
elif [[ "$GZai" = $MAGISKTMP/.magisk/mirror/system_root ]]; then
if [[ -w "$GZai/system" ]]; then
GZai="$GZai/system"
Result=0
else
unset GZai
Result=1
return 1
fi
fi
return 0
fi
echo "开始使用`busybox -where` mount挂载$2可读写$3"
echo
busybox mount -o rw,remount $GZai
if [[ -w /$2 ]]; then
system=/system
vendor=/vendor
Result=0
return 0
elif [[ -w "$GZai" ]]; then
Result=0
if [[ "$GZai" = / ]]; then
unset GZai
elif [[ "$GZai" = $MAGISKTMP/.magisk/mirror/system_root ]]; then
if [[ -w "$GZai/system" ]]; then
GZai=$GZai/system
Result=0
else
unset GZai
Result=1
return 1
fi
fi
else
unset GZai
Result=1
return 1
fi
}
Check_Mount() {
[[ "$Result" -eq 0 ]] && echo "挂载$1读写成功。"
if [[ "$Result" -eq 1 ]]; then
error "!您的`getprop ro.product.model`(Android `getprop ro.build.version.release`)设备未解锁System"
echo -e "\n\n错误详情:\n"
mount | grep -m 1 /system 1>&2
abort
fi
}
Mount_system() {
mask
Mount_Write /system system . 2>/dev/null
if [[ $? -eq 1 ]]; then
Mount_Write $MAGISKTMP/.magisk/mirror/system system .. 2>/dev/null
if [[ $? -eq 1 ]]; then
Mount_Write $MAGISKTMP/.magisk/mirror/system_root system ... 2>/dev/null
if [[ $? -eq 1 ]]; then
Mount_Write / system .... 2>/dev/null
fi
fi
fi
export system=${GZai:-/system}
export audio="$system/media/audio/ui"
Check_Mount system
Unload(){
mount -o ro,remount "$GZai" &>/dev/null
[[ -w "$GZai" ]] && busybox mount -o ro,remount "$GZai" &>/dev/null
#umount -r $GZai
}
}
Mount_vendor() {
mask
Mount_Write /vendor vendor . 2>/dev/null
if [[ $? -eq 1 ]]; then
Mount_Write $MAGISKTMP/.magisk/mirror/vendor vendor .. 2>/dev/null
if [[ $? -eq 1 ]]; then
Mount_Write / vendor ... 2>/dev/null
fi
fi
export vendor=${GZai:-/vendor}
Check_Mount vendor
Unload_vendor(){
mount -o ro,remount "$GZai" &>/dev/null
[[ ! -w "$GZai" ]] && busybox mount -o ro,remount "$GZai" &>/dev/null
#umount -r $GZai
}
}
grep_prop() {
local J="s/^$1=//p"
[[ -z "$2" ]] && { getprop $1; return $?; }
[[ -f "$2" ]] && sed -n "$J" $2 2>/dev/null | head -n 1 || return 2
}
mkdir() {
umask 022
`$which mkdir` "$@"
}
touch() {
umask 022
`$which touch` "$@"
}
set_perm() {
chown $2:$3 $1 || return 1
chmod $4 $1 || return 1
CON=$5
[ -z $CON ] && CON=u:object_r:system_file:s0
chcon $CON $1 || return 1
}
set_perm_recursive() {
find $1 -type d 2>/dev/null | while read dir; do
set_perm $dir $2 $3 $4 $6
done
find $1 -type f -o -type l 2>/dev/null | while read file; do
set_perm $file $2 $3 $5 $6
done
}
mktouch() {
mkdir -p ${1%/*} 2>/dev/null
[[ -z $2 ]] && touch "$1" || echo "$2" > "$1"
chmod 644 "$1"
}
Write_Record() {
local system=${system%/*}
local jian=$MODPATH/Write_Record.sh
cd $MODPATH
for c in `find system`; do
[[ -d "$c" ]] && continue
if [[ -f "$system/$c" ]]; then
#Original_file
echo "$c文件存在源文件开始备份"
dir=`dirname "$c"`
mkdir -p "$MODPATH/Original_file/$dir"
cp -arf "$system/$c" "$MODPATH/Original_file/$dir"
else
#Add_file
echo "$system/$c文件属于新添加文件开始写入记录"
echo "rm -f \$$c" >>$jian
fi
done
}
Inject_prop() {
if [[ -f "$MODPATH/system.prop" ]]; then
grep '^[^#]' "$MODPATH/system.prop" | while read i; do
if ! grep -q ^"$i"$ "$system/build.prop"; then
echo "$i" >>"$system/build.prop"
echo "$i" >>"$MODPATH/build.prop"
fi
done
fi
}
Delete_prop() {
if [[ -f "$MODPATH/build.prop" ]]; then
cat "$MODPATH/build.prop" | while read i; do
sed -i "/"$i"/d" "$system/build.prop"
done
fi
}
End_installation() {
lu="$MODPATH/system"
Inject_prop
case "$MODID" in
riru_edxposed | riru_edxposed_sandhook)
echo "- 已跳过模块启动脚本"
;;
*)
[[ -f "$MODPATH/service.sh" ]] && sh "$MODPATH/service.sh" &>/dev/null
[[ -f "$MODPATH/post-fs-data.sh" ]] && sh "$MODPATH/post-fs-data.sh" &>/dev/null
;;
esac
[[ ! -d "$lu" ]] && ls "$MODPATH" >"$Status" && abort2 "\n! "$MODNAME"安装失败"
Write_Record
cp -arf "$lu"/* "$system"
[[ $? = 0 ]] && echo "- "$MODNAME"安装成功" && rm -rf "$lu" || abort "!$MODNAME安装失败"
Unload
if [[ -f "$MODPATH/module.prop" ]]; then
echo "THE END"
[[ "$Result" = 0 ]] && CQ
else
abort "未在框架目录里找到module.prop"
fi
}
check_ab_device() {
. $ShellScript/Block_Device_Name.sh | egrep -q 'boot_a|boot_b'
return $?
}
set_Game_Toolbox() {
am force-stop com.miui.securitycenter
set_perm /data/data/com.miui.securitycenter/files/gamebooster system system 700
set_perm "$Game_Toolbox_File" system system 444
echo "将在下次启动游戏时立即生效,不需要重启手机哦"
}
Check_Riru() {
No_Riru() {
error "*********************************************************"
error "未安装Riru - Core框架"
abort "*********************************************************"
}
if [[ ! -f "/data/misc/riru/api_version" && ! -f "/data/misc/riru/api_version.new" ]]; then
No_Riru
fi
}
Frame_installation_Check() {
if [[ -d "$Modules_Dir/$MODID" ]]; then
abort -e "已检测到用Magisk模块方式安装了$MODID,无法再次安装\n模块安装目录:\"$Modules_Dir/$MODID\""
fi
}
Play_Music() {
am start -n $Package_name/com.projectkr.shell.MusicPlayer --es music "$1" 1>/dev/null
}
Power() {
echo "`cat /sys/class/power_supply/battery/capacity 2>/dev/null`%"
}
module_prop() {
echo "- 正在打印模块信息……"
cat <<Han >$Module_XinXi
id=$id
name=$name
version=$version
versionCode=$versionCode
author=$author
description=$description
Han
}
Clean_install() {
[[ -z "$id" ]] && abort"未设置id"
mask $id
rm -rf $Module
mkdir -p $Module
ui_print "- 开始安装 $name-$version($versionCode)"
ui_print "- 安装目录:$Module"
ui_print "- 模块作者:$author"
ui_print "- Powered by Magisk & topjohnwu"
abort() {
rm -rf $Module
error "$@"
exit 1
}
}
man() {
URL="https://gitee.com/youngdriver/command_help/raw/master"
COMMAND=`curl -sL "${URL}/help_list" | sed -n "/^$1$/p"`
[[ $COMMAND ]] || (echo "命令 [ $1 ] 不存在中文帮助,检查是否输入有误或联系管理员解决" && exit 1)
curl -sL $URL/$COMMAND
}