#!/bin/sh
# make a patch file of a mysql distribution
# takes as argument the previous version

case $# in
0) echo Usage: $0 previous_version; exit 1;;
esac

PVER=$1;
VER=`grep SERVER_VERSION /my/tmp/BUILD/include/mysql_version.h  | cut -d'"' -f2`
NEWDIR="binary"
NEW="mysql-$VER.tar.gz"
OLD="mysql-$PVER.tar.gz"
RESULT="mysql-$PVER-$VER.patch.gz"
PATCH_DIR=/my/web/Downloads-live/Patches
RESULT_DIR=/my/web/Downloads-live/MySQL-4.0
RESULT_DIR_MAX=/my/web/Downloads-live/MySQL-Max-4.0

if test ! -f $NEWDIR/$NEW
then
  echo "$NEWDIR/$NEW doesn't exist";
  exit 1;
fi

if test ! -f $RESULT_DIR/$OLD
then
  echo "$RESULT_DIR/$OLD doesn't exist";
  exit 1;
fi

mkdir patch
cd patch
gtar xfz ../$NEWDIR/$NEW
gtar xfz $RESULT_DIR/$OLD
cd mysql-$PVER
diff --unified --new-file --recursive . ../mysql-$VER | gzip -9 > ../../$RESULT
cd ../..
/bin/rm -rf patch
chmod a+r,o-w $RESULT binary/*
mv $RESULT $PATCH_DIR
cp binary/mysqlcom-* binary/mysql*win* /net/web/home/production/data/nweb/customer/Downloads
rm binary/mysqlcom-*
mv binary/*Max* binary/*-max* $RESULT_DIR_MAX
cp binary/* $RESULT_DIR
