#! /bin/sh
#
# script to install a patch -poptix@WildStar.Net May 1 1997
#

if test "$1" = ""; then
  echo ""
  echo "Usage: addpatch <patch>"
  echo ""
  exit 1
fi
if test ! -r $1; then
  echo ""
  echo "I can't find that patch!"
  echo ""
  exit 1
fi
echo ""
if test -r eggdrop; then ./eggdrop -v
fi
grep "  PATCH(" src/main.c |grep -v snarf |grep -v p1 | grep -v p2| cut -f2 -d "\"" >poptix.tmp
TMP=`tail -n5 poptix.tmp`
echo $TMP
echo ""
echo "These are the last 5 installed patches, If the patch you're "
echo "installing is listed above you probrally don't want to install "
echo "this patch. "
echo -n "Are you sure you want to install the patch? (y/N) "
read ans
echo ""
if test "$ans" = "y"; then
  echo "Copying help files ..."
  patch -lp1 < $1
  echo "Checking for rejects..."
  find . -name "*.rej" -print >tmp.poptix
  if test `grep -c "rej" tmp.poptix` = 0; then
    echo "Yippie! No rejects!"
    else
    echo "It seems I found some rejects :/"
    echo "Now you have a choice.."
    echo "Would you like to:"
    echo "1. Reverse the patch"
    echo "2. List the rejects"
    echo "3. Exit"
    echo -n "Make your choice. (1/2/3) "  
    read opt
    if test "$opt" = "1"; then 
      patch -Rlp1 < $1
      BLAH=`find . -name "*.rej"`
      rm -rf $BLAH
    fi
    if test "$opt" = "2"; then 
      cat tmp.poptix |less
    fi
  fi
  echo "Removing useless *.orig files..."
  TMPVAR=`find . -name "*.orig" -print`
  rm -rf tmp.poptix poptix.tmp $TMPVAR
  echo "Remeber, if you have any compiling problems check out /doc/compiling.FAQ"
else
  echo "Okay, later."
fi

