source: freewrt/scripts/update-patches@ 382b81d

Last change on this file since 382b81d 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
RevLine 
[daec02d]1#!/usr/bin/env bash
[8f30051]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>
[54f72bc]7#
8# Derived from the MirPorts Framework "update-patches" script:
9#
[8f30051]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#
[b9492d5]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.
[8f30051]20#
[b9492d5]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.
[8f30051]29
[daec02d]30shopt -s extglob
[8f30051]31
[24dce9d]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
[daec02d]52TRANSFORM='sed s/[.+]/\\\\&/g'
[aee909e]53PATCHDIR=$CURDIR/patches
54EXTRADIR=$CURDIR/extra
[8f30051]55
56mkdir -p $PATCHDIR
57
[54f72bc]58SUBDIST=${WRKDIST##${WRKDIR1}?(/)}
59if [[ -n $SUBDIST ]]; then
60 mv ${WRKDIR1}.orig/${SUBDIST} ${WRKDIR1}/${SUBDIST}.orig
61 D_BASE=${WRKDIR1}
62 D_SUB=${SUBDIST}
[54282b2]63# D_SUBP=$D_SUB
64 D_SUBP='[^/]*'
65 D_CMP=$D_SUBP
[54f72bc]66else
67 # WRKSRC == WRKDIR
68 D_BASE=$(dirname ${WRKDIR1})
69 D_SUB=$(basename ${WRKDIR1})
[54282b2]70 D_SUBP=$D_SUB
[54f72bc]71 D_CMP=
72fi
73ORGDIST=${D_BASE}/${D_SUB}.orig
[8f30051]74
[aee909e]75[[ -d $EXTRADIR ]] && \
76 (cd $EXTRADIR; find . -print0) | \
77 (cd $WRKDIST; pax -rw -0 -d $ORGDIST/) >/dev/null 2>&1
78
[f266cab]79if [[ -e $WRKDIST/.patched-newfiles ]]; then
80 touch $ORGDIST/.patched-newfiles
81 patch_newfiles=1
82else
83 patch_newfiles=0
84fi
85
[54282b2]86DIFF_FLAGS="-adu -I \"^--- $(echo $D_SUBP.orig/ | $TRANSFORM)@@ .*\""
87DIFF_FLAGS="$DIFF_FLAGS -I \"^\+\+\+ $(echo $D_SUBP/ | $TRANSFORM)@@ .*\""
[8f30051]88
[54f72bc]89for file in $(cd ${WRKDIST}; find . -type f | sed 's#^\./##'); do
[f266cab]90 [[ ! -e $ORGDIST/$file && $patch_newfiles = 0 ]] && continue
[54f72bc]91 cmp -s "$ORGDIST/$file" "$WRKDIST/$file" && continue
[daec02d]92 echo "Processing ${file}..." >&2
[8f30051]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
[54f72bc]97 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
[8f30051]98
99 # Patch found. Is this the one?
[24dce9d]100 if grep "^[+-][+-][+-] $D_CMP[^/]*/$file " "$i" >/dev/null; then
[54f72bc]101 # Multiple files in the diff?
102 if [ $(grep -c "^--- $D_CMP" "$i") -gt 1 -o \
[ee2a32c]103 $(grep -c "^+++ $D_CMP" "$i") -gt 1 ]; then
[54f72bc]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
[24dce9d]114 pflst=
[54f72bc]115 for j in $PATCH_LIST; do
116 [[ ! -f $j || $j = *@(.orig|.rej|~) ]] && \
117 continue
[24dce9d]118 grep "^[+-][+-][+-] $D_CMP[^/]*/$file " \
[54f72bc]119 "$j" >/dev/null || continue
120 let n++
[24dce9d]121 pflst="$pflst '$j'"
[54f72bc]122 done
123 if (( n != 1 )); then
124 echo "Cannot process, file $file" >&2
125 echo "is contained in multiple patches:" >&2
[24dce9d]126 echo "$pflst" >&2
[54f72bc]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
[8f30051]135 accounted="$accounted $i"
136 # found it, copy preamble before comparision
[54f72bc]137 ( sed -e "/^--- /,\$d" <$i; \
[24dce9d]138 cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
[8f30051]139 ) >"$i.new"
140 # did it change ? mark it as changed
[daec02d]141 tfile="$(echo "$file" | $TRANSFORM)"
142 if eval diff "$(echo "${DIFF_FLAGS}" \
[54f72bc]143 | sed "s#@@#${tfile}#g")" \
[8f30051]144 "$i" "$i.new" 1>&2; then
145 rm "$i.new"
146 else
[daec02d]147 echo "Patch $i for $file updated" >&2
[54f72bc]148 mv "$i" "$i.orig"
[8f30051]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
[daec02d]157 patchname=patch-$(echo "$file" | sed -e 's#[/. ]#_#g')
158 echo "No patch-* found for $file, creating $patchname" >&2
159 ( echo '$Free''WRT$'; \
[24dce9d]160 cd $D_BASE && do_diff "$file" "$D_SUB.orig" "$D_SUB" \
[8f30051]161 ) >$patchname
162 edit="$edit $patchname"
163 accounted="$accounted $patchname"
164done
165
166# Verify all patches accounted for
167cd $PATCHDIR
168for i in *; do
[54f72bc]169 [[ ! -f $i || $i = *@(.orig|.rej|~) ]] && continue
[8f30051]170 grep '^\\ No newline at end of file' $i >/dev/null \
[daec02d]171 && echo "*** Patch $i needs manual intervention" >&2
[8f30051]172 [[ $accounted != *@($i)* ]] \
[daec02d]173 && echo "*** Patch $i not accounted for" >&2
[8f30051]174done
175
[daec02d]176echo $edit
[54f72bc]177[[ -n $SUBDIST ]] && mv ${WRKDIR1}/${SUBDIST}.orig ${WRKDIR1}.orig/${SUBDIST}
[8f30051]178exit 0
Note: See TracBrowser for help on using the repository browser.