forked from n0k0m3/revanced-build-template
-
Notifications
You must be signed in to change notification settings - Fork 6
/
build_revanced.sh
executable file
Β·247 lines (206 loc) Β· 7.91 KB
/
build_revanced.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
#!/bin/bash
# Import build configuration
source build.targets
# File containing all patches
patch_file=./patches.txt
# Get line numbers where included & excluded patches start from.
# We rely on the hardcoded messages to get the line numbers using grep
excluded_start="$(grep -n -m1 'EXCLUDE PATCHES' "$patch_file" | cut -d':' -f1)"
included_start="$(grep -n -m1 'INCLUDE PATCHES' "$patch_file" | cut -d':' -f1)"
# Get everything but hashes from between the EXCLUDE PATCH & INCLUDE PATCH line
# Note: '^[^#[:blank:]]' ignores starting hashes and/or blank characters i.e, whitespace & tab excluding newline
excluded_patches="$(tail -n +$excluded_start $patch_file | head -n "$(( included_start - excluded_start ))" | grep '^[^#[:blank:]]')"
# Get everything but hashes starting from INCLUDE PATCH line until EOF
included_patches="$(tail -n +$included_start $patch_file | grep '^[^#[:blank:]]')"
# Array for storing patches
declare -a patches
# Artifacts associative array aka dictionary
declare -A artifacts
if [ "$EXTENDED_SUPPORT" = "true" ]; then
artifacts["revanced-cli.jar"]="inotia00/revanced-cli revanced-cli .jar"
artifacts["revanced-integrations.jar"]="inotia00/revanced-integrations revanced-integrations .jar"
artifacts["revanced-patches.jar"]="inotia00/revanced-patches revanced-patches .jar"
else
artifacts["revanced-integrations.apk"]="revanced/revanced-integrations revanced-integrations .apk"
artifacts["revanced-cli.jar"]="revanced/revanced-cli revanced-cli .jar"
artifacts["revanced-patches.jar"]="revanced/revanced-patches revanced-patches .jar"
fi
artifacts["vanced-microG.apk"]="inotia00/VancedMicroG microg .apk"
artifacts["apkeep"]="EFForg/apkeep apkeep-x86_64-unknown-linux-gnu"
## Functions
get_artifact_download_url() {
# Usage: get_download_url <repo_name> <artifact_name> <file_type>
local api_url result
api_url="https://api.github.com/repos/$1/releases/latest"
# shellcheck disable=SC2086
result=$(curl -s $api_url | jq ".assets[] | select(.name | contains(\"$2\") and contains(\"$3\") and (contains(\".sig\") | not)) | .browser_download_url")
echo "${result:1:-1}"
}
# Function for populating patches array, using a function here reduces redundancy & satisfies DRY principals
populate_patches() {
# Note: <<< defines a 'here-string'. Meaning, it allows reading from variables just like from a file
while read -r patch; do
patches+=("$1 $patch")
done <<< "$2"
}
## Main
# cleanup to fetch new revanced on next run
if [[ "$1" == "clean" ]]; then
rm -f revanced-cli.jar revanced-integrations.apk revanced-patches.jar vanced-microG.apk
rm -rf build/*
exit
fi
if [[ "$1" == "experimental" ]]; then
EXPERIMENTAL="--experimental"
fi
# Fetch all the dependencies
for artifact in "${!artifacts[@]}"; do
if [ ! -f "$artifact" ]; then
echo "Downloading $artifact"
# shellcheck disable=SC2086,SC2046
curl -sLo "$artifact" $(get_artifact_download_url ${artifacts[$artifact]})
fi
done
# Fetch microG
chmod +x apkeep
if [ ! -f "vanced-microG.apk" ]; then
# Vanced microG 0.2.24.220220
VMG_VERSION="0.2.24.220220"
echo "Downloading Vanced microG"
./apkeep -a com.mgoogle.android.gms@$VMG_VERSION .
mv com.mgoogle.android.gms@$VMG_VERSION.apk vanced-microG.apk
fi
# If the variables are NOT empty, call populate_patches with proper arguments
[[ ! -z "$excluded_patches" ]] && populate_patches "-e" "$excluded_patches"
[[ ! -z "$included_patches" ]] && populate_patches "-i" "$included_patches"
mkdir -p build
function build_youtube_root(){
echo "************************************"
echo "Building YouTube Root APK"
echo "************************************"
if [ -f "com.google.android.youtube.apk" ]; then
java -jar revanced-cli.jar patch \
-m revanced-integrations.apk \
-b revanced-patches.jar \
--mount \
-e microg-support ${patches[@]} \
$EXPERIMENTAL \
-o "build/revanced-youtube-$(cat versions.json | grep -oP '(?<="com.google.android.youtube.apk": ")[^"]*')-root.apk" \
com.google.android.youtube.apk
else
echo "Cannot find YouTube APK, skipping build"
fi
}
function build_youtube_nonroot(){
echo "************************************"
echo "Building YouTube Non-root APK"
echo "************************************"
if [ -f "com.google.android.youtube.apk" ]; then
java -jar revanced-cli.jar patch \
-m revanced-integrations.apk \
-b revanced-patches.jar \
${patches[@]} \
$EXPERIMENTAL \
-o "build/revanced-youtube-$(cat versions.json | grep -oP '(?<="com.google.android.youtube.apk": ")[^"]*').apk" \
com.google.android.youtube.apk
else
echo "Cannot find YouTube APK, skipping build"
fi
}
function build_ytmusic_root(){
echo "************************************"
echo "Building YouTube Music APK"
echo "************************************"
if [ -f "com.google.android.apps.youtube.music.apk" ]; then
echo "Building Root APK"
java -jar revanced-cli.jar \
-b revanced-patches.jar \
--mount \
-e microg-support ${patches[@]} \
$EXPERIMENTAL \
-o "build/revanced-music-$(cat versions.json | grep -oP '(?<="com.google.android.apps.youtube.music.apk": ")[^"]*')-root.apk" \
com.google.android.apps.youtube.music.apk
else
echo "Cannot find YouTube Music APK, skipping build"
fi
}
function build_ytmusic_nonroot(){
echo "************************************"
echo "Building YouTube Music APK"
echo "************************************"
if [ -f "com.google.android.apps.youtube.music.apk" ]; then
echo "Building Non-root APK"
java -jar revanced-cli.jar patch \
-b revanced-patches.jar \
${patches[@]} \
$EXPERIMENTAL \
-o "build/revanced-music-$(cat versions.json | grep -oP '(?<="com.google.android.apps.youtube.music.apk": ")[^"]*').apk" \
com.google.android.apps.youtube.music.apk
else
echo "Cannot find YouTube Music APK, skipping build"
fi
}
function build_tiktok_nonroot(){
echo "************************************"
echo "Building TikTok APK"
echo "************************************"
if [ -f "com.zhiliaoapp.musically.apk" ]; then
echo "Building Non-root APK"
java -Xmx8192m -jar revanced-cli.jar patch \
-m revanced-integrations.apk \
-b revanced-patches.jar \
${patches[@]} \
$EXPERIMENTAL \
-o "build/revanced-tiktok-$(cat versions.json | grep -oP '(?<="com.zhiliaoapp.musically.apk": ")[^"]*').apk" \
com.zhiliaoapp.musically.apk
else
echo "Cannot find TikTok APK, skipping build"
fi
}
function build_twitch_nonroot(){
echo "************************************"
echo "Building Twitch APK"
echo "************************************"
if [ -f "tv.twitch.android.app.apk" ]; then
echo "Building Non-root APK"
java -jar revanced-cli.jar patch \
-m revanced-integrations.apk \
-b revanced-patches.jar \
${patches[@]} \
$EXPERIMENTAL \
-o "build/revanced-twitch-$(cat versions.json | grep -oP '(?<="tv.twitch.android.app.apk": ")[^"]*').apk" \
tv.twitch.android.app.apk
else
echo "Cannot find Twitch APK, skipping build"
fi
}
if [ "$YOUTUBE_ROOT" = "true" ]; then
build_youtube_root
else
printf "\nSkipping YouTube ReVanced (root)"
fi
if [ "$YOUTUBE_NONROOT" = "true" ]; then
build_youtube_nonroot
else
printf "\nSkipping YouTube ReVanced (nonroot)"
fi
if [ "$YTMUSIC_ROOT" = "true" ]; then
build_ytmusic_root
else
printf "\nSkipping YouTube Music ReVanced (root)"
fi
if [ "$YTMUSIC_NONROOT" = "true" ]; then
build_ytmusic_nonroot
else
printf "\nSkipping YouTube Music ReVanced (nonroot)"
fi
if [ "$TIKTOK_NONROOT" = "true" ] && [ "$EXTENDED_SUPPORT" != "true" ]; then
build_tiktok_nonroot
else
printf "\nSkipping TikTok (nonroot) due to disabled config or ReVanced Extended support being enabled in build.targets"
fi
if [ "$TWITCH_NONROOT" = "true" ] && [ "$EXTENDED_SUPPORT" != "true" ]; then
build_twitch_nonroot
else
printf "\nSkipping Twitch (nonroot) due to disabled config or ReVanced Extended support being enabled in build.targets"
fi