1#!/bin/sh 2 3# $MidnightBSD: mports/Tools/scripts/update-patches,v 1.3 2011/03/20 00:07:21 laffer1 Exp $ 4# $OpenBSD: update-patches,v 1.3 2000/06/09 17:08:37 espie Exp $ 5# Copyright (c) 2000 6# Marc Espie. All rights reserved. 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Neither the name of OpenBSD nor the names of its contributors 13# may be used to endorse or promote products derived from this software 14# without specific prior written permission. 15# 16# THIS SOFTWARE IS PROVIDED BY ITS AUTHOR AND THE OpenBSD project ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27 28# Find out all .orig files and strip the name to what diff will use 29cd $PATCH_WRKSRC && find . -type f -name '*.orig' | fgrep -v $DISTORIG | \ 30sed -e "s,^./\(.*\)\.orig\$,\1," | { 31while read file 32do 33 echo 1>&2 "Processing $file" 34 # look in patchdir for an existing patchfile matching this 35 mkdir -p $PATCHDIR 36 cd $PATCHDIR 37 for i in ${PATCH_LIST} 38 do 39 # Ignore non-files, or old backup 40 [ -f $i ] || continue 41 case $i in \ 42 *.orig|*.rej|*~) ;; 43 *) # Patch found. Is this the one ? 44 if grep "^--- $file.orig" $i >/dev/null 45 then 46 accounted="$accounted $i" 47 # found it, splice before diff part with diff 48 esc=`echo $file | sed -e 's,/,\\\\/,g'` 49 { sed -e "/^--- $esc.orig/,\$ d" <$i 50 (cd $PATCH_WRKSRC && diff -p ${DIFF_ARGS} -u $file.orig $file) } >$i.new 51 # did it change ? mark it as changed 52 if diff ${DIFF_ARGS} -u --ignore-matching-lines="^--- $file.orig .*" \ 53 --ignore-matching-lines="^+++ $file .*" $i $i.new 1>&2 54 then 55 rm $i.new 56 else 57 echo 1>&2 "Patch $i for $file updated" 58 mv $i $i.orig 59 mv $i.new $i 60 edit="$edit $i" 61 fi 62 continue 2 63 fi;; 64 esac 65 done 66 # Build a sensible name for the patch file 67 patchname=patch-`echo $file|sed -e s,/,_,g` 68 echo 1>&2 "No patch-* found for $file, creating $patchname" 69 (cd $PATCH_WRKSRC && diff -p ${DIFF_ARGS} -u $file.orig $file) >$patchname 70 edit="$edit $patchname" 71 accounted="$accounted $patchname" 72done 73 74# Verify all patches accounted for 75for i in ${PATCHDIR}/* 76do 77 [ -f $i ] || continue 78 case $i in \ 79 *.orig|*.rej|*~) ;; 80 *) 81 for j in $accounted 82 do 83 if [ $j = $i ] 84 then 85 continue 2 86 fi 87 done 88 echo 1>&2 "*** Patch $i not accounted for.";; 89 esac 90done 91 92# Check for $Id and similar bugs in all those patch files. 93for i in $accounted 94do 95 if sed -e '/1,^---/ d' $i|egrep '$(Id|FreeBSD|MidnightBSD)' 96 then 97 echo 1>&2 "Problem with $i: CVS tag found in patch" 98 fi 99done 100 101find ${PATCHDIR} -size 0c | xargs rm 102 103echo $edit 104} 105exit 0 106