#!/bin/bash


DEST=/usr/local/jazz


echo -n "installing JAZZ++ to $DEST ... "

# make everything owner/group/world readable
umask 022

# remove old installation
if test -d $DEST
then
	if test -d $DEST.old
	then
  		rm -rf $DEST.old || exit
	fi
  mv $DEST $DEST.old || exit
fi

# copy the files
mkdir -p $DEST || exit 1
cp -r * $DEST/. || exit 1

# set modes
find $DEST -type d -exec chmod 755 {} \;
find $DEST -type f -exec chmod 644 {} \;

# config files and tmp files must be writable
chmod 666 $DEST/jazz.cfg || exit 1
chmod 777 $DEST

# jazz binary must be executable
chmod 755 $DEST/jazz

mv $DEST/conf/*.jzi $DEST/. || exit 1

# add a link to the bin directory
ln -sf $DEST/jazz /usr/local/bin/jazz || exit
ln -sf $DEST/wxhelp /usr/local/bin/wxhelp || exit
ln -sf $DEST/doc/jazz.xlp /usr/local/bin/jazz.xlp || exit

# add a .profile entry

echo "done."
echo '********************************************************************'
echo 'Installation completed sucessful!'
echo 
echo "Please make sure that the environment variable JAZZ points to $DEST"
echo "When using sh or bash add the lines"
echo "  JAZZ=$DEST"
echo "  export JAZZ" 
echo "to your .profile or .bashrc. When using csh add the line"
echo "  setenv JAZZ $DEST" 
echo "to your .cshrc"
echo
echo "Please read the documentation at $DEST/doc/html/jazz_contents.html"
echo '********************************************************************'
echo


exit 0

