ldmud-3.2.9/doc/
ldmud-3.2.9/doc/efun/
ldmud-3.2.9/mud/
ldmud-3.2.9/mud/heaven7/
ldmud-3.2.9/mud/heaven7/lib/
ldmud-3.2.9/mud/lp-245/
ldmud-3.2.9/mud/lp-245/banish/
ldmud-3.2.9/mud/lp-245/doc/
ldmud-3.2.9/mud/lp-245/doc/examples/
ldmud-3.2.9/mud/lp-245/doc/sefun/
ldmud-3.2.9/mud/lp-245/log/
ldmud-3.2.9/mud/lp-245/obj/Go/
ldmud-3.2.9/mud/lp-245/players/lars/
ldmud-3.2.9/mud/lp-245/room/death/
ldmud-3.2.9/mud/lp-245/room/maze1/
ldmud-3.2.9/mud/lp-245/room/sub/
ldmud-3.2.9/mud/lp-245/secure/
ldmud-3.2.9/mud/morgengrauen/
ldmud-3.2.9/mud/morgengrauen/lib/
ldmud-3.2.9/mud/sticklib/
ldmud-3.2.9/mud/sticklib/src/
ldmud-3.2.9/mudlib/uni-crasher/
ldmud-3.2.9/pkg/
ldmud-3.2.9/pkg/debugger/
ldmud-3.2.9/pkg/diff/
ldmud-3.2.9/pkg/misc/
ldmud-3.2.9/src/autoconf/
ldmud-3.2.9/src/bugs/
ldmud-3.2.9/src/bugs/MudCompress/
ldmud-3.2.9/src/bugs/b-020916-files/
ldmud-3.2.9/src/bugs/doomdark/
ldmud-3.2.9/src/bugs/ferrycode/ferry/
ldmud-3.2.9/src/bugs/ferrycode/obj/
ldmud-3.2.9/src/bugs/psql/
ldmud-3.2.9/src/done/
ldmud-3.2.9/src/done/order_alist/
ldmud-3.2.9/src/done/order_alist/obj/
ldmud-3.2.9/src/done/order_alist/room/
ldmud-3.2.9/src/gcc/
ldmud-3.2.9/src/gcc/2.7.0/
ldmud-3.2.9/src/gcc/2.7.1/
ldmud-3.2.9/src/hosts/
ldmud-3.2.9/src/hosts/GnuWin32/
ldmud-3.2.9/src/hosts/amiga/NetIncl/
ldmud-3.2.9/src/hosts/amiga/NetIncl/netinet/
ldmud-3.2.9/src/hosts/amiga/NetIncl/sys/
ldmud-3.2.9/src/hosts/i386/
ldmud-3.2.9/src/hosts/msdos/byacc/
ldmud-3.2.9/src/hosts/msdos/doc/
ldmud-3.2.9/src/hosts/os2/
ldmud-3.2.9/src/hosts/win32/
ldmud-3.2.9/src/util/
ldmud-3.2.9/src/util/erq/
ldmud-3.2.9/src/util/indent/hosts/next/
ldmud-3.2.9/src/util/xerq/
ldmud-3.2.9/src/util/xerq/lpc/
ldmud-3.2.9/src/util/xerq/lpc/www/
#!/bin/bash
#######################################################################
#                                                                     #
# Automatically upgrade/downgrade the LDMud-driver                    #
#                                                                     #
# Written by Andre "Guandalug la'Fay" Meiske                          #
#                                                                     #
#######################################################################

# Some global settings
#
# The trailing slash is required for all directory-settings

# Where shall the diff-files be stored?
DIFFDIR=$HOME/src/ldmud-src/

# Where is the driver-source to be found
SRCDIR=$HOME/src/ldmud-cur/

# Where in our Mudlib are the manpages?
MUDDOCDIR=${HOME}/mudlib/doc/man/

# Parameters needed for 'wget' to work properly
WGETPARAMS="-q"

# Name of the setting used to configure the driver
SETTINGNAME=forgottendreams

# Driver-Branch dependent settings:

# a) Development-branch (3.3)

