source: freewrt/scripts/update-patches@ daec02d

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

freewrtify a little

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

  • Property mode set to 100644
File size: 3.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# 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.
11#
12# Licensee is hereby permitted to deal in this work without restric-
13# tion, including unlimited rights to use, publicly perform, modify,
14# merge, distribute, sell, give away or sublicence, provided all co-
15# pyright notices above, these terms and the disclaimer are retained
16# in all redistributions or reproduced in accompanying documentation
17# or other materials provided with binary redistributions.
18#
19# Licensor offers the work "AS IS" and WITHOUT WARRANTY of any kind,
20# express, or implied, to the maximum extent permitted by applicable
21# law, without malicious intent or gross negligence; in no event may
22# licensor, an author or contributor be held liable for any indirect
23# or other damage, or direct damage except proven a consequence of a
24# direct error of said person and intended use of this work, loss or
25# other issues arising in any way out of its use, even if advised of
26# the possibility of such damage or existence of a nontrivial bug.
27
28shopt -s extglob
29
30TRANSFORM='sed s/[.+]/\\\\&/g'
31tfile=$(echo "$PATCHORIG" | $TRANSFORM)
32DIFF_FLAGS="-adu -I \"^--- @@$(echo "$tfile") \""
33DIFF_FLAGS="${DIFF_FLAGS} -I \"^\+\+\+ @@ \""
34
35mkdir -p $PATCHDIR
36
37
38# Find out all $PATCHORIG files and strip the name to what diff will use
39( cd $WRKDIST && find . -type f -name "*${PATCHORIG}" \
40 | fgrep -v $DISTORIG | sed -e "s#^./\(.*\)\.${PATCHORIG#.*}\$#\1#" \
41) |&
42
43while read -p file; do
44 if cmp -s "$WRKDIST/$file" "$WRKDIST/$file$PATCHORIG"; then
45 echo "$file and $file$PATCHORIG are identical" >&2
46 continue
47 fi
48 if [[ ! -f $WRKDIST/$file ]]; then
49 echo "$file does not exist" >&2
50 continue
51 fi
52 echo "Processing ${file}..." >&2
53 # look in patchdir for an existing patchfile matching this
54 cd $PATCHDIR
55 for i in $PATCH_LIST; do
56 # Ignore non-files, or old backup
57 [[ ! -f $i || $i = *@(${PATCHORIG}|.rej|~) ]] \
58 && continue
59
60 # Patch found. Is this the one?
61 if grep "^--- $file$PATCHORIG" "$i" >/dev/null; then
62 accounted="$accounted $i"
63 # found it, copy preamble before comparision
64 esc="$(echo "$file" | sed -e 's#/#\\/#g')"
65 ( sed -e "/^--- $esc$PATCHORIG/,\$d" <$i; \
66 cd $WRKDIST && diff -adup \
67 ${DIFF_ARGS} "$file$PATCHORIG" "$file" \
68 ) >"$i.new"
69 # did it change ? mark it as changed
70 tfile="$(echo "$file" | $TRANSFORM)"
71 if eval diff "$(echo "${DIFF_FLAGS}" \
72 ${DIFF_ARGS} | sed "s#@@#${tfile}#g")" \
73 "$i" "$i.new" 1>&2; then
74 rm "$i.new"
75 else
76 echo "Patch $i for $file updated" >&2
77 mv "$i" "$i$PATCHORIG"
78 mv "$i.new" "$i"
79 edit="$edit $i"
80 fi
81 continue 2
82 fi
83 done
84
85 # Build a sensible name for the new patch file
86 patchname=patch-$(echo "$file" | sed -e 's#[/. ]#_#g')
87 echo "No patch-* found for $file, creating $patchname" >&2
88 ( echo '$Free''WRT$'; \
89 cd $WRKDIST && diff -adup ${DIFF_ARGS} "$file$PATCHORIG" "$file" \
90 ) >$patchname
91 edit="$edit $patchname"
92 accounted="$accounted $patchname"
93done
94
95# Verify all patches accounted for
96cd $PATCHDIR
97for i in *; do
98 [[ ! -f $i || $i = *@(${PATCHORIG}|.rej|~) ]] \
99 && continue
100 grep '^\\ No newline at end of file' $i >/dev/null \
101 && echo "*** Patch $i needs manual intervention" >&2
102 [[ $accounted != *@($i)* ]] \
103 && echo "*** Patch $i not accounted for" >&2
104done
105
106echo $edit
107exit 0
Note: See TracBrowser for help on using the repository browser.