forked from VictorML11/FluxSpigot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generateJar.sh
executable file
·96 lines (76 loc) · 2.2 KB
/
generateJar.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
#!/bin/bash
# Generates a patched jar for paperclip
if [[ $# -lt 4 ]]; then
echo "Usage ./generateJar.sh {input jar} {mojang_jar} {source_url} {name}"
exit 1;
fi;
basedir="$(pwd)"
mkdir -p work/Paperclip
PAPERCLIP_JAR=paperclip.jar
if [ ! -f work/Paperclip/$PAPERCLIP_JAR ]; then
if [ ! -d Paperclip ]; then
echo "Paperclip not found"
exit 1;
fi
echo "Generating Paperclip Jar"
pushd Paperclip
mvn -P '!generate' clean install || exit 1
RESULT_JARS=( target/paperclip*.jar )
if [ ! -f ${RESULT_JARS[0]} ]; then
echo "Couldn't generate paperclip jar" 2>/dev/null;
exit 1;
fi;
cp "${RESULT_JARS[0]}" "$basedir/work/Paperclip/$PAPERCLIP_JAR"
popd
fi;
if [ ! -f work/jbsdiff.jar ]; then
echo "jbsdiff not found"
if [ ! -d work/jbsdiff ]; then
echo "Cloning jbsdiff"
git clone "https://github.com/malensek/jbsdiff.git" work/jbsdiff
if [ ! -d work/jbsdiff ]; then
echo "Failed to clone bsdiff " 2>/dev/null;
exit 1
fi;
fi
echo "Compiling jbsdiff"
pushd work/jbsdiff
mvn clean package || exit 1
RESULT_JARS=( target/jbsdiff*.jar )
if [ ! -f ${RESULT_JARS[0]} ]; then
echo "Couldn't generate jbsdiff jar" 2>/dev/null;
exit 1;
fi;
cp "${RESULT_JARS[0]}" "$basedir/work/jbsdiff.jar"
popd
fi;
INPUT_JAR=$1
VANILLA_JAR=$2
VANILLA_URL=$3
NAME=$4
OUTPUT_JAR=$NAME.jar
PATCH_FILE=$NAME.patch
hash() {
echo "$(sha256sum $1 | sed -E "s/(\S+).*/\1/")"
}
echo "Computing Patch"
java -jar work/jbsdiff.jar diff $VANILLA_JAR $INPUT_JAR work/Paperclip/$PATCH_FILE || exit 1
genJson() {
PATCH=$1
SOURCE_URL=$2
ORIGINAL_HASH=$3
PATCHED_HASH=$4
echo "{"
echo " \"patch\": \"$PATCH\","
echo " \"sourceUrl\": \"$SOURCE_URL\","
echo " \"originalHash\": \"$ORIGINAL_HASH\","
echo " \"patchedHash\": \"$PATCHED_HASH\""
echo "}"
}
echo "Generating Final Jar"
cp work/Paperclip/$PAPERCLIP_JAR work/Paperclip/$OUTPUT_JAR
PATCH_JSON=patch.json
genJson $PATCH_FILE $VANILLA_URL "$(hash $VANILLA_JAR)" "$(hash $INPUT_JAR)" > work/Paperclip/$PATCH_JSON
pushd work/Paperclip
jar uf $OUTPUT_JAR $PATCH_FILE $PATCH_JSON
popd