-
Notifications
You must be signed in to change notification settings - Fork 23
/
install.sh
226 lines (166 loc) · 6.63 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
#!/data/data/com.termux/files/usr/bin/bash
echo
if [ ! -d "$HOME/storage" ]; then
echo -e "\nGrant permission: termux-setup-storage\nThen rerun the command.\n"
exit 1
fi
if [ ! -d "/data/data/com.termux.api" ]; then
echo -e "\ncom.termux.api app is not installed\nPlease install it first\n"
exit 1
fi
arch=$(dpkg --print-architecture)
if [[ "$arch" != "aarch64" && "$arch" != "arm" ]]; then
echo "MiTool does not support architecture $arch"
exit 1
fi
mitoolusers="$PREFIX/bin/.mitoolusersok"
miunlockusers="$PREFIX/bin/.miunlockusersok"
if [ ! -f "$mitoolusers" ]; then
if [ ! -f "$miunlockusers" ]; then
echo -ne "\rapt upgrade ..."
apt upgrade > /dev/null 2> >(grep -v "apt does not have a stable CLI interface")
fi
curl -Is https://github.com/offici5l/MiTool/releases/download/tracking/totalusers> /dev/null 2>&1
touch "$mitoolusers"
fi
echo -ne "\rurl check ..."
main_repo=$(grep -E '^deb ' /data/data/com.termux/files/usr/etc/apt/sources.list | awk '{print $2}' | head -n 1)
curl -s --retry 4 $main_repo > /dev/null
exit_code=$?
if [ $exit_code -eq 6 ]; then
echo -e "\nRequest to $main_repo failed. Please check your internet connection.\n"
exit 6
elif [ $exit_code -eq 35 ]; then
echo -e "\nThe $main_repo is blocked in your current country.\n"
exit 35
fi
git_repo="https://raw.githubusercontent.com"
curl -s --retry 4 $git_repo > /dev/null
exit_code=$?
if [ $exit_code -eq 6 ]; then
echo -e "\nRequest to $git_repo failed. Please check your internet connection.\n"
exit 6
elif [ $exit_code -eq 35 ]; then
echo -e "\nThe $git_repo is blocked in your current country.\n"
exit 35
fi
echo -ne "\rapt update ..."
apt update > /dev/null 2> >(grep -v "apt does not have a stable CLI interface")
charit=-1
total=31
start_time=$(date +%s)
_progress() {
charit=$((charit + 1))
percentage=$((charit * 100 / total))
echo -ne "\rProgress: $charit/$total ($percentage%)"
if [ $percentage -eq 100 ]; then
end_time=$(date +%s)
elapsed_time=$((end_time - start_time))
echo -ne "\rProgress: $charit/$total ($percentage%) Took: $elapsed_time seconds"
else
echo -ne "\rProgress: $charit/$total ($percentage%)"
fi
}
_progress
url="https://raw.githubusercontent.com/nohajc/nohajc.github.io/master/dists/termux/extras/binary-${arch}"
get_version() {
package_name="$1"
local __resultvar=$2
version=$(curl -s "$url/Packages" | awk -v package="$package_name" '
$0 ~ "^Package: " package {found=1}
found && /^Version:/ {print $2; exit}
')
eval $__resultvar="'$version'"
}
libprotobuf_version_c=""
termux_adb_version_c=""
get_version "libprotobuf-tadb-core" libprotobuf_version_c
get_version "termux-adb" termux_adb_version_c
libprotobuf_version_i=$(pkg show libprotobuf-tadb-core 2>/dev/null | grep Version | cut -d ' ' -f 2)
termux_adb_version_i=$(pkg show termux-adb 2>/dev/null | grep Version | cut -d ' ' -f 2)
# Function to compare versions without printing anything if the package is already updated
compare_versions() {
package_name="$1"
available_version="$2"
installed_version="$3"
if [ "$installed_version" != "$available_version" ]; then
curl -s -O "$url/${package_name}_${available_version}_${arch}.deb"
dpkg --force-overwrite -i "${package_name}_${available_version}_${arch}.deb" >/dev/null 2>&1
rm -f "${package_name}_${available_version}_${arch}.deb"
fi
_progress
}
compare_versions "libprotobuf-tadb-core" "$libprotobuf_version_c" "$libprotobuf_version_i"
compare_versions "termux-adb" "$termux_adb_version_c" "$termux_adb_version_i"
ln -sf "$PREFIX/bin/termux-fastboot" "$PREFIX/bin/fastboot" && ln -sf "$PREFIX/bin/termux-adb" "$PREFIX/bin/adb"
packages=(
"libffi"
"abseil-cpp"
"termux-api"
"libusb"
"brotli"
"python"
"python-pip"
"libexpat"
"pkg-config"
"openssl"
"libc++"
"zlib"
"zstd"
"liblz4"
"pv"
"tur-repo"
"python-pycryptodomex"
)
for package in "${packages[@]}"; do
installed=$(apt policy "$package" 2>/dev/null | grep 'Installed' | awk '{print $2}')
candidate=$(apt policy "$package" 2>/dev/null | grep 'Candidate' | awk '{print $2}')
if [ "$installed" != "$candidate" ]; then
apt download "$package" >/dev/null 2>&1
dpkg --force-overwrite -i "${package}"*.deb >/dev/null 2>&1
rm -f "${package}"*.deb
fi
_progress
done
libs=(
"urllib3"
"requests"
"colorama"
)
for lib in "${libs[@]}"; do
installed_version=$(pip show "$lib" 2>/dev/null | grep Version | awk '{print $2}')
latest_version=$(pip index versions "$lib" 2>/dev/null | grep 'LATEST:' | awk '{print $2}')
if [ -z "$installed_version" ]; then
pip install "$lib" -q
elif [ "$installed_version" != "$latest_version" ]; then
pip install --upgrade "$lib" -q
fi
_progress
done
curl -s "https://raw.githubusercontent.com/offici5l/MiTool/master/MT/mitool.py" -o "$PREFIX/bin/mitool" && chmod +x "$PREFIX/bin/mitool"
_progress
curl -s "https://raw.githubusercontent.com/offici5l/MiTool/master/MT/mihelp.py" -o "$PREFIX/bin/mihelp" && chmod +x "$PREFIX/bin/mihelp"
_progress
curl -s "https://raw.githubusercontent.com/offici5l/MiTool/master/MT/miflashf.py" -o "$PREFIX/bin/miflashf" && chmod +x "$PREFIX/bin/miflashf"
_progress
curl -s "https://raw.githubusercontent.com/offici5l/MiTool/master/MT/miflashs.py" -o "$PREFIX/bin/miflashs" && chmod +x "$PREFIX/bin/miflashs"
_progress
curl -s "https://raw.githubusercontent.com/offici5l/MiTool/master/MT/mifce.py" -o "$PREFIX/bin/mifce" && chmod +x "$PREFIX/bin/mifce"
_progress
curl -s "https://raw.githubusercontent.com/offici5l/MiTool/master/MT/miasst.py" -o "$PREFIX/bin/miasst" && chmod +x "$PREFIX/bin/miasst"
_progress
if [ ! -f "$miunlockusers" ]; then
curl -sSL -o "$PREFIX/bin/miunlock" https://github.com/offici5l/MiUnlockTool/releases/latest/download/MiUnlockTool.py
touch "$miunlockusers"
else
curl -sSL -o "$PREFIX/bin/miunlock" https://raw.githubusercontent.com/offici5l/MiUnlockTool/master/MiUnlockTool.py
fi
chmod +x "$PREFIX/bin/miunlock"
_progress
curl -s "https://raw.githubusercontent.com/offici5l/MiBypassTool/master/MiBypassTool.py" -o "$PREFIX/bin/mibypass" && chmod +x "$PREFIX/bin/mibypass"
_progress
curl -s -L -o $PREFIX/bin/miasst_termux $(curl -s "https://api.github.com/repos/offici5l/MiAssistantTool/releases/latest" | grep "browser_download_url.*miasst_termux_${arch}" | cut -d '"' -f 4) && chmod +x $PREFIX/bin/miasst_termux
_progress
echo
curl -L -s https://raw.githubusercontent.com/offici5l/MiTool/main/CHANGELOG.md | tac | awk '/^#/{exit} {print "\033[0;34m" $0 "\033[0m"}' | tac
printf "\nuse command: \e[1;32mmitool\e[0m\n\n"