source: freewrt/scripts/update-patches@ 54f72bc

freewrt_1_0 freewrt_2_0
Last change on this file since 54f72bc was 54f72bc, checked in by Thorsten Glaser <tg@…>, 19 years ago

(cd package/foo; TOPDIR=../.. gmake update-patches) # should now work

IMPORTANT: gmake TOPDIR=../.. foo *does not work* (since it overrides
the correct value which otherwise gets pulled from prereq.mk after it
has been found from the environment-TOPDIR value and gets preference)

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

  • Property mode set to 100644
File size: 4.5 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
33TRANSFORM='sed s/[.+]/\\\\&/g'
34
35mkdir -p $PATCHDIR
36
37SUBDIST=${WRKDIST##${WRKDIR1}?(/)}
38if [[ -n $SUBDIST ]]; then
39 mv ${WRKDIR1}.orig/${SUBDIST} ${WRKDIR1}/${SUBDIST}.orig
40 D_BASE=${WRKDIR1}
41 D_SUB=${SUBDIST}
42 D_CMP=$D_SUB
43else
44 # WRKSRC == WRKDIR
45 D_BASE=$(dirname ${WRKDIR1})
46 D_SUB=$(basename ${WRKDIR1})
47 D_CMP=
48fi
49ORGDIST=${D_BASE}/${D_SUB}.orig
50
51DIFF_FLAGS="-adu -I \"^--- $(echo $D_SUB.orig | $TRANSFORM)@@\""
52DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(echo $D_SUB | $TRANSFORM)@@\""
53
54for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do
55 cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue
56 echo "Processing ${file}..." >&2
57 # look in patchdir for an existing patchfile matching this
58 cd $PATCHDIR
59 for i in $PATCH_LIST; do
60 # Ignore non-files, or old backup
61 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
62
63 # Patch found. Is this the one?
64 if grep "^[+-][+-][+-] $D_CMP[^/]*/$file" "$i" >/dev/null; then
65 # Multiple files in the diff?
66 if [ $(grep -c "^--- $D_CMP" "$i") -gt 1 -o \
67 $(grep -c "^\+\+\+ $D_CMP" "$i") -gt 1 ]; then
68 echo "Cannot process, $i contains patches" >&2
69 echo "to multiple files! Aborting." >&2
70 echo FAIL
71 [[ -n $SUBDIST ]] && mv \
72 ${WRKDIR1}/${SUBDIST}.orig \
73 ${WRKDIR1}.orig/${SUBDIST}
74 exit 0
75 fi
76 # Multiple diffs with this file?
77 let n=0
78 esc=
79 for j in $PATCH_LIST; do
80 [[ ! -f $j || $j = *@(.orig|.rej|~) ]] && \
81 continue
82 grep "^[+-][+-][+-] $D_CMP[^/]*/$file" \
83 "$j" >/dev/null || continue
84 let n++
85 esc="$esc '$j'"
86 done
87 if (( n != 1 )); then
88 echo "Cannot process, file $file" >&2
89 echo "is contained in multiple patches:" >&2
90 echo "$esc" >&2
91 echo FAIL
92 [[ -n $SUBDIST ]] && mv \
93 ${WRKDIR1}/${SUBDIST}.orig \
94 ${WRKDIR1}.orig/${SUBDIST}
95 exit 0
96 fi
97 # No, process this patch
98
99 accounted="$accounted $i"
100 # found it, copy preamble before comparision
101 esc="$(echo "$file" | sed -e 's#/#\\/#g')"
102 ( sed -e "/^--- /,\$d" <$i; \
103 cd $D_BASE && diff -adup \
104 "$D_SUB.orig/$file" "$D_SUB/$file" \
105 ) >"$i.new"
106 # did it change ? mark it as changed
107 tfile="$(echo "$file" | $TRANSFORM)"
108 if eval diff "$(echo "${DIFF_FLAGS}" \
109 | sed "s#@@#${tfile}#g")" \
110 "$i" "$i.new" 1>&2; then
111 rm "$i.new"
112 else
113 echo "Patch $i for $file updated" >&2
114 mv "$i" "$i.orig"
115 mv "$i.new" "$i"
116 edit="$edit $i"
117 fi
118 continue 2
119 fi
120 done
121
122 # Build a sensible name for the new patch file
123 patchname=patch-$(echo "$file" | sed -e 's#[/. ]#_#g')
124 echo "No patch-* found for $file, creating $patchname" >&2
125 ( echo '$Free''WRT$'; \
126 cd $D_BASE && diff -adup "$D_SUB.orig/$file" "$D_SUB/$file" \
127 ) >$patchname
128 edit="$edit $patchname"
129 accounted="$accounted $patchname"
130done
131
132# Verify all patches accounted for
133cd $PATCHDIR
134for i in *; do
135 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
136 grep '^\\ No newline at end of file' $i >/dev/null \
137 && echo "*** Patch $i needs manual intervention" >&2
138 [[ $accounted != *@($i)* ]] \
139 && echo "*** Patch $i not accounted for" >&2
140done
141
142echo $edit
143[[ -n $SUBDIST ]] && mv ${WRKDIR1}/${SUBDIST}.orig ${WRKDIR1}.orig/${SUBDIST}
144exit 0
Note: See TracBrowser for help on using the repository browser.