#!/bin/ksh PATCH=/usr/bin/patch SED="/usr/bin/sed" MESSAGE_FILE=/tmp/PaTcHrM_mEsSaGe_12001x OLD_PATCH_SEPARATOR="___Old_File_Diff_Separator_aBcDeFgHiJkLmN___OjK___5924894_6548915___" PATCH_SAVE_SUFFIX="pre${ACTIVE_PATCH}" get_orig() { cat $1 | \ $SED -ne "1,/${OLD_PATCH_SEPARATOR}/{/${OLD_PATCH_SEPARATOR}/d;p;}" } get_diff() { cat $1 | \ $SED -ne "/${OLD_PATCH_SEPARATOR}/,\${/${OLD_PATCH_SEPARATOR}/d;p;}" } while read src dst ; do realdst="`echo $dst| /bin/sed -e 's/\.old_and_patch$//'`" if [ "$realdst" != "$dst" ]; then cp "${src}" "${dst}" if [ -f "${realdst}" ] ; then get_diff $src | $PATCH -o /dev/null -R $realdst >/dev/null 2>&1 if [ "$?" = "0" ] ; then get_diff $src | $PATCH -R $realdst >/dev/null 2>&1 else get_orig $src > "$realdst.${PATCH_SAVE_SUFFIX}" echo " File $realdst has changed since installation of ${ACTIVE_PATCH}" >> "${MESSAGE_FILE}" echo " Copy of that file as found on the system prior to applying ${ACTIVE_PATCH}" >> "${MESSAGE_FILE}" echo " is stored in $realdst.${PATCH_SAVE_SUFFIX}" >> "${MESSAGE_FILE}" echo " Please, review those files to see whether you wish to undo any changes." >> "${MESSAGE_FILE}" echo >> "${MESSAGE_FILE}" if [ -f "${realdst}.rej" ] ; then rm -f "${realdst}.rej" fi fi else get_orig $src > $realdst fi fi done exit 0