source: freewrt/scripts/update-patches@ 54282b2

Last change on this file since 54282b2 was 54282b2, checked in by Thorsten Glaser <tg@…>, 19 years ago

second try to fix this script updating patches it shouldn't need to
because only the patch header changed

git-svn-id: svn://www.freewrt.org/trunk/freewrt@2020 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 5.0 KB
Line 
1#!/usr/bin/env bash
2# $FreeWRT$
3# $MirOS: ports/infrastructure/scripts/update-patches,v 1.5 2006/06/15 19:18:43 tg Exp $
4#-
5# Copyright (c) 2006
6# Thorsten Glaser <tg@freewrt.org>
7#
8# Derived from the MirPorts Framework "update-patches" script:
9#
10# Copyright (c) 2003, 2004, 2005
11# Thorsten "mirabile" Glaser <tg@MirBSD.de>
12# Based upon code and idea (c) 2000
13# Marc Espie for the OpenBSD project. All rights reserved.
14#
15# Provided that these terms and disclaimer and all copyright notices
16# are retained or reproduced in an accompanying document, permission
17# is granted to deal in this work without restriction, including un-
18# limited rights to use, publicly perform, distribute, sell, modify,
19# merge, give away, or sublicence.
20#
21# This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
22# the utmost extent permitted by applicable law, neither express nor
23# implied; without malicious intent or gross negligence. In no event
24# may a licensor, author or contributor be held liable for indirect,
25# direct, other damage, loss, or other issues arising in any way out
26# of dealing in the work, even if advised of the possibility of such
27# damage or existence of a defect, except proven that it results out
28# of said person's immediate fault when using the work as intended.
29
30shopt -s extglob
31
32do_diff()
33{
34 local f1=$2/$1
35 local f2=$3/$1
36
37 if [[ ! -e $f1 ]]; then
38 if [[ ! -s $f2 ]]; then
39 cat <<EOF
40--- $f1 (non-existant)
41+++ $f2 (empty)
42@@ -0,0 +0,0 @@
43EOF
44 return 0
45 fi
46 touch -t 197001010000.00 "$f1"
47 fi
48 diff -adup "$f1" "$f2"
49 return $?
50}
51
52TRANSFORM='sed s/[.+]/\\\\&/g'
53PATCHDIR=$CURDIR/patches
54EXTRADIR=$CURDIR/extra
55
56mkdir -p $PATCHDIR
57
58SUBDIST=${WRKDIST##${WRKDIR1}?(/)}
59if [[ -n $SUBDIST ]]; then
60 mv ${WRKDIR1}.orig/${SUBDIST} ${WRKDIR1}/${SUBDIST}.orig
61 D_BASE=${WRKDIR1}
62 D_SUB=${SUBDIST}
63# D_SUBP=$D_SUB
64 D_SUBP='[^/]*'
65 D_CMP=$D_SUBP
66else
67 # WRKSRC == WRKDIR
68 D_BASE=$(dirname ${WRKDIR1})
69 D_SUB=$(basename ${WRKDIR1})
70 D_SUBP=$D_SUB
71 D_CMP=
72fi
73ORGDIST=${D_BASE}/${D_SUB}.orig
74
75[[ -d $EXTRADIR ]] && \
76 (cd $EXTRADIR; find . -print0) | \
77 (cd $WRKDIST; pax -rw -0 -d $ORGDIST/) >/dev/null 2>&1
78
79if [[ -e $WRKDIST/.patched-newfiles ]]; then
80 touch $ORGDIST/.patched-newfiles
81 patch_newfiles=1
82else
83 patch_newfiles=0
84fi
85
86DIFF_FLAGS="-adu -I \"^--- $(echo $D_SUBP.orig/ | $TRANSFORM)@@ .*\""
87DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(echo $D_SUBP/ | $TRANSFORM)@@ .*\""
88
89for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do
90 [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue
91 cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue
92 echo "Processing ${file}..." >&2
93 # look in patchdir for an existing patchfile matching this
94 cd $PATCHDIR
95 for i in $PATCH_LIST; do
96 # Ignore non-files, or old backup
97 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
98
99 # Patch found. Is this the one?
100 if grep "^[+-][+-][+-] $D_CMP[^/]*/$file " "$i" >/dev/null; then
101 # Multiple files in the diff?
102 if [ $(grep -c "^--- $D_CMP" "$i") -gt 1 -o \
103 $(grep -c "^+++ $D_CMP" "$i") -gt 1 ]; then
104 echo "Cannot process, $i contains patches" >&2
105 echo "to multiple files! Aborting." >&2
106 echo FAIL
107 [[ -n $SUBDIST ]] && mv \
108 ${WRKDIR1}/${SUBDIST}.orig \
109 ${WRKDIR1}.orig/${SUBDIST}
110 exit 0
111 fi
112 # Multiple diffs with this file?
113 let n=0
114 pflst=
115 for j in $PATCH_LIST; do
116 [[ ! -f $j || $j = *@(.orig|.rej|~) ]] && \
117 continue
118 grep "^[+-][+-][+-] $D_CMP[^/]*/$file " \
119 "$j" >/dev/null || continue
120 let n++
121 pflst="$pflst '$j'"
122 done
123 if (( n != 1 )); then
124 echo "Cannot process, file $file" >&2
125 echo "is contained in multiple patches:" >&2
126 echo "$pflst" >&2
127 echo FAIL
128 [[ -n $SUBDIST ]] && mv \
129 ${WRKDIR1}/${SUBDIST}.orig \
130 ${WRKDIR1}.orig/${SUBDIST}
131 exit 0
132 fi
133 # No, process this patch
134
135 accounted="$accounted $i"
136 # found it, copy preamble before comparision
137 ( sed -e "/^--- /,\$d" <$i; \
138 cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
139 ) >"$i.new"
140 # did it change ? mark it as changed
141 tfile="$(echo "$file" | $TRANSFORM)"
142 if eval diff "$(echo "${DIFF_FLAGS}" \
143 | sed "s#@@#${tfile}#g")" \
144 "$i" "$i.new" 1>&2; then
145 rm "$i.new"
146 else
147 echo "Patch $i for $file updated" >&2
148 mv "$i" "$i.orig"
149 mv "$i.new" "$i"
150 edit="$edit $i"
151 fi
152 continue 2
153 fi
154 done
155
156 # Build a sensible name for the new patch file
157 patchname=patch-$(echo "$file" | sed -e 's#[/. ]#_#g')
158 echo "No patch-* found for $file, creating $patchname" >&2
159 ( echo '$Free''WRT$'; \
160 cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
161 ) >$patchname
162 edit="$edit $patchname"
163 accounted="$accounted $patchname"
164done
165
166# Verify all patches accounted for
167cd $PATCHDIR
168for i in *; do
169 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
170 grep '^\\ No newline at end of file' $i >/dev/null \
171 && echo "*** Patch $i needs manual intervention" >&2
172 [[ $accounted != *@($i)* ]] \
173 && echo "*** Patch $i not accounted for" >&2
174done
175
176echo $edit
177[[ -n $SUBDIST ]] && mv ${WRKDIR1}/${SUBDIST}.orig ${WRKDIR1}.orig/${SUBDIST}
178exit 0
Note: See TracBrowser for help on using the repository browser.