-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatePatches.sh
56 lines (48 loc) · 1.57 KB
/
createPatches.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
#!/bin/bash
# Script heavily based on CraftBukkit's makePatches.sh:
# https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/makePatches.sh
if [ -z "$1" ]
then
echo "Missing clean decompiled sources argument. The clean directory should have been generated by setupWorkspace.sh under 'decompile'"
exit
fi
# https://stackoverflow.com/a/38595160
# https://stackoverflow.com/a/800644
if sed --version >/dev/null 2>&1; then
strip_cr() {
sed -i -- "s/\r//" "$@"
}
else
strip_cr () {
sed -i "" "s/$(printf '\r')//" "$@"
}
fi
clean="$1"
modded="src/main/java"
for file in $modded/**/*
do
# Ignore any of the modded project's source files
if [ $file = "src/main/java/wtf/*" ] || [ -d "$file" ]
then
continue
fi
relativeFileName=${file#"$modded/"}
echo "Diffing $relativeFileName"
strip_cr "$clean/$relativeFileName" > /dev/null
strip_cr "$file" > /dev/null
outFile=$(echo equilinox-patches/"$(echo $relativeFileName | cut -d. -f1)".patch)
patchContents=$(diff -u --label a/$relativeFileName "$clean/$relativeFileName" --label b/$relativeFileName "$file")
if [ -f "$outFile" ]
then
patchContentsCut=$(echo "$patchContents" | tail -n +3)
patchContentOld=$(cat "$outFile" | tail -n +3)
if [ "$patchContentsCut" != "$patchContentOld" ] ; then
echo "$outFile changed"
echo "$patchContents" > "$outFile"
fi
else
mkdir -p "$(dirname $outFile)"
echo "New patch, $outFile"
echo "$patchContents" > "$outFile"
fi
done