forked from zgfg/ToyBox-Ext
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice.sh
More file actions
151 lines (132 loc) · 3.28 KB
/
service.sh
File metadata and controls
151 lines (132 loc) · 3.28 KB
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
#!/system/bin/sh
# Magisk Module: ToyBox-Ext v1.0.9
# Copyright (c) zgfg @ xda, 2022-
# GitHub source: https://github.com/zgfg/ToyBox-Ext
# Module's own path (local path)
MODDIR=${0%/*}
# Log file for debugging
LogFile="$MODDIR/service.log"
exec 3>&1 4>&2 2>$LogFile 1>&2
set -x
if [ -z $MODDIR ]
then
MODDIR=$(pwd)
fi
# Log info
date +%c
whoami
magisk -c
echo $APATCH
getprop ro.product.cpu.abi
getprop ro.product.cpu.abilist
# Log results for stock ToyBox
TB=toybox
$TB --version
TBBIN=$(which $TB)
ls -lZ $TBBIN
TBDIR=$(echo "$TBBIN" | sed "s,/$TB$,,")
TBEXT=toybox-ext
if [ -d $TBDIR ]
then
cd $TBDIR
pwd
ls -la | grep $TB | grep -v $TBEXT | grep ^lr.x | rev | cut -d ' ' -f 3 | rev
ls -la | grep $TB | grep -v $TBEXT | grep ^lr.x | wc -l
fi
# Log results for ToyBox-Ext
$TBEXT --version
TBEXTBIN=$(which $TBEXT)
ls -lZ $TBEXTBIN
TBEXTDIR=$(echo "$TBEXTBIN" | sed "s,/$TBEXT$,,")
if [ -d $TBEXTDIR ]
then
cd $TBEXTDIR
pwd
ls -la | grep $TBEXT | grep ^lr.x | rev | cut -d ' ' -f 3 | rev
ls -la | grep $TBEXT | grep ^lr.x | wc -l
if [ "$TBEXTDIR" != "$TBDIR" ]
then
ls -la | grep $TB | grep -v $TBEXT | grep ^lr.x | rev | cut -d ' ' -f 3 | rev
ls -la | grep $TB | grep -v $TBEXT | grep ^lr.x | wc -l
fi
fi
# Source the original toybox binary type and last download time
cd $MODDIR
pwd
LASTDLTIME=0
TBSCRIPT='./tbtype.sh'
if [ -f $TBSCRIPT ]
then
. $TBSCRIPT
fi
# Current time
DLTIME=$(date +"%s")
# Passed time since the last download
PASSEDTIME=$(($DLTIME - $LASTDLTIME))
# Waiting time between downloads (15 days)
WAITTIME=$((15 * 24 * 3600))
#WAITTIME=$((15 * 60)) # 15 min, for testing
# If waiting time passed, download the latest binary again
if [ -n $TBTYPE ] && [ $PASSEDTIME -gt $WAITTIME ]
then
# Wait to finish booting
until [ "$(getprop sys.boot_completed)" = 1 ]
do
sleep 1
done
# Wait few additional seconds
sleep 3
rm -f $TBTYPE
# Find busybox binary
BB=busybox
BBBIN=$(which $BB)
if [ -z $BBBIN ]
then
DATA=/data/adb
MODULES=$DATA/modules
for Path in $MODULES/BuiltIn-BusyBox/$BB $MODULES/busybox-ndk/system/*/$BB $DATA/magisk/$BB $DATA/ap/bin/$BB $DATA/ksu/bin/$BB
do
if [ -x $Path ]
then
BBBIN=$Path
break
fi
done
fi
# Download latest toybox binary
$BBBIN wget -c -T 20 "http://landley.net/toybox/bin/$TBTYPE"
fi
# Test the download
if [ -n $TBTYPE ] && [ -f $TBTYPE ]
then
# Compare checksums for the old and new binary
MD5Old=$(md5sum $TBEXT | head -c 32)
MD5New=$(md5sum "$TBTYPE" | head -c 32)
if [ "$MD5New" = "$MD5Old" ]
then
# Save the download time
echo "LASTDLTIME=$DLTIME" >> $TBSCRIPT
# Delete, same as old binary
rm -f $TBTYPE
else
# Test downloaded binary
chmod 755 $TBTYPE
Applets=$(./$TBTYPE)
if [ -z "$Applets" ]
then
# Delete, not working
rm -f $TBTYPE
else
# Save the binary type and installation time
echo "TBTYPE=$TBTYPE" > $TBSCRIPT
echo "LASTDLTIME=$DLTIME" >> $TBSCRIPT
# Notify user to reboot
Version=$(./$TBTYPE --version)
exec 1>&3 2>&4
su -lp 2000 -c "cmd notification post -S bigtext -t 'ToyBox-Ext Module' 'Tag' 'Reboot to update ToyBox binary to $Version'" 1>/dev/null
exec 3>&1 4>&2 2>>$LogFile 1>&2
fi
fi
fi
set +x
exec 1>&3 2>&4 3>&- 4>&-