Created
February 21, 2010 14:30
-
-
Save hron84/310340 to your computer and use it in GitHub Desktop.
Bulk patch script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
## This code is proteced by Creative Commons Attribution-Share Alike 2.5 Generic licence | |
## Some rights reserved | |
## | |
## @author: Gabor Garami <[email protected]> | |
## @version: 0.2 | |
## @since: 02/2010 | |
PATCHLOG=/tmp/epatch.log | |
#PATCHLOG=/dev/null | |
function _epatch() { | |
local PATCH=$1 | |
local DIR=$2 | |
local DIR=${DIR:-.} | |
local OPTS="-N -E -g0 --no-backup-if-mismatch ${EPATCH_OPTS}" | |
local SUFFIX="${PATCH##*.}" | |
local count=0 | |
case $SUFFIX in | |
bz2) | |
FILTER="bzip2 -dc" | |
;; | |
lzma) | |
FILTER="lzma -dc" | |
;; | |
gz) | |
FILTER="gzip -dc" | |
;; | |
xz) | |
FILTER="xz -dc" | |
;; | |
*) | |
FILTER="cat" | |
;; | |
esac | |
while [ "${count}" -lt 5 ]; do | |
echo " --- Starting patch ${PATCH} " >> ${PATCHLOG} | |
if ${FILTER} ${PATCH} | patch -p${count} ${OPTS} --dry-run -f >> ${PATCHLOG} 2>&1 ; then | |
if ${FILTER} ${PATCH} | patch -p${count} ${OPTS} -d ${DIR} >> ${PATCHLOG} 2>&1; then | |
echo "!!! Found level ${count} !!!" >> ${PATCHLOG} | |
else | |
echo "A dry-run of patch command succeeded, but actually" | |
echo "applying the patch failed!" | |
count=5 | |
fi | |
break | |
fi | |
count=$((count + 1)) | |
done | |
if [ "${count}" -eq 5 ] | |
then | |
echo | |
echo "Failed Patch: ${PATCH} !" | |
echo | |
return 1 | |
fi | |
} | |
if [ "$1" = "-d" ]; then | |
DIR=$2 | |
shift 2 | |
fi | |
for patch in $*; do | |
_epatch ${patch} ${DIR} | |
if [ "$?" -ne "0" ]; then | |
echo " --- Applying patch \"${patch}\" FAILED ---" | tee -a ${PATCHLOG} | |
else | |
echo " --- Applying patch \"${patch}\" succeeded ---" | tee -a ${PATCHLOG} | |
fi | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment