-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpatch_sources.sh
executable file
·117 lines (94 loc) · 2.28 KB
/
patch_sources.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
#!/bin/bash
export FILTEREDTYPES=".png .svg .ogg .ttf .spec .tilespec .jpg .po .git ChangeLog setup_auth_server.sh .gitignore"
export FILTEREDDIRS="client themes doc graphics .git windows"
# $1 - Version
# $2 - Patch
apply_patch() {
echo "Applying $2"
if ! patch -Nurd -p1 -d "patched/$TGTVERSION" < "$2"
then
echo "Failed to patch $TGTVERSION with \"$2\""
return 1
fi
}
copy_file() {
TGTDIR=$(dirname "$2")
if ! mkdir -p "$TGTDIR"
then
echo "Failed to create directory $TGTDIR" >&2
return 1
fi
if ! cp "$1" "$2" ; then
echo "Failed to copy file $1" >&2
return 1
fi
}
pass_filter() {
case "$(basename $1)" in
# Every Makefile.am must pass
Makefile.am)
return 0 ;;
# Files that configure uses as input must pass
*.in)
return 0 ;;
esac
# Filter by directory hierarchy (client data not needed)
for FILTERENTRY in $FILTEREDDIRS
do
if echo $1 | grep "/$FILTERENTRY/" >/dev/null
then
return 1
fi
done
# Filter by file type (client data not needed)
for FILTERENTRY in $FILTEREDTYPES
do
if echo $1 | grep "$FILTERENTRY\$" >/dev/null
then
return 1
fi
done
return 0
}
if test "$1" = "-h" || test "$1" = "--help" || test "$1" = "" ; then
echo "$(basename $0) <source version> [target version number]"
exit 1
fi
export SRCVERSION="$1"
export TGTVERSION="$2"
if test "$TGTVERSION" = "" ; then
TGTVERSION="$SRCVERSION"
fi
if ! [ -d "src/$SRCVERSION" ] || [ "$SRCVERSION" = "" ]
then
echo "No version \"$SRCVERSION\" sources available as \"src/$SRCVERSION\"" >&2
exit 1
fi
if ! [ -d "patches/$TGTVERSION" ] || [ "$TGTVERSION" = "" ]
then
echo "No version \"$TGTVERSION\" patches available in \"patches/$TGTVERSION\"" >&2
exit 1
fi
rm -Rf "patched/$TGTVERSION"
( cd src/$SRCVERSION && find . -type f ) | grep -v "/\.svn" |
(
while read FILE
do
if pass_filter $FILE ; then
echo "Copying $FILE"
if ! copy_file src/$SRCVERSION/$FILE patched/$TGTVERSION/$FILE
then
exit 1
fi
fi
done
# Build requires ChangeLog, create dummy file.
touch patched/$TGTVERSION/ChangeLog
)
for patch in $(ls -1 patches/$TGTVERSION/*.patch 2>/dev/null | sort )
do
if ! apply_patch "$TGTVERSION" "$patch"
then
exit 1
fi
done