3 # Thorsten Glaser <tg@freewrt.org>
5 # Derived from the MirPorts Framework "update-patches" script:
7 # Copyright (c) 2003, 2004, 2005
8 # Thorsten "mirabile" Glaser <tg@MirBSD.de>
9 # Based upon code and idea (c) 2000
10 # Marc Espie for the OpenBSD project. All rights reserved.
12 # Provided that these terms and disclaimer and all copyright notices
13 # are retained or reproduced in an accompanying document, permission
14 # is granted to deal in this work without restriction, including un-
15 # limited rights to use, publicly perform, distribute, sell, modify,
16 # merge, give away, or sublicence.
18 # This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
19 # the utmost extent permitted by applicable law, neither express nor
20 # implied; without malicious intent or gross negligence. In no event
21 # may a licensor, author or contributor be held liable for indirect,
22 # direct, other damage, loss, or other issues arising in any way out
23 # of dealing in the work, even if advised of the possibility of such
24 # damage or existence of a defect, except proven that it results out
25 # of said person's immediate fault when using the work as intended.
27 [[ -n $BASH_VERSION ]] && shopt -s extglob
34 if [[ ! -e $f1 ]]; then
35 [[ -d ${f1%/*}/.
]] || mkdir
-p ${f1%/*}
36 if [[ ! -s $f2 ]]; then
38 --- $f1 (non-existant)
44 touch -t 197001010000.00 "$f1"
46 diff -adup "$f1" "$f2"
50 TRANSFORM
='sed s/[.+]/\\\\&/g'
51 PATCHDIR
=$CURDIR/patches
52 EXTRADIR
=$CURDIR/extra
56 SUBDIST
=${WRKDIST##${WRKDIR1}?(/)}
57 if [[ -n $SUBDIST ]]; then
58 mv ${WRKDIR1}.orig/${SUBDIST} ${WRKDIR1}/${SUBDIST}.orig
66 D_BASE
=$
(dirname ${WRKDIR1})
67 D_SUB
=$
(basename ${WRKDIR1})
71 ORGDIST
=${D_BASE}/${D_SUB}.orig
73 if [[ -e $WRKDIST/.patched-newfiles
]]; then
74 touch $ORGDIST/.patched-newfiles
80 DIFF_FLAGS
="-adu -I \"^--- $(echo $D_SUBP.orig/ | $TRANSFORM)@@ .*\""
81 DIFF_FLAGS
="$DIFF_FLAGS -I \"^\+\+\+ $(echo $D_SUBP/ | $TRANSFORM)@@ .*\""
83 for file in $
(cd ${WRKDIST}; find .
-type f |
sed 's#^\./##'); do
84 [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue
85 cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue
86 echo "Processing ${file}..." >&2
87 # look in patchdir for an existing patchfile matching this
89 for i
in $PATCH_LIST; do
90 # Ignore non-files, or old backup
91 [[ ! -f $i ||
$i = *@
(.orig|.rej|~
) ]] && continue
93 # Patch found. Is this the one?
94 if grep "^[+-][+-][+-] $D_CMP[^/]*/$file " "$i" >/dev
/null
; then
95 # Multiple files in the diff?
96 if [ $
(grep -c "^--- $D_CMP" "$i") -gt 1 -o \
97 $
(grep -c "^+++ $D_CMP" "$i") -gt 1 ]; then
98 echo "Cannot process, $i contains patches" >&2
99 echo "to multiple files! Aborting." >&2
101 [[ -n $SUBDIST ]] && mv \
102 ${WRKDIR1}/${SUBDIST}.orig \
103 ${WRKDIR1}.orig
/${SUBDIST}
106 # Multiple diffs with this file?
109 for j
in $PATCH_LIST; do
110 [[ ! -f $j ||
$j = *@
(.orig|.rej|~
) ]] && \
112 grep "^[+-][+-][+-] $D_CMP[^/]*/$file " \
113 "$j" >/dev
/null ||
continue
117 if (( n
!= 1 )); then
118 echo "Cannot process, file $file" >&2
119 echo "is contained in multiple patches:" >&2
122 [[ -n $SUBDIST ]] && mv \
123 ${WRKDIR1}/${SUBDIST}.orig \
124 ${WRKDIR1}.orig
/${SUBDIST}
127 # No, process this patch
129 accounted
="$accounted $i"
130 # found it, copy preamble before comparision
131 ( sed -e "/^--- /,\$d" <$i; \
132 cd $D_BASE && do_diff
"$file" "$D_SUB.orig" "$D_SUB" \
134 # did it change ? mark it as changed
135 tfile
="$(echo "$file" | $TRANSFORM)"
136 if eval diff "$(echo "${DIFF_FLAGS}" \
137 | sed "s
#@@#${tfile}#g")" \
138 "$i" "$i.new" 1>&2; then
141 echo "Patch $i for $file updated" >&2
150 # Build a sensible name for the new patch file
151 patchname
=patch-$
(echo "$file" |
sed -e 's#[/. ]#_#g')
152 echo "No patch-* found for $file, creating $patchname" >&2
153 ( cd $D_BASE && do_diff
"$file" "$D_SUB.orig" "$D_SUB" ) >$patchname
154 edit
="$edit $patchname"
155 accounted
="$accounted $patchname"
158 # Verify all patches accounted for
161 [[ ! -f $i ||
$i = *@
(.orig|.rej|~
) ]] && continue
162 grep '^\\ No newline at end of file' $i >/dev
/null \
163 && echo "*** Patch $i needs manual intervention" >&2
164 [[ $accounted != *@
($i)* ]] \
165 && echo "*** Patch $i not accounted for" >&2
169 [[ -n $SUBDIST ]] && mv ${WRKDIR1}/${SUBDIST}.orig ${WRKDIR1}.orig/${SUBDIST}