# Where are the patches to be found?
DIFFSOURCE="http://www.bearnip.com/ftp/mud/ldmud-33/"
# what's the prefix/suffix of the diff-files?
# diff-file-name is build as prefix-<oldver>-<newver>.suffix
DIFFPREFIX="diff-33-"
DIFFSUFFIX=".gz"

# b) Current branch (3.2)
# # Where are the patches to be found?
# DIFFSOURCE="http://www.bearnip.com/ftp/mud/ldmud-32/"
# # what's the prefix/suffix of the diff-files?
# # diff-file-name is build as prefix-<oldver>-<newver>.suffix
# DIFFPREFIX="diff-32dev"
# DIFFSUFFIX=".gz"

###################################################################
#
# The script itself

# 
# Find the driver's current version and calculate the name of the
# diff-file we need. in 'reverse' mode we need (current-1)-(current),
# and (current)-(current+1) otherwise 
#
function get_cur_version()
{
  CURRENT=`fgrep "Project-Version" ${SRCDIR}lpmud.prj |\
           cut -d' ' -f4 | cut -d')' -f1`

  if [ "X$1" == "Xreverse" ]; then
    OLD_VER=$((CURRENT-1))
    NEW_VER=$CURRENT
  else
    OLD_VER=$CURRENT
    NEW_VER=$((CURRENT+1))
  fi  
  
  DIFF=${DIFFPREFIX}${OLD_VER}-${NEW_VER}${DIFFSUFFIX}
}

# 
# Check if we already have the patch. Try downloading it via 'wget'
# if not. 
#
# Check again if we have the patch. If not, bail out, otherwise
# apply it. Afterwards copy all changed manpages to the mudlib
# directory, so your mud-internal manuall access system can find them
#
# Unfortunately manpages won't get deleted this way, so every now and then 
# you need check for (re)moved manpages
#

function apply_patch()
{
  # Get the newest patch
  if [ ! -e ${DIFFDIR}${DIFF} ]; then
    cd ${DIFFDIR}
    wget ${WGETPARAMS} ${DIFFSOURCE}${DIFF}
  fi

  # Apply it
  if  [ -e ${DIFFDIR}${DIFF} ]; then
    cd ${SRCDIR}

    zcat ${DIFFDIR}${DIFF} | patch $1 > /dev/null

    # Copy new manpages and other stuff to the mud-directory
    cd ${SRCDIR}doc/
    for file in `find . -mtime -1 -type f`; do
      cp $file ${MUDDOCDIR}$file > /dev/null
    done
    return 1
  fi

  return 2
}


# Main function:

if [ "x$1" == "x-help" ]; then
  echo 'Usage: patch-o-matic [-reverse] [-build|-install]'
  exit 0
fi

if [ "X$1" == "X-reverse" ]; then
  # if '-reverse' is given, downgrade the driver one version
  # (useful for debugging)
  shift;
  get_cur_version "reverse"
  apply_patch "-R -p1"

  if [ $?==1 ]; then
    echo "LDMud backpatched to version $OLD_VER"
  else
    echo "Missing patch, version $CURRENT unchanged"
  fi
else
  # otherwise repeat attempt to upgrade the driver until
  # we don't find any new patches any more
  CHANGED=0
  while (true); do

    get_cur_version "forward"
    apply_patch "-p1"

    if [ $? -eq 2 ]; then
      if [ $CHANGED -eq 1 ]; then
        echo "LDMud patched to version $CURRENT"
      else
        echo "No patch available, version $CURRENT is unchanged."
      fi
      break
    else
      CHANGED=1
    fi
  done
fi

# if '-build' was given on the commandline, change into the 'real'
# sourcedirectory, clean up, apply the given settings and rebuild
# both driver and utils
if [ "X$1" == "X-build" ]; then
  # build the new driver
  cd ${SRCDIR}src
  make distclean
  ${SRCDIR}src/settings/${SETTINGNAME}
  make ldmud utils
fi

# if '-install' was given on the commandline, change into the 'real'
# sourcedirectory, clean up, apply the given settings, rebuild
# both driver and utils and install them directly
if [ "X$1" == "X-install" ]; then
  # build the new driver
  cd ${SRCDIR}src
  make distclean
  ${SRCDIR}src/settings/${SETTINGNAME}
  make ldmud utils install install-utils
fi