#!/bin/sh
#
# This script makes a patch distribution for basesuif given two
# gzipped tar files, one for the old distribution and one for the new
# distribution.
#
# usage: make_basesuif_patch_distr <old-version> <new-version>
#


if test ${1}"" = "" ; then
    echo "no old-version specified" 1>&2
    exit 1
fi

if test ${2}"" = "" ; then
    echo "no new-version specified" 1>&2
    exit 1
fi


old_version=${1}
new_version=${2}


package_name=basesuif
olddir=${package_name}-${old_version}
newdir=${package_name}-${new_version}
patchfile=${olddir}-to-${new_version}.patch



if test '!' -f ${olddir}.tar.gz ; then
    echo "Cannot find distribution file ${olddir}.tar.gz" 1>&2
    exit 1
fi

if test '!' -f ${newdir}.tar.gz ; then
    echo "Cannot find distribution file ${newdir}.tar.gz" 1>&2
    exit 1
fi



echo gunzip ${olddir}.tar.gz
gunzip ${olddir}.tar.gz
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo gunzip ${newdir}.tar.gz
gunzip ${newdir}.tar.gz
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo tar xf ${olddir}.tar
tar xf ${olddir}.tar
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo tar xf ${newdir}.tar
tar xf ${newdir}.tar
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo rm -f ${olddir}.tar
rm -f ${olddir}.tar
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo rm -f ${newdir}.tar
rm -f ${newdir}.tar
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi



echo echo 'Prereq: '`cat ${olddir}/stamp-version` '>' ${patchfile}
echo 'Prereq: '`cat ${olddir}/stamp-version` > ${patchfile}
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo diff -crN ${olddir}/stamp-version ${newdir}/stamp-version '1>&2 >>' \
        ${patchfile}
diff -crN ${olddir}/stamp-version ${newdir}/stamp-version 1>&2 >> ${patchfile}

echo rm -f ${olddir}/stamp-version
rm -f ${olddir}/stamp-version
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo rm -f ${newdir}/stamp-version
rm -f ${newdir}/stamp-version
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo diff -crN -x'^docs$' -x'^html$' -x'^info$' ${olddir} ${newdir} '1>&2 >>' \
        ${patchfile}
diff -crN -x'^docs$' -x'^html$' -x'^info$' ${olddir} ${newdir} 1>&2 >> \
        ${patchfile}



echo rm -rf ${olddir}
rm -rf ${olddir}
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo rm -rf ${newdir}
rm -rf ${newdir}
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi



echo mkdir save
mkdir save
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo cp ${patchfile} save
cp ${patchfile} save
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo compress ${patchfile}
compress ${patchfile}
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo mv save/${patchfile} .
mv save/${patchfile} .
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo rmdir save
rmdir save
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi

echo gzip ${patchfile}
gzip ${patchfile}
if test ${?} != 0 ; then
    echo "failed" 1>&2
    exit 1
fi
