applying patches

Roman Duka rduka@mail.ru
Thu Jan 29 18:15:00 GMT 2004


Hey guys, i thought i might share with you on how to write a script 
which will apply most patches
Sometimes when you issue "patch" command, you need to specify "-p<num>" 
argument, where <num> is usually 0 or 1. The problem is you're can't be 
sure which <num> will be successful. So here is a little loop which 
resolves this problem (i had to rewrite it slightly just now, so there 
might be a few errors, test it first, however i've just looked at it 
several times and it seems fine)

#look for files that contain pattern "patch" after a dot
for i in `ls $SRCDIR/patches/$patchdir/*.*patch*`
do
     #make sure it's a regular file and not a directory or anything else
     if test -f $i
     then
         success=no
         echo "Trying patch file: $i"
         for pnum in 0 1 2 3 4 5
         do
             #trying each number up to 5
             patch -p$pnum -f --dry-run < $i > /dev/null
             if test $? -eq 0
             then
                 patch -p$pnum -f < $i
                 success=yes
                 break
             fi
         done
         if test x$success = xno
         then
             echo "Patch failed: $i"
         fi
     fi
done


Hope this will make it easy for you to apply all sorts of patches 
automatically in your shell scripts



------
Want more information?  See the CrossGCC FAQ, http://www.objsw.com/CrossGCC/
Want to unsubscribe? Send a note to crossgcc-unsubscribe@sources.redhat.com



More information about the crossgcc mailing list