source: freewrt/scripts/update-patches@ 24dce9d

freewrt_1_0 freewrt_2_0
Last change on this file since 24dce9d was 24dce9d, checked in by Thorsten Glaser <tg@…>, 19 years ago
  • remove unused variable
  • fix variable name
  • fix files with same starting name (e.g. Makefile vs Makefile.in)
  • fix generation of patches for new files
  • allow creation of patches for new empty files

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

  • Property mode set to 100644
File size: 4.7 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# Licensee is hereby permitted to deal in this work without restric-
16# tion, including unlimited rights to use, publicly perform, modify,
17# merge, distribute, sell, give away or sublicence, provided all co-
18# pyright notices above, these terms and the disclaimer are retained
19# in all redistributions or reproduced in accompanying documentation
20# or other materials provided with binary redistributions.
21#
22# Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
23# express, or implied, to the maximum extent permitted by applicable
24# law, without malicious intent or gross negligence; in no event may
25# licensor, an author or contributor be held liable for any indirect
26# or other damage, or direct damage except proven a consequence of a
27# direct error of said person and intended use of this work, loss or
28# other issues arising in any way out of its use, even if advised of
29# the possibility of such damage or existence of a nontrivial bug.
30
31shopt -s extglob
32
33do_diff()
34{
35 local f1=$2/$1
36 local f2=$3/$1
37
38 if [[ ! -e $f1 ]]; then
39 if [[ ! -s $f2 ]]; then
40 cat <<EOF
41--- $f1 (non-existant)
42+++ $f2 (empty)
43@@ -0,0 +0,0 @@
44EOF
45 return 0
46 fi
47 touch -t 197001010000.00 "$f1"
48 fi
49 diff -adup "$f1" "$f2"
50 return $?
51}
52
53TRANSFORM='sed s/[.+]/\\\\&/g'
54
55mkdir -p $PATCHDIR
56
57SUBDIST=${WRKDIST##${WRKDIR1}?(/)}
58if [[ -n $SUBDIST ]]; then
59 mv ${WRKDIR1}.orig/${SUBDIST} ${WRKDIR1}/${SUBDIST}.orig
60 D_BASE=${WRKDIR1}
61 D_SUB=${SUBDIST}
62 D_CMP=$D_SUB
63else
64 # WRKSRC == WRKDIR
65 D_BASE=$(dirname ${WRKDIR1})
66 D_SUB=$(basename ${WRKDIR1})
67 D_CMP=
68fi
69ORGDIST=${D_BASE}/${D_SUB}.orig
70
71DIFF_FLAGS="-adu -I \"^--- $(echo $D_SUB.orig/ | $TRANSFORM)@@ .*\""
72DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(echo $D_SUB/ | $TRANSFORM)@@ .*\""
73
74for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do
75 cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue
76 echo "Processing ${file}..." >&2
77 # look in patchdir for an existing patchfile matching this
78 cd $PATCHDIR
79 for i in $PATCH_LIST; do
80 # Ignore non-files, or old backup
81 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
82
83 # Patch found. Is this the one?
84 if grep "^[+-][+-][+-] $D_CMP[^/]*/$file " "$i" >/dev/null; then
85 # Multiple files in the diff?
86 if [ $(grep -c "^--- $D_CMP" "$i") -gt 1 -o \
87 $(grep -c "^\+\+\+ $D_CMP" "$i") -gt 1 ]; then
88 echo "Cannot process, $i contains patches" >&2
89 echo "to multiple files! Aborting." >&2
90 echo FAIL
91 [[ -n $SUBDIST ]] && mv \
92 ${WRKDIR1}/${SUBDIST}.orig \
93 ${WRKDIR1}.orig/${SUBDIST}
94 exit 0
95 fi
96 # Multiple diffs with this file?
97 let n=0
98 pflst=
99 for j in $PATCH_LIST; do
100 [[ ! -f $j || $j = *@(.orig|.rej|~) ]] && \
101 continue
102 grep "^[+-][+-][+-] $D_CMP[^/]*/$file " \
103 "$j" >/dev/null || continue
104 let n++
105 pflst="$pflst '$j'"
106 done
107 if (( n != 1 )); then
108 echo "Cannot process, file $file" >&2
109 echo "is contained in multiple patches:" >&2
110 echo "$pflst" >&2
111 echo FAIL
112 [[ -n $SUBDIST ]] && mv \
113 ${WRKDIR1}/${SUBDIST}.orig \
114 ${WRKDIR1}.orig/${SUBDIST}
115 exit 0
116 fi
117 # No, process this patch
118
119 accounted="$accounted $i"
120 # found it, copy preamble before comparision
121 ( sed -e "/^--- /,\$d" <$i; \
122 cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
123 ) >"$i.new"
124 # did it change ? mark it as changed
125 tfile="$(echo "$file" | $TRANSFORM)"
126 if eval diff "$(echo "${DIFF_FLAGS}" \
127 | sed "s#@@#${tfile}#g")" \
128 "$i" "$i.new" 1>&2; then
129 rm "$i.new"
130 else
131 echo "Patch $i for $file updated" >&2
132 mv "$i" "$i.orig"
133 mv "$i.new" "$i"
134 edit="$edit $i"
135 fi
136 continue 2
137 fi
138 done
139
140 # Build a sensible name for the new patch file
141 patchname=patch-$(echo "$file" | sed -e 's#[/. ]#_#g')
142 echo "No patch-* found for $file, creating $patchname" >&2
143 ( echo '$Free''WRT$'; \
144 cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
145 ) >$patchname
146 edit="$edit $patchname"
147 accounted="$accounted $patchname"
148done
149
150# Verify all patches accounted for
151cd $PATCHDIR
152for i in *; do
153 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
154 grep '^\\ No newline at end of file' $i >/dev/null \
155 && echo "*** Patch $i needs manual intervention" >&2
156 [[ $accounted != *@($i)* ]] \
157 && echo "*** Patch $i not accounted for" >&2
158done
159
160echo $edit
161[[ -n $SUBDIST ]] && mv ${WRKDIR1}/${SUBDIST}.orig ${WRKDIR1}.orig/${SUBDIST}
162exit 0
Note: See TracBrowser for help on using the repository browser.