forked from CnC-Robert/revanced-cli-script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-from-source.sh
executable file
·175 lines (137 loc) · 4.89 KB
/
build-from-source.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
#!/bin/bash
DIR="$(pwd)"
# Check if a youtube.apk is provided before continuing
if [ ! -e "$DIR/build/youtube.apk" ]; then
echo
echo -e "\e[1;31mError: ./build/youtube.apk not found\e[0m"
echo
exit 1
fi
# Check if curl & git are 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
if ! command -v "git" &> "/dev/null"; then
echo
echo -e "\e[1;31mError: git 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
else
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
fi
# Check if android sdk is installed and if not, download and extract android sdk
if [ -z "$ANDROID_HOME" ] && [ -z "$ANDROID_SDK_ROOT" ]; then
export ANDROID_HOME="$(readlink -f "$DIR/android-sdk")"
if [ ! -e "$ANDROID_HOME" ]; then
echo
if [ ! -e "android-sdk.tar.gz" ]; then
echo "Downloading Android SDK"
curl "https://github.com/CnC-Robert/revanced-cli-script/releases/download/androidsdk/android-sdk.tar.gz" -L -s -o "android-sdk.tar.gz"
fi
echo "Extracting android-sdk.tar.gz"
tar xzf "android-sdk.tar.gz"
fi
fi
# Check if adb device is connected before continuing
if [ ! -z "$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 shell & root access
if ! adb shell su -c exit; then
echo
echo -e "\e[1;31mError: device $1 either has no shell access or 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 ReVanced\e[0m"
fi
echo
# Clone the patcher and publish it
git clone https://github.com/revanced/revanced-patcher
cd revanced-patcher
git checkout dev
chmod +x ./gradlew
# If $LOCALMAVEN is set to 1 use publishToMavenLocal instead of publish
./gradlew $(if [ "$LOCALMAVEN" == "1" ]; then echo "publishToMavenLocal"; else echo "publish"; fi)
# If the program did not build & publish correctly exit the script
if [ ! $? == 0 ]; then exit 1; fi
cd ..
echo
# Clone the patches and publish it
git clone https://github.com/revanced/revanced-patches
cd revanced-patches
git checkout dev
chmod +x ./gradlew
./gradlew $(if [ "$LOCALMAVEN" == "1" ]; then echo "publishToMavenLocal"; else echo "publish"; fi)
if [ ! $? == 0 ]; then exit 1; fi
cd ..
echo
# Clone the cli and build it
git clone https://github.com/revanced/revanced-cli
cd revanced-cli
git checkout dev
chmod +x ./gradlew
./gradlew build
if [ ! $? == 0 ]; then exit 1; fi
cd ..
echo
# Clone the integrations and build it
git clone https://github.com/revanced/revanced-integrations
cd revanced-integrations
chmod +x ./gradlew
./gradlew build
if [ ! $? == 0 ]; then exit 1; fi
cd ..
# Copy the cli, integrations, patches and patcher to the build directory
cp revanced-cli/build/libs/revanced-cli-*-all.jar build/revanced-cli.jar
cp revanced-integrations/app/build/outputs/apk/release/*.apk build/integrations.apk
# The cli doesn't need the files that end -sources.jar or -javadoc.jar so don't copy those
cp "$DIR/revanced-patches/build/libs/$(ls "$DIR/revanced-patches/build/libs/" | grep -Pv "javadoc|sources")" "$DIR/build/revanced-patches.jar"
cp "$DIR/revanced-patcher/build/libs/$(ls "$DIR/revanced-patcher/build/libs/" | grep -Pv "javadoc|sources")" "$DIR/build/revanced-patcher.jar"
cd build
# Set the correct java executable
if [ -z "$JAVA_HOME" ]; then
JAVA="java"
else
JAVA="$JAVA_HOME/bin/java"
fi
# Execute the cli and if an adb device name is given deploy on device
"$JAVA" -jar "revanced-cli.jar" -a "youtube.apk" $(if [ ! -z "$1" ]; then echo "-d $1"; fi) -m "integrations.apk" -o "revanced.apk" -p "revanced-patches.jar" -t "temp" $(if [ ! -z "$1" ] && [ "$ROOT" != "1" ]; then echo "--install"; fi) $(if [ "$ROOT" != "1" ]; then echo "-i codecs-unlock -i exclusive-audio-playback -i background-play -i upgrade-button-remover -i tasteBuilder-remover -i seekbar-tapping -i old-quality-layout -i minimized-playback -i disable-create-button -i shorts-button -i amoled -i microg-patch -i general-ads -i video-ads"; fi)
cp "$DIR/build/revanced.apk" "$DIR/revanced.apk"
exit 0