forked from j-hc/revanced-magisk-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.sh
executable file
·172 lines (141 loc) · 6.55 KB
/
utils.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
#!/bin/bash
MODULE_TEMPLATE_DIR="revanced-magisk"
TEMP_DIR="temp"
WGET_HEADER="User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0"
get_prebuilts() {
echo "Getting prebuilts"
mkdir -p "$TEMP_DIR"
RV_CLI_URL=$(req https://api.github.com/repos/revanced/revanced-cli/releases/latest - | tr -d ' ' | sed -n 's/.*"browser_download_url":"\(.*jar\)".*/\1/p')
RV_CLI_JAR="${TEMP_DIR}/$(echo "$RV_CLI_URL" | awk -F/ '{ print $NF }')"
log "CLI: ${RV_CLI_JAR#"$TEMP_DIR/"} "
RV_INTEGRATIONS_URL=$(req https://api.github.com/repos/revanced/revanced-integrations/releases/latest - | tr -d ' ' | sed -n 's/.*"browser_download_url":"\(.*apk\)".*/\1/p')
RV_INTEGRATIONS_APK="${TEMP_DIR}/$(echo "$RV_INTEGRATIONS_URL" | awk '{n=split($0, arr, "/"); printf "%s-%s.apk", substr(arr[n], 0, length(arr[n]) - 4), arr[n-1]}')"
log "Integrations: ${RV_INTEGRATIONS_APK#"$TEMP_DIR/"} "
RV_PATCHES_URL=$(req https://api.github.com/repos/revanced/revanced-patches/releases/latest - | tr -d ' ' | sed -n 's/.*"browser_download_url":"\(.*jar\)".*/\1/p')
RV_PATCHES_JAR="${TEMP_DIR}/$(echo "$RV_PATCHES_URL" | awk -F/ '{ print $NF }')"
log "Patches: ${RV_PATCHES_JAR#"$TEMP_DIR/"} "
dl_if_dne "$RV_CLI_JAR" "$RV_CLI_URL"
dl_if_dne "$RV_INTEGRATIONS_APK" "$RV_INTEGRATIONS_URL"
dl_if_dne "$RV_PATCHES_JAR" "$RV_PATCHES_URL"
}
reset_template() {
echo "# utils" >"${MODULE_TEMPLATE_DIR}/common/install.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/service.sh"
echo "# utils" >"${MODULE_TEMPLATE_DIR}/module.prop"
rm -f "${MODULE_TEMPLATE_DIR}/base.apk" "${MODULE_TEMPLATE_DIR}/libjsc.so"
}
req() {
wget -nv -O "$2" --header="$WGET_HEADER" "$1"
}
dl_if_dne() {
if [ ! -f "$1" ]; then
echo -e "\nGetting '$1' from '$2'"
req "$2" "$1"
fi
}
log() {
echo -e "$1" >>build.log
}
# yes this is how i download the stock yt apk from apkmirror
dl_yt() {
echo "Downloading YouTube"
local url="https://www.apkmirror.com/apk/google-inc/youtube/youtube-${1//./-}-release/"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's/href="/@/g; s;.*BUNDLE</span>[^@]*@\([^#]*\).*;\1;p')"
log "\nYouTube version: $1\ndownloaded from: [APKMirror]($url)"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
req "$url" "$2"
}
dl_music() {
echo "Downloading YouTube Music"
local url="https://www.apkmirror.com/apk/google-inc/youtube-music/youtube-music-${1//./-}-release/"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's/href="/@/g; s;.*arm64-v8a</div>[^@]*@\([^"]*\).*;\1;p')"
log "\nYouTube Music version: $1\ndownloaded from: [APKMirror]($url)"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
url="https://www.apkmirror.com$(req "$url" - | tr '\n' ' ' | sed -n 's;.*href="\(.*key=[^"]*\)">.*;\1;p')"
req "$url" "$2"
}
build_yt() {
echo "Patching YouTube"
reset_template
# This only finds the supported versions of some random patch wrt the first occurance of the string but that's fine
local supported_versions last_ver yt_base_apk dl_output yt_patched_apk output
supported_versions=$(unzip -p "$RV_PATCHES_JAR" | strings -n 8 -s , | sed -rn 's/.*youtube,versions,(([0-9.]*,*)*),Lk.*/\1/p')
echo "Supported versions of the YouTube patch: $supported_versions"
last_ver=$(echo "$supported_versions" | awk -F, '{ print $NF }')
echo "Choosing '${last_ver}'"
yt_base_apk="${TEMP_DIR}/base-v${last_ver}.apk"
if [ ! -f "$yt_base_apk" ]; then
dl_output="${TEMP_DIR}/yt-stock-v${last_ver}.zip"
dl_yt "$last_ver" "$dl_output"
unzip -p "$dl_output" "base.apk" >"$yt_base_apk"
fi
yt_patched_apk="${TEMP_DIR}/yt-revanced-base.apk"
java -jar $RV_CLI_JAR -a $yt_base_apk -c -o $yt_patched_apk -b $RV_PATCHES_JAR -m $RV_INTEGRATIONS_APK -e premium-heading $1
mv -f "$yt_patched_apk" "${MODULE_TEMPLATE_DIR}/base.apk"
echo "Creating the magisk module for YouTube..."
output="yt-revanced-magisk-v${last_ver}-noarch.zip"
service_sh "com.google.android.youtube"
yt_module_prop "$last_ver"
cd "$MODULE_TEMPLATE_DIR" || return
zip -r "../$output" .
cd ..
echo "Built YouTube: '${output}'"
}
build_music() {
echo "Patching YouTube Music"
reset_template
local supported_versions last_ver music_apk music_patched_apk output
# This only finds the supported versions of some random patch wrt the first occurance of the string but that's fine
supported_versions=$(unzip -p "$RV_PATCHES_JAR" | strings -n 7 -s , | sed -rn 's/.*music,versions,(([0-9.]*,*)*),Lk.*/\1/p')
echo "Supported versions of the Music patch: $supported_versions"
last_ver=$(echo "$supported_versions" | awk -F, '{ print $NF }')
echo "Choosing '${last_ver}'"
music_apk="${TEMP_DIR}/music-stock-v${last_ver}.apk"
if [ ! -f "$music_apk" ]; then
dl_music "$last_ver" "$music_apk"
fi
unzip -p "$music_apk" "lib/arm64-v8a/libjsc.so" >"${MODULE_TEMPLATE_DIR}/libjsc.so"
music_patched_apk="${TEMP_DIR}/music-revanced-base.apk"
java -jar $RV_CLI_JAR -a $music_apk -c -o $music_patched_apk -b $RV_PATCHES_JAR -m $RV_INTEGRATIONS_APK $1
mv -f "$music_patched_apk" "${MODULE_TEMPLATE_DIR}/base.apk"
echo "Creating the magisk module for YouTube Music"
output="music-revanced-magisk-v${last_ver}-arm64-v8a.zip"
service_sh "com.google.android.apps.youtube.music"
music_module_prop "$last_ver"
echo 'YTPATH=$(pm path com.google.android.apps.youtube.music | grep base | sed "s/package://g; s/\/base.apk//g")
cp_ch -n $MODPATH/libjsc.so $YTPATH/lib/arm64 0755' >"${MODULE_TEMPLATE_DIR}/common/install.sh"
cd "$MODULE_TEMPLATE_DIR" || return
zip -r "../$output" .
cd ..
echo "Built Music '${output}'"
}
service_sh() {
echo 'while [ "$(getprop sys.boot_completed)" != 1 ]; do
sleep 1
done
YTPATH=$(pm path PACKAGE | grep base | sed "s/package://g; s/\/base.apk//g")
if [ -n "$YTPATH" ]; then
su -c mount $MODDIR/base.apk $YTPATH/base.apk
fi' | sed "s/PACKAGE/$1/g" >"${MODULE_TEMPLATE_DIR}/service.sh"
}
yt_module_prop() {
echo "id=ytrv-magisk
name=YouTube ReVanced
version=v${1}
versionCode=$(date +'%Y%m%d')
author=j-hc
description=mounts base.apk for YouTube ReVanced
updateJson=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/update/yt-update.json
" >"${MODULE_TEMPLATE_DIR}/module.prop"
}
music_module_prop() {
echo "id=ytmusicrv-magisk
name=YouTube Music ReVanced
version=v${1}
versionCode=$(date +'%Y%m%d')
author=j-hc
description=mounts base.apk for YouTube Music ReVanced
updateJson=https://raw.githubusercontent.com/${GITHUB_REPOSITORY}/update/music-update.json
" >"${MODULE_TEMPLATE_DIR}/module.prop"
}