#!/bin/sh

if [ "$1" = "" ] ; then
    echo 'Usage: .makedist bin-directory version'
    echo 'You should really run this script from "make dist".'
    exit 1
fi    

echo "Making xwatch distribution.. Current version: $2"

echo 'Copying binary..'
cp -p $1/xwatch ../bin-linux/xwatch

echo 'Copying syslogd.conf example..'
cp -p /etc/syslog.conf ../syslog.conf.SAMPLE

echo 'Copying app-defaults file..'
cp -p /usr/lib/X11/app-defaults/XWatch ../XWatch.ap

echo 'Making xwatch.ANNOUNCEMENT and xwatch.lsm..'
cd ..
for name in ANNOUNCEMENT lsm README ; do
    template=.xwatch.$name
    dest=xwatch.$name
    if [ ! -f $template ] ; then
        echo 'Cannot find template' $template
        exit 1
    fi
    echo "($template -> $dest)"
    sed "s/_VER_/$2/g" < $template > $dest
done
cd src

echo 'Making docs..'
cd ../doc
gawk '{
        if (active)
            print;
        else if ($1 == "STARTINSTALL")
            active = 1;
      }' xwatch.yo > xinst.yo
yodl2txt -DINSTALL xinst || exit 1
mv xinst.txt ../INSTALL
rm xinst.yo
(yodl2html xwatch && yodl2tex xwatch && yodl2txt xwatch) || exit 1
cd ../src

echo 'Making archive..'
cd ../..
tar cvzf xwatch-$2.tar.gz xwatch

if [ `hostname` = bambix ] ; then
    echo 'Uploading archive to ftp site..'
    ftp ftp << ENDFTP
	cd /home/ftp/pub/karel/tounix
	put xwatch-$2.tar.gz
	put xwatch/xwatch.README xwatch.README
	put xwatch/xwatch.lsm xwatch.lsm
	quit
ENDFTP
    echo 'Uploading WWW docs..'
    cd xwatch/doc
    ftp www << ENDWWW
        cd docs/programs/xwatch
        prompt off
        mput xwatch*.html
        quit
ENDWWW
else
    echo 'NOT UPLOADED TO FTP/WWW SITE: NOT AT BAMBIX!'
fi    
