-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathbuild-from-prebuilt.sh
executable file
·177 lines (140 loc) · 5.71 KB
/
build-from-prebuilt.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
#!/bin/bash
DIR="$(pwd)"
# Check if stock.apk exists before continuing
if [ ! -e "$DIR/build/stock.apk" ]; then
echo
echo -e "\e[1;31mError: ./build/stock.apk not found\e[0m"
echo
exit 1
fi
# Check if curl is installed before continuing
if ! command -v "curl" &> "/dev/null"; then
echo
echo -e "\e[1;31mError: curl not found\e[0m"
echo
exit 1
fi
# Check if java is installed and if not, download and extract openjdk 17
if ! command -v "java" &> "/dev/null" && [ -z "$JAVA_HOME" ]; then
export JAVA_HOME="$(readlink -f "$DIR/openjdk")"
if [ ! -e "$JAVA_HOME/bin/java" ]; then
echo
if [ ! -e "openjdk.tar.gz" ]; then
echo "Downloading openjdk..."
wget -q "https://download.java.net/java/GA/jdk17.0.2/dfd4a8d0985749f896bed50d7138ee7f/8/GPL/openjdk-17.0.2_linux-x64_bin.tar.gz" -O "openjdk.tar.gz"
fi
echo "Extracting openjdk..."
tar xzf "openjdk.tar.gz"
mv jdk-* "openjdk"
fi
fi
# Set the correct java executable
if [ -z "$JAVA_HOME" ]; then
JAVA="java"
else
JAVA="$JAVA_HOME/bin/java"
fi
# Check the java version
if $JAVA -version 2>&1 | grep "1.8" &> "/dev/null"; then
echo
echo -e "\e[1;31mError: Java 8 is not supported\e[0m"
echo
exit 1
fi
# Check if adb device is connected before continuing
if [ -n "$1" ]; then
# Check if adb is installed before continuing
if ! command -v "adb" &> "/dev/null"; then
echo
echo -e "\e[1;31mError: adb not found\e[0m"
echo
exit 1
fi
# Check if the adb device is connected
if ! adb devices | grep "$1" &> "/dev/null"; then
echo
echo -e "\e[1;31mError: device $1 not connected\e[0m"
echo
exit 1
fi
# Check if adb has root access if $ROOT is set to 1
if [[ $ROOT == 1 ]] && ! adb shell su -c exit 2> /dev/null; then
echo
echo -e "\e[1;31mError: device $1 has no root access\e[0m"
echo
exit 1
fi
else
echo
echo -e "\e[1;33mWarning: no adb device specified. It is recommended to do so to automatically install the patched apk\e[0m"
fi
# Check $GITHUB_TOKEN if set
if [ -n "$GITHUB_TOKEN" ]; then
if curl "https://api.github.com/rate_limit" -L -s -H "Authorization: token $GITHUB_TOKEN" | grep "Bad credentials" &> "/dev/null"; then
echo
echo -e "\e[1;31mError: \$GITHUB_TOKEN is not set correctly\e[0m"
echo
exit 1
fi
fi
# Check if api has reached request limit
API_LIMIT="$(curl "https://api.github.com/rate_limit" -L -s $(if [ -z "$GITHUB_TOKEN" ]; then echo -H "Authorization: token $GITHUB_TOKEN" ;fi) | grep "remaining" | head -1)"
API_LIMIT="${API_LIMIT:19:-1}"
if [ "$API_LIMIT" -lt "3" ]; then
echo
echo -e "\e[1;31mError: Less than 3 Github API request left: $API_LIMIT left. $(if [ -z "$GITHUB_TOKEN" ]; then echo "Set \$GITHUB_TOKEN with a token to get more API requests"; fi)\e[0m"
echo
exit 1
fi
echo
echo "Downloading packages..."
echo
# Get latest cli version
CLI_VERSION="$(curl -s "https://api.github.com/repos/revanced/revanced-cli/releases/latest" -L -s $(if [ -z "$GITHUB_TOKEN" ]; then echo -H "Authorization: token $GITHUB_TOKEN" ;fi) | grep "tag_name")"
CLI_VERSION="${CLI_VERSION:16:-2}"
# Download cli and check if it downloaded correctly
if ! curl "https://github.com/revanced/revanced-cli/releases/download/v$CLI_VERSION/revanced-cli-$CLI_VERSION-all.jar" -L -s -o "$DIR/build/revanced-cli.jar"; then exit 1; fi
# Get latest integrations version
INTEGRATIONS_VERSION="$(curl -s "https://api.github.com/repos/revanced/revanced-integrations/releases/latest" -L -s $(if [ -z "$GITHUB_TOKEN" ]; then echo -H "Authorization: token $GITHUB_TOKEN" ;fi) | grep "tag_name")"
INTEGRATIONS_VERSION="${INTEGRATIONS_VERSION:16:-2}"
# Download integrations and check if it downloaded correctly
if ! curl "https://github.com/revanced/revanced-integrations/releases/download/v$INTEGRATIONS_VERSION/app-release-unsigned.apk" -L -s -o "$DIR/build/integrations.apk"; then exit 1; fi
# Get latest patches version
PATCHES_VERSION="$(curl -s "https://api.github.com/repos/revanced/revanced-patches/releases/latest" -L -s $(if [ -z "$GITHUB_TOKEN" ]; then echo -H "Authorization: token $GITHUB_TOKEN" ;fi) | grep "tag_name")"
PATCHES_VERSION="${PATCHES_VERSION:16:-2}"
# Download patches and check if it downloaded correctly
if ! curl "https://github.com/revanced/revanced-patches/releases/download/v$PATCHES_VERSION/revanced-patches-$PATCHES_VERSION.jar" -L -s -o "$DIR/build/revanced-patches.jar"; then exit 1; fi
cd "$DIR/build"
echo "Executing the CLI..."
echo
# If $LIST is set to 1 list all the patches and dont start patching
if [ "$LIST" = "1" ]; then
"$JAVA" -jar "revanced-cli.jar" -b "revanced-patches.jar" -l
exit 0
fi
if [ -n "$EXCLUDED_PATCHES" ]; then
# Get a list of all available patches
PATCHES="$("$JAVA" -jar "revanced-cli.jar" -a "stock.apk" -b "revanced-patches.jar" -l)"
# Check if every patch in $EXCLUDED_PATCHES is a valid patch and add it to patches to exclude
for PATCH in $EXCLUDED_PATCHES; do
if echo "$PATCHES" | grep "$PATCH" &> "/dev/null"; then
EXCLUDE="$EXCLUDE -e $PATCH"
fi
done
EXCLUDE="${EXCLUDE:1}"
fi
if [ -n "$INCLUDED_PATCHES" ]; then
# Get a list of all available patches
PATCHES="$("$JAVA" -jar "revanced-cli.jar" -a "stock.apk" -b "revanced-patches.jar" -l)"
# Check if every patch in $INCLUDED_PATCHES is a valid patch and add it to patches to include
for PATCH in $INCLUDED_PATCHES; do
if echo "$PATCHES" | grep "$PATCH" &> "/dev/null"; then
INCLUDE="$INCLUDE -i $PATCH"
fi
done
INCLUDE="${INCLUDE:1}"
fi
# Execute the cli and if an adb device name is given deploy on device
"$JAVA" -jar "revanced-cli.jar" -a "stock.apk" -o "revanced.apk" -b "revanced-patches.jar" -m "integrations.apk" $(if [ -n "$1" ]; then echo "-d $1"; fi) -t "temp" $(if [ "$ROOT" = "1" ]; then echo "--mount"; fi) $EXCLUDE $INCLUDE
if [ -e "$DIR/build/revanced.apk" ]; then cp "$DIR/build/revanced.apk" "$DIR/revanced.apk"; fi
exit 0