-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpatch.sh
More file actions
218 lines (191 loc) · 7.68 KB
/
Copy pathpatch.sh
File metadata and controls
218 lines (191 loc) · 7.68 KB
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
#!/bin/sh
#---------------------------#
# Made by XDream8 #
#---------------------------#
# deps #
#---------------------------#
# curl, wget or $downloader #
# awk #
# java(17) #
# grep #
#---------------------------#
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
check_dep() {
if [ ! "$(command -v $1)" ]; then
printf '%b\n' "${RED}$2${NC}"
exit 1
fi
}
checkadb() {
if [ ! "$(pidof adb)" ]; then
if [ "$(command -v rdo)" ]; then
sudo=rdo
elif [ "$(command -v doas)" ]; then
sudo=doas
else
sudo=sudo
fi
printf '%b\n' "${YELLOW}starting adb server${NC}"
$sudo adb start-server
fi
device_id=$(adb devices | awk 'FNR == 2 {print $1}')
if [ "$device_id" = "" ]; then
printf '%b\n' "${RED}your phone is not connected to pc, exiting!${NC}"
exit 1
else
printf '%b\n' "${YELLOW}adb device_id=$device_id"
fi
}
checkyt() {
if [ ! "$(adb shell cmd package list packages | grep -o 'com.google.android.youtube')" ]; then
printf '%b\n' "${RED}root variant: install youtube v${apk_version} on your device to mount w/ integrations, exiting!${NC}"
exit 1
fi
}
get_latest_version_info() {
printf '%b\n' "${BLUE}getting latest versions info${NC}"
revanced_cli_version=$(curl -s -L https://github.com/revanced/revanced-cli/releases/latest | awk 'match($0, /([0-9][.]+).*.jar/) {print substr($0, RSTART, RLENGTH)}' | head -n 1 | cut -d"/" -f1)
revanced_patches_version=$(curl -s -L https://github.com/revanced/revanced-patches/releases/latest | awk 'match($0, /([0-9][.]+).*.jar/) {print substr($0, RSTART, RLENGTH)}' | head -n 1 | cut -d"/" -f1)
revanced_integrations_version=$(curl -s -L https://github.com/revanced/revanced-integrations/releases/latest | grep -o 'revanced/revanced-integrations/releases/download/v[0-9].*/.*.apk' | grep -o "[0-9].*" | cut -d"/" -f1)
for i in \
"revanced_cli_version=$revanced_cli_version" \
"revanced_patches_version=$revanced_patches_version" \
"revanced_integrations_version=$revanced_integrations_version"; do
printf '%b\n' "${YELLOW}$i${NC}"
done
}
remove_old() {
if [ ! "$(command -v find)" ]; then
[ ! -f "$cli_filename" ] && [ -f "revanced-cli-*-all.jar" ] && (printf '%b\n' "${RED}removing old revanced-cli${NC}" && rm -f revanced-cli-*.jar)
[ ! -f "$patches_filename" ] && [ -f "revanced-patches-*-all.jar" ] && (printf '%b\n' "${RED}removing old revanced-patches${NC}" && rm -f revanced-patches-*.jar)
[ ! -f "$apk_filename" ] && [ -f "YouTube-*.apk" ] && (printf '%b\n' "${RED}removing old youtube${NC}" && rm YouTube-17*.apk)
[ ! -f "$apk_filename" ] && [ -f "YouTube-Music-*.apk" ] && (printf '%b\n' "${RED}removing old youtube-music${NC}" && rm YouTube-Music-*.apk)
rm -f $integrations_filename
else
find . -maxdepth 1 -type f \( -name "revanced-*.jar" -or -name "$integrations_filename" \) ! \( -name "*.keystore" -or -name "$cli_filename" -or -name "$patches_filename" -or -name "$apk_filename" \) -delete
fi
}
download_needed() {
# number
n=0
printf '%b\n' "${BLUE}Downloading revanced-cli, revanced-patches and revanced-integrations${NC}"
for i in \
https://github.com/revanced/revanced-cli/releases/download/v$revanced_cli_version/$cli_filename \
https://github.com/revanced/revanced-patches/releases/download/v$revanced_patches_version/$patches_filename \
https://github.com/revanced/revanced-integrations/releases/download/v$revanced_integrations_version/$integrations_filename \
$apk_link; do
n=$(awk "BEGIN {print $n+1}")
printf '%b\n' "${CYAN}$n) ${YELLOW}downloading $i${NC}"
$downloader $i
done
}
build_apk() {
base_cmd="java -jar $cli_filename \
-a $apk_filename \
-c \
-o $output_apk_name \
-b $patches_filename \
-m $integrations_filename"
-e sponsorblock
-i return-youtube-dislike
-i hide-get-premium
-i amoled
-e swipe-controls
-i old-quality-layout
if [ "$1" ] && [ ! "$additional_args" = "" ]; then
# root with $additional_args
$base_cmd \
$additional_args \
$1
elif [ "$1" ] && [ "$additional_args" = "" ]; then
# root
$base_cmd \
$1
elif [ ! "$1" ] && [ ! "$additional_args" = "" ]; then
# non-root with $additional_args
$base_cmd \
$additional_args
elif [ ! "$1" ] && [ "$additional_args" = "" ]; then
# non-root
$base_cmd
fi
}
patch() {
printf '%b\n' "${BLUE}patching process started(${RED}$root_text${BLUE})${NC}"
printf '%b\n' "${BLUE}it may take a while please be patient${NC}"
if [ $nonroot = 1 ]; then
build_apk
else
root_args=" \
-d $device_id \
-e microg-support \
--mount"
build_apk "$root_args"
fi
}
main() {
## defaults
[ -z "$what_to_patch" ] && what_to_patch="youtube"
[ -z "$nonroot" ] && nonroot=1
[ -z "$additional_args" ] && additional_args=""
## check $nonroot
if [ $nonroot = 1 ]; then
root_text="non-root"
else
root_text="root"
printf '%b\n' "${RED}please be sure that your phone is connected to your pc, waiting 5 seconds${NC}"
sleep 5s
checkadb
fi
## what should we patch
if [ "$what_to_patch" = "youtube" ]; then
[ -z "$apk_version" ] && apk_version=17.28.34
apk_filename=YouTube-$apk_version.apk
output_apk_name=revanced-$apk_version-$root_text.apk
elif [ "$what_to_patch" = "youtube-music" ]; then
[ -z "$apk_version" ] && apk_version=5.14.53
apk_filename=YouTube-Music-$apk_version.apk
output_apk_name=revanced-music-$apk_version-$root_text.apk
fi
## link to download $what_to_patch
apk_link=https://github.com/XDream8/revanced-creator/releases/download/v0.1/$apk_filename
## downloader
if [ -z "$downloader" ] && [ "$(command -v curl)" ]; then
downloader="curl -qLJO"
elif [ -z "$downloader" ] && [ "$(command -v wget)" ]; then
downloader="wget"
fi
## dependecy checks
check_dep curl "curl is required, exiting!"
check_dep $downloader "$downloader is missing, exiting!"
check_dep java "java 17 is required, exiting!"
check_dep awk "awk is required, exiting!"
check_dep grep "grep is required, exiting!"
## java version check
JAVA_VERSION="$(java -version 2>&1 | grep -oe "version \".*\"" | awk 'match($0, /([0-9]+)/) {print substr($0, RSTART, RLENGTH)}')"
if [ $JAVA_VERSION -lt 17 ]; then
printf '%b\n' "${RED}java 17 is required but you have version $JAVA_VERSION, exiting!${NC}"
exit 1
else
printf '%b\n' "${YELLOW}java version $JAVA_VERSION found${NC}"
fi
get_latest_version_info
printf '%b\n' "${YELLOW}$what_to_patch version to be patched: $apk_version${NC}"
cli_filename=revanced-cli-$revanced_cli_version-all.jar
patches_filename=revanced-patches-$revanced_patches_version.jar
integrations_filename=app-release-unsigned.apk
remove_old
download_needed
if [ $nonroot = 0 ]; then
printf '%b\n' "${BLUE}root variant: installing stock youtube-$apk_version first${NC}"
adb install -r $apk_filename || ( printf '%b\n' "${RED}install failed, exiting!${NC}" && exit 1 && exit 1 )
checkyt
fi
patch
exit 0
}
main