-
Notifications
You must be signed in to change notification settings - Fork 26
/
.install
195 lines (151 loc) · 5.39 KB
/
.install
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
#!/data/data/com.termux/files/usr/bin/bash
echo
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
source "/data/data/com.termux/files/usr/bin/termux-setup-package-manager" || { echo "Failed to load package manager"; exit 1; }
if [ "$TERMUX_APP_PACKAGE_MANAGER" = "apt" ]; then
arch=$(dpkg --print-architecture)
elif [ "$TERMUX_APP_PACKAGE_MANAGER" = "pacman" ]; then
arch=$(pacman-conf | awk -F ' = ' '/Architecture/ {print $2}')
else
echo "Unknown package manager"
exit 1
fi
if [[ "$arch" != "aarch64" && "$arch" != "arm" ]]; then
echo "MiUnlockTool(termux) does not support architecture $arch"
exit 1
fi
miunlockusersok="false"
miunlockusers="$PREFIX/bin/.miunlockusersok"
mitoolusers="$PREFIX/bin/.mitoolusersok"
if [ ! -f "$miunlockusers" ] && [ ! -f "$mitoolusers" ]; then
echo -ne "\rapt upgrade ..."
apt upgrade > /dev/null 2> >(grep -v "apt does not have a stable CLI interface")
touch "$miunlockusers"
miunlockusersok="true"
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=22
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=(
"openssl"
"libffi"
"abseil-cpp"
"termux-api"
"libusb"
"brotli"
"python"
"python-pip"
"libexpat"
"pkg-config"
"libc++"
"zlib"
"zstd"
"liblz4"
"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
if [ "$miunlockusersok" == "false" ]; then
curl -sSL -o "$PREFIX/bin/miunlock" https://raw.githubusercontent.com/offici5l/MiUnlockTool/master/MiUnlockTool.py
fi
if [ "$miunlockusersok" == "true" ]; then
curl -sSL -o "$PREFIX/bin/miunlock" https://github.com/offici5l/MiUnlockTool/releases/latest/download/MiUnlockTool.py
fi
chmod +x "$PREFIX/bin/miunlock"
_progress
echo
printf "\nuse command: \e[1;32mmiunlock\e[0m\n\n